diff --git a/litex/soc/software/libbase/memtest.c b/litex/soc/software/libbase/memtest.c index 625b46429..2c51580b2 100644 --- a/litex/soc/software/libbase/memtest.c +++ b/litex/soc/software/libbase/memtest.c @@ -179,7 +179,7 @@ void memspeed(unsigned int *addr, unsigned long size, bool read_only) { volatile unsigned long *array = (unsigned long *)addr; int i; - unsigned int start, end; + uint32_t start, end; unsigned long write_speed = 0; unsigned long read_speed; __attribute__((unused)) unsigned long data; @@ -202,8 +202,10 @@ void memspeed(unsigned int *addr, unsigned long size, bool read_only) } timer0_update_value_write(1); end = timer0_value_read(); - write_speed = (size*(CONFIG_CLOCK_FREQUENCY/1000000))/(start - end); - printf(" Write: %ldMiB/s\n", write_speed); + uint64_t numerator = ((uint64_t)size)*((uint64_t)CONFIG_CLOCK_FREQUENCY); + uint64_t denominator = ((uint64_t)start - (uint64_t)end); + write_speed = numerator/denominator; + printf(" Write speed: %lub/s\n", write_speed); } /* flush CPU and L2 caches */ @@ -221,8 +223,10 @@ void memspeed(unsigned int *addr, unsigned long size, bool read_only) } timer0_update_value_write(1); end = timer0_value_read(); - read_speed = (size*(CONFIG_CLOCK_FREQUENCY/1000000))/(start - end); - printf(" Read: %ldMiB/s\n", read_speed); + uint64_t numerator = ((uint64_t)size)*((uint64_t)CONFIG_CLOCK_FREQUENCY); + uint64_t denominator = ((uint64_t)start - (uint64_t)end); + read_speed = numerator/denominator; + printf(" Read speed: %lub/s\n", read_speed); } int memtest(unsigned int *addr, unsigned long maxsize)