Commit d434fccf authored by Thanassis Tsiodras's avatar Thanassis Tsiodras

These CPUs have very slow division - count and compare instead.

parent 27e4d722
...@@ -19,7 +19,8 @@ void memcheck() ...@@ -19,7 +19,8 @@ void memcheck()
unsigned primes[] = { 3, 7, 31, 127 }; unsigned primes[] = { 3, 7, 31, 127 };
size_t space = 512*1024; // Allocated test memory space starts at 512K size_t space = 512*1024; // Allocated test memory space starts at 512K
void *p = malloc(space); void *p = malloc(space);
int i; int i = 0;
unsigned cnt = 0;
printf("[MEMCHECK] Detecting memory available"); printf("[MEMCHECK] Detecting memory available");
while(p) { while(p) {
...@@ -45,24 +46,30 @@ void memcheck() ...@@ -45,24 +46,30 @@ void memcheck()
uint8_t *pc = p; uint8_t *pc = p;
unsigned prime = primes[i]; unsigned prime = primes[i];
unsigned bytes = space; unsigned bytes = space;
unsigned idx = 0;
printf("%s%d", i?", ":"", prime); printf("%s%d", i?", ":"", prime);
fflush(stdout); fflush(stdout);
cnt = 0;
while (bytes--) { while (bytes--) {
*pc++ = (idx % prime); *pc++ = cnt;
idx++; cnt++;
if (cnt == prime) {
cnt = 0;
}
} }
pc = p; pc = p;
bytes = space; bytes = space;
idx = 0; cnt = 0;
while (bytes--) { while (bytes--) {
if (*pc != (idx % prime)) { if (*pc != cnt) {
printf("[MEMCHECK] Address space wrapped around at 0x%x!\n", (unsigned)pc); printf("[MEMCHECK] Address space wrapped around at 0x%x!\n", (unsigned)pc);
fflush(stdout); fflush(stdout);
exit(1); exit(1);
} }
pc++; pc++;
idx++; cnt++;
if (cnt == prime) {
cnt = 0;
}
} }
} }
puts(""); puts("");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment