From: Luke Kenneth Casson Leighton Date: Thu, 11 Oct 2018 12:17:11 +0000 (+0100) Subject: more explicit testing, duplicating header file algorithms for div, rem and shift X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ca25e0e1b818b48a33e96bba668d439abc06ad33;p=riscv-isa-sim.git more explicit testing, duplicating header file algorithms for div, rem and shift --- diff --git a/operators/operators.t.cc b/operators/operators.t.cc index c025c49..3ad5c68 100644 --- a/operators/operators.t.cc +++ b/operators/operators.t.cc @@ -12,19 +12,27 @@ #define plus + #define minus - #define shiftr >> -#define shiftl >> -#define mul >> +#define shiftl << +#define mul * + +#define xlen 64 + +#define zext(x, y) (((reg_t)(x) << (64-y)) >> (64-y)) +//typedef int64_t sreg_t; +//#define sext32(x) ((sreg_t)(int32_t)(x)) + #define operator_check( op ) { \ - int8_t z = x op y; \ + int8_t z = (int8_t)(x op y); \ x1 = (uint8_t)x; \ y1 = (uint8_t)y; \ - uint16_t z1 = x1 op y1; \ + uint64_t z1 = x1 op y1; \ if ((uint8_t)z1 != (uint8_t)z) { \ - printf("FAILED %s %d %d %d %d\n", \ + printf("FAILED %s %d %d %d %ld\n", \ xstr(op), i, j, z, z1); \ } \ } + int main(int argc, char *argv[]) { /*op2 o(0xfff0); @@ -39,7 +47,7 @@ int main(int argc, char *argv[]) //printf("hello %lx\n", o); int8_t x=0, y=0; - int16_t x1, y1; + uint64_t x1, y1; for (int i=0, x=0; i < 256; i++, x++) { //printf("hello %x\n", (int)(uint8_t)x); @@ -47,10 +55,88 @@ int main(int argc, char *argv[]) operator_check( plus ) operator_check( minus ) operator_check( mul ) - operator_check( divide ) - operator_check( remainder ) - operator_check( shiftr ) - operator_check( shiftl ) + + // shiftl - NOTE: must use xlen=8. so, have to overload xlen... + { + int8_t z = 0; + z = (int8_t)(x << (y & (8-1))); + x1 = (uint8_t)x; + y1 = (uint8_t)y; + uint64_t z1 = (x1 << (y1 & (8-1))); + if ((uint8_t)z1 != (uint8_t)z) { + printf("FAILED %s xy %d %d x1y1 %d %d z %d z1 %ld\n", + "<<", x, y, x1, y1, z, z1); + } + else { + printf("OK %s %d %d %d %ld\n", + "<<", x, y, z, z1); + } + } + // shiftr + { + int8_t z = 0; + z = (int8_t)(zext(x, 8) >> (y & (8-1))); + x1 = (uint8_t)x; + y1 = (uint8_t)y; + uint64_t z1 = (zext(x1, 8) >> (y1 & (8-1))); + if ((uint8_t)z1 != (uint8_t)z) { + printf("FAILED %s xy %d %d x1y1 %ld %ld z %d z1 %ld\n", + ">>", x, y, x1, y1, z, z1); + } + else { + printf("OK %s %d %d %d %ld\n", + ">>", x, y, z, z1); + } + } + // rem + { + int8_t z = 0; + if (y == 0) + z = sext32(y); + else + z = (int8_t)(x % y); + x1 = (uint8_t)x; + y1 = (uint8_t)y; + uint64_t z1 = 0; + if (y1 == 0) + z1 = sext32(y1); + z1 = (x1 % y1); + if ((uint8_t)z1 != (uint8_t)z) { + printf("FAILED %s xy %d %d x1y1 %d %d z %d z1 %ld\n", + "rem", x, y, x1, y1, z, z1); + } + else { + printf("OK %s %d %d %d %ld\n", + "rem", x, y, z, z1); + } + } + // divide + { + int8_t z = 0; + if (y == 0) + z = 0xff; + else if (x == -127 && y == -1) // have to redefine UINT64_MAX + z = x; + else + z = (int8_t)(x / y); + x1 = (uint8_t)x; + y1 = (uint8_t)y; + uint64_t z1 = 0; + if (y1 == 0) + z1 = UINT64_MAX; + else if (x1 == INT64_MIN && y1 == -1) + z1 = x1; + else + z1 = (x1 / y1); + if ((uint8_t)z1 != (uint8_t)z) { + printf("FAILED %s xy %d %d x1y1 %ld %ld z %d z1 %ld\n", + xstr(op), x, y, x1, y1, z, z1); + } + else { + printf("OK %s %d %d %d %ld\n", + xstr(op), x, y, z, z1); + } + } } } }