[llvm-commits] CVS: llvm/test/Programs/SingleSource/UnitTests/2003-07-06-IntOverflow.c 2003-07-09-LoadShorts.c 2003-07-09-SignedArgs.c 2003-07-10-SignConversions.c
Vikram Adve
vadve at cs.uiuc.edu
Thu Jul 10 14:21:02 PDT 2003
Changes in directory llvm/test/Programs/SingleSource/UnitTests:
2003-07-06-IntOverflow.c added (r1.1)
2003-07-09-LoadShorts.c added (r1.1)
2003-07-09-SignedArgs.c added (r1.1)
2003-07-10-SignConversions.c added (r1.1)
---
Log message:
Four new unit tests for different situations with integer values:
(1) SignConversions: Basic signed/unsigned conversions.
(2) IntOverflow: Operations after one that overflows
(3) LoadShorts: Load/store operations on short values
(4) SignedArgs: Passing short signed values as arguments to normal
and varargs functions
---
Diffs of the changes:
Index: llvm/test/Programs/SingleSource/UnitTests/2003-07-06-IntOverflow.c
diff -c /dev/null llvm/test/Programs/SingleSource/UnitTests/2003-07-06-IntOverflow.c:1.1
*** /dev/null Thu Jul 10 14:20:03 2003
--- llvm/test/Programs/SingleSource/UnitTests/2003-07-06-IntOverflow.c Thu Jul 10 14:19:53 2003
***************
*** 0 ****
--- 1,52 ----
+ /*
+ * This test stresses masking and sign-extension after int operations
+ * that cause overflow, producing bogus high-order bits.
+ * The basic overflow situation (x * x + y * y, for x = y = 1 << 21)
+ * actually happens in Olden-perimeter, in the function CheckOutside.
+ *
+ * Several things have to happen correctly:
+ * -- correct constant folding if it is done at compile-time
+ * -- correct sign-extensions during native code generation for -, * and /.
+ * -- correct handling of high bits during native code generation for
+ * a sequence of operations involving -, * and /.
+ */
+ #include <stdio.h>
+
+ void compareOvf(int x, int y)
+ {
+ int sum = x * x + y * y;
+ if (sum < (1 << 22))
+ printf("compare after overflow is TRUE\n");
+ else
+ printf("compare after overflow is FALSE\n");
+ }
+
+ void divideOvf(int x, int y)
+ {
+ int sum = x * x + y * y;
+ int rem = (1 << 31) / sum;
+ printf("divide after overflow = %d (0x%lx)\n", rem, rem);
+ }
+
+ void divideNeg(int x, int y)
+ {
+ int sum = x * x - y * y;
+ int rem = sum / (1 << 18);
+ printf("divide negative value by power-of-2 = %d (0x%lx)\n", rem, rem);
+ }
+
+ void subtractOvf(int x, int y)
+ {
+ int sum = x * x + y * y;
+ int rem = (1u << 31) - sum;
+ printf("subtract after overflow = %d (0x%lx)\n", rem, rem);
+ }
+
+ int main()
+ {
+ int b21 = 1 << 21;
+ compareOvf(b21, b21);
+ divideOvf(b21 + 1, b21 + 2);
+ divideNeg(b21 + 1, b21 + 2); /* arg1 must be < arg2 */
+ subtractOvf(b21 + 1, b21 + 2);
+ }
Index: llvm/test/Programs/SingleSource/UnitTests/2003-07-09-LoadShorts.c
diff -c /dev/null llvm/test/Programs/SingleSource/UnitTests/2003-07-09-LoadShorts.c:1.1
*** /dev/null Thu Jul 10 14:20:03 2003
--- llvm/test/Programs/SingleSource/UnitTests/2003-07-09-LoadShorts.c Thu Jul 10 14:19:53 2003
***************
*** 0 ****
--- 1,75 ----
+ /*
+ * This test is similar to 2003-05-26-Shorts.c except that it stores all
+ * short values in a structure to test load and store operations on those
+ * values. It stresses masking and sign-extension for such load/stores.
+ */
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ typedef struct ShortsSet_struct {
+ unsigned int ui;
+ int i;
+ unsigned short us;
+ short s;
+ unsigned char ub;
+ signed char b;
+ } ShortsSet;
+
+
+ /* Move the value here to prevent constant folding */
+ unsigned long long getL()
+ {
+ return 0xafafafafc5c5b8a3ull;
+ }
+
+ int
+ main(int argc, char** argv)
+ {
+ unsigned long long UL = getL(); /* 0xafafafafc5c5b8a3 */
+ long long L = (long long) UL;
+
+ ShortsSet* S = (ShortsSet*) malloc(sizeof(ShortsSet));
+ S->ui = (unsigned int) UL; /* 0xc5c5b8a3 = 3318069411 */
+ S-> i = (int) UL; /* 0xc5c5b8a3 = -976897885 */
+
+ S->us = (unsigned short) UL; /* 0xb8a3 = 47267 */
+ S-> s = (short) UL; /* 0xb8a3 = -18269 */
+
+ S->ub = (unsigned char) UL; /* 0xa3 = 163 */
+ S-> b = ( signed char) UL; /* 0xa3 = -93 */
+
+ printf(" ui = %u (0x%x)\t\tUL-ui = %lld (0x%llx)\n",
+ S->ui, S->ui, UL - S->ui, UL - S->ui);
+ printf("ui*ui = %u (0x%x)\t UL/ui = %lld (0x%llx)\n\n",
+ (unsigned int) S->ui * S->ui, (unsigned int) S->ui * S->ui,
+ UL/S->ui, UL/S->ui);
+
+ printf(" i = %d (0x%x)\tL-i = %lld (0x%llx)\n",
+ S->i, S->i, L - S->i, L - S->i);
+ printf(" i* i = %d (0x%x)\tL/ i = %lld (0x%llx)\n\n",
+ (int) S->i * S->i, (int) S->i * S->i, L/S->i, L/S->i);
+
+ printf("us = %u (0x%x)\t\tUL-us = %lld (0x%llx)\n",
+ S->us, S->us, UL - S->us, UL - S->us);
+ printf("us*us = %u (0x%x)\t UL/us = %lld (0x%llx)\n\n",
+ (unsigned short) S->us * S->us, (unsigned short) S->us * S->us,
+ UL/S->us, UL/S->us);
+
+ printf(" s = %d (0x%x)\tL-s = %lld (0x%llx)\n",
+ S->s, S->s, L - S->s, L - S->s);
+ printf(" s* s = %d (0x%x)\tL/ s = %lld (0x%llx)\n\n",
+ (short) S->s * S->s, (short) S->s * S->s, L/S->s, L/S->s);
+
+ printf("ub = %u (0x%x)\t\tUL-ub = %lld (0x%llx)\n",
+ S->ub, S->ub, UL - S->ub, UL - S->ub);
+ printf("ub*ub = %u (0x%x)\t\tUL/ub = %lld (0x%llx)\n\n",
+ (unsigned char) S->ub * S->ub, (unsigned char) S->ub * S->ub,
+ UL/S->ub, UL/S->ub);
+
+ printf(" b = %d (0x%x)\t\tL-b = %lld (0x%llx)\n",
+ S->b, S->b, L - S->b, L - S->b);
+ printf(" b* b = %d (0x%x)\t\t\tL/b = %lld (0x%llx)\n\n",
+ (signed char) S->b * S->b, (signed char) S->b * S->b, L/S->b, L/S->b);
+
+ return 0;
+ }
Index: llvm/test/Programs/SingleSource/UnitTests/2003-07-09-SignedArgs.c
diff -c /dev/null llvm/test/Programs/SingleSource/UnitTests/2003-07-09-SignedArgs.c:1.1
*** /dev/null Thu Jul 10 14:20:03 2003
--- llvm/test/Programs/SingleSource/UnitTests/2003-07-09-SignedArgs.c Thu Jul 10 14:19:53 2003
***************
*** 0 ****
--- 1,60 ----
+ /*
+ * Test sign extensions on short signed values passed as arguments
+ * to function calls. Include arithmetic to produce extra high bits
+ * from operations that overflow. Lots of codes do this!
+ */
+ #include <stdio.h>
+ #include <stdarg.h>
+ #include <inttypes.h>
+
+ short getShort(char c, char c2, char c3, short s, short s2, int i);
+ int getUnknown(char c, ...);
+
+ int passShort(char c, short s)
+ {
+ char c2 = s + c;
+ char c3 = s - c;
+ short s2 = s * c;
+ int i = s * s * c * c;
+ short s3 = getShort(c, c2, c3, s, s2, i); /* args shd be sign-extended */
+ return getUnknown(c, c2, c3, s, s2, s3, i); /* args shd be promoted to int */
+ }
+
+ int main()
+ {
+ printf("%d\n", passShort(0x80, 0xf0f4));
+ }
+
+ short getShort(char c, char c2, char c3, short s, short s2, int i)
+ {
+ int bc = c == (char) -128;
+ int bc2 = c2 == (char) 116;
+ int bc3 = c3 == (char) 116;
+ int bs = s == (short) -3852;
+ int bs2 = s2 == (short) -31232;
+ int bi = i == (int) -1708916736;
+
+ printf("getShort():\t%d %d %d %d %d %d\n", bc, bc2, bc3, bs, bs2, bi);
+ printf("getShort():\t%d %d %d %d %d %d\n", c, c2, c3, s, s2, i);
+ return (c + c2 + c3 + s + s2) + (short) i;
+ }
+
+ int getUnknown(char c, ...)
+ {
+ char c2, c3;
+ short s, s2, s3;
+ int i;
+ va_list ap;
+
+ va_start(ap, c);
+ c2 = (char) va_arg(ap, int);
+ c3 = (char) va_arg(ap, int);
+ s = (short) va_arg(ap, int);
+ s2 = (short) va_arg(ap, int);
+ s3 = (short) va_arg(ap, int);
+ i = va_arg(ap, int);
+ va_end(ap);
+
+ printf("getUnknown():\t%d %d %d %d %d %d %d\n", c, c2, c3, s, s2, s3, i);
+ return c + c2 + c3 + s + s2 + s3 + i;
+ }
Index: llvm/test/Programs/SingleSource/UnitTests/2003-07-10-SignConversions.c
diff -c /dev/null llvm/test/Programs/SingleSource/UnitTests/2003-07-10-SignConversions.c:1.1
*** /dev/null Thu Jul 10 14:20:03 2003
--- llvm/test/Programs/SingleSource/UnitTests/2003-07-10-SignConversions.c Thu Jul 10 14:19:53 2003
***************
*** 0 ****
--- 1,31 ----
+ /*
+ * Test basic conversions between short signed and unsigned values
+ * with no function calls and no arithmetic.
+ */
+ #include <stdio.h>
+
+ unsigned char getUC() { return 0x80; }
+
+ char getC() { return 0x80; }
+
+ int main()
+ {
+ char C80 = getC();
+ unsigned char UC80 = getUC();
+
+ /* source is smaller than dest: both decide */
+ unsigned short us = (unsigned short) C80; /* sign-ext then zero-ext */
+ unsigned short us2 = (unsigned short) UC80; /* zero-ext only: NOP! */
+ short s = ( short) C80; /* sign-ext */
+ short s2 = ( short) UC80; /* zero-extend only : NOP! */
+ printf("%d %d --> unsigned: us = %d, us2 = %d\n", C80, UC80, us, us2);
+ printf("%d %d --> signed: s = %d, s2 = %d\n", C80, UC80, s, s2);
+
+ /* source is same size or larger than dest: dest decides */
+ unsigned char uc = (unsigned char ) C80; /* zero-ext */
+ unsigned char uc2 = (unsigned char ) UC80; /* NOP */
+ char c = ( char ) C80; /* NOP */
+ char c2 = ( char ) UC80; /* sign-extend */
+ printf("%d %d --> unsigned: uc = %d, uc2 = %d\n", C80, UC80, uc, uc2);
+ printf("%d %d --> signed: c = %d, c2 = %d\n", C80, UC80, c, c2);
+ }
More information about the llvm-commits
mailing list