It is obviously important that the addr pointer used to access the memory region being tested is volatile-qualified, to prevent the compiler from optimizing out the "write this value, read it back, check that it is what we expect".
However, none of these auxiliary variables have any such need for, effectively, being forced to live on the stack and cause each and every reference to them to do a memory access. This makes the memtest about 15% faster on a beagleboneblack. Before: => dcache off => time mtest 0x81000000 0x81100000 0 1 Testing 81000000 ... 81100000: Iteration: 1 Tested 1 iteration(s) with 0 errors. time: 10.868 seconds After: => dcache off => time mtest 0x81000000 0x81100000 0 1 Testing 81000000 ... 81100000: Iteration: 1 Tested 1 iteration(s) with 0 errors. time: 9.209 seconds [Without the 'dcache off', there's no difference in the time, about 0.6s, but the memtest cannot usefully be done with dcache enabled.] Signed-off-by: Rasmus Villemoes <r...@prevas.dk> --- cmd/mem.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/cmd/mem.c b/cmd/mem.c index 9e716776393..9a1cfa4534c 100644 --- a/cmd/mem.c +++ b/cmd/mem.c @@ -717,12 +717,9 @@ static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr, ulong errs = 0; ulong val, readback; int j; - vu_long offset; - vu_long test_offset; - vu_long pattern; - vu_long temp; - vu_long anti_pattern; - vu_long num_words; + ulong offset, test_offset; + ulong pattern, anti_pattern; + ulong temp, num_words; static const ulong bitpattern[] = { 0x00000001, /* single bit */ 0x00000003, /* two adjacent bits */ -- 2.50.1