有一个用于测试 DDR 的代码,它曾经在 GCC-4.2.4 上运行良好,但是在我们转移到 GCC-4.7.0 之后,在执行以下代码后观察到位翻转;这是由于代码中的错误还是我需要为新编译器处理一些事情;下面给出的是代码片段:
int test_bitflip_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count) {
unsigned long volatile *p1 = bufa;
unsigned long volatile *p2 = bufb;
unsigned int j, k;
unsigned long q;
size_t i;
char *msgBuf;
for (k = 0; k < UL_LEN; k++) {
q = ONE << k;
for (j = 0; j < 8; j++) {
q = ~q;
p1 = (unsigned long volatile *) bufa;
p2 = (unsigned long volatile *) bufb;
for (i = 0; i < count; i++) {
*p1++ = *p2++ = (i % 2) == 0 ? q : ~q;
}
if (compare_regions(bufa, bufb, count)) {
return -1;
}
}
if(!(k % 10))
puts1(".\0");
}
return 0;
}
int compare_regions(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count) {
int r = 0;
size_t i;
unsigned long physaddr;
unsigned long volatile *p1 = bufa;
unsigned long volatile *p2 = bufb;
for (i = 0; i < count; i++, p1++, p2++) {
if (*p1 != *p2) {
if (use_phys) {
physaddr = physaddrbase + (i * sizeof(unsigned long));
} else {
}
r = -1;
}
}
return r;
}