[llvm-commits] CVS: llvm-test/SingleSource/UnitTests/Integer/bit_concat.c bit_concat.reference_output bit_reduce.c bit_reduce.reference_output part_select.c part_select.reference_output bit_select.c

Reid Spencer reid at x10sys.com
Mon Feb 12 09:53:16 PST 2007



Changes in directory llvm-test/SingleSource/UnitTests/Integer:

bit_concat.c added (r1.1)
bit_concat.reference_output added (r1.1)
bit_reduce.c added (r1.1)
bit_reduce.reference_output added (r1.1)
part_select.c added (r1.1)
part_select.reference_output added (r1.1)
bit_select.c updated: 1.1 -> 1.2
---
Log message:

Update/Add tests for the arbitrary bit width builtin functions.


---
Diffs of the changes:  (+323 -3)

 bit_concat.c                |   62 ++++++++++++++++++++++
 bit_concat.reference_output |  119 ++++++++++++++++++++++++++++++++++++++++++++
 bit_reduce.c                |   67 ++++++++++++++++++++++++
 bit_reduce.reference_output |   18 ++++++
 bit_select.c                |    6 +-
 part_select.c               |   54 +++++++++++++++++++
 6 files changed, 323 insertions(+), 3 deletions(-)


Index: llvm-test/SingleSource/UnitTests/Integer/bit_concat.c
diff -c /dev/null llvm-test/SingleSource/UnitTests/Integer/bit_concat.c:1.1
*** /dev/null	Mon Feb 12 11:53:09 2007
--- llvm-test/SingleSource/UnitTests/Integer/bit_concat.c	Mon Feb 12 11:52:59 2007
***************
*** 0 ****
--- 1,62 ----
+ //===--- part_select.c --- Test The bit_select builtin --------------------===//
+ //
+ // This file was developed by Reid Spencer and is distributed under the 
+ // University of Illinois Open Source License. See LICENSE.TXT for details.
+ //
+ //===----------------------------------------------------------------------===//
+ //
+ // This test case tests the __builtin_part_select builtin function llvm-gcc.
+ // bit_select selects one bit out of a larger 
+ //
+ //===----------------------------------------------------------------------===//
+ 
+ #include <stdio.h>
+ #include <stdlib.h>
+ 
+ typedef unsigned int __attribute__((bitwidth(17))) BitType1;
+ typedef unsigned int __attribute__((bitwidth(19))) BitType2;
+ typedef unsigned long long __attribute__((bitwidth(36))) ConcatType;
+ int numbits1 = 17;
+ int numbits2 = 19;
+ 
+ void printBits(ConcatType val, int numbits ) {
+   int j;
+   for (j = numbits-1; j >= 0; --j) {
+     if (__builtin_bit_select(val, j))
+       printf("1");
+     else
+       printf("0");
+   }
+ }
+ 
+ int main(int argc, char** argv)
+ {
+   BitType1 X = 0;
+   BitType2 Y = 0;
+   ConcatType Z = 0;
+   int i, j;
+   int count = (argc > 1 ? atoi(argv[1]) % 128 : 128);
+ 
+   srand(count);
+ 
+   for (i = 0; i < count; i++) {
+     Y = X = 0;
+     for (j = 0; j < numbits1; j++) {
+       X += (rand() % 2 == 0 ? 0 : 1);
+       X <<= 1;
+     }
+     for (j = 0; j < numbits2; j++) {
+       Y += (rand() % 2 == 0 ? 0 : 1);
+       Y <<= 1;
+     }
+     Z = __builtin_bit_concat(X, Y);
+     printf("bit_concat(");
+     printBits(X, numbits1);
+     printf(",");
+     printBits(Y, numbits2);
+     printf(") = ");
+     printBits(Z, numbits1 + numbits2);
+     printf("\n");
+   }
+   return 0;
+ }


Index: llvm-test/SingleSource/UnitTests/Integer/bit_concat.reference_output
diff -c /dev/null llvm-test/SingleSource/UnitTests/Integer/bit_concat.reference_output:1.1
*** /dev/null	Mon Feb 12 11:53:16 2007
--- llvm-test/SingleSource/UnitTests/Integer/bit_concat.reference_output	Mon Feb 12 11:52:59 2007
***************
*** 0 ****
--- 1,119 ----
+ bit_concat(01111000000011100,0100110100110111000) = 011110000000111000100110100110111000
+ bit_concat(10111100010110100,0000010011010100000) = 101111000101101000000010011010100000
+ bit_concat(10011000010110000,1010110100000110100) = 100110000101100001010110100000110100
+ bit_concat(00001001101011100,1001000111110110110) = 000010011010111001001000111110110110
+ bit_concat(11101001101111100,1001000011000010100) = 111010011011111001001000011000010100
+ bit_concat(10000101010010000,0001111111111101110) = 100001010100100000001111111111101110
+ bit_concat(11110111001001100,0101010101100111000) = 111101110010011000101010101100111000
+ bit_concat(00100000010010010,0100010001100100000) = 001000000100100100100010001100100000
+ bit_concat(01000110111110100,0010011001000001010) = 010001101111101000010011001000001010
+ bit_concat(10101001111001100,0110110111000110100) = 101010011110011000110110111000110100
+ bit_concat(10001101100001010,1111011010000010000) = 100011011000010101111011010000010000
+ bit_concat(00110111110111100,0101111011011011000) = 001101111101111000101111011011011000
+ bit_concat(10101100010011110,0011110000000010100) = 101011000100111100011110000000010100
+ bit_concat(00001110001100010,0100100001011011110) = 000011100011000100100100001011011110
+ bit_concat(00100000001001000,0000011110101100010) = 001000000010010000000011110101100010
+ bit_concat(11111010110011010,1001011010011000100) = 111110101100110101001011010011000100
+ bit_concat(01111010100010000,0011010111111010000) = 011110101000100000011010111111010000
+ bit_concat(00010011010110000,1111000101101101110) = 000100110101100001111000101101101110
+ bit_concat(10110111110111000,0000111001011101000) = 101101111101110000000111001011101000
+ bit_concat(11100111011111100,0111010101111000110) = 111001110111111000111010101111000110
+ bit_concat(00000111101110000,1000111001010101100) = 000001111011100001000111001010101100
+ bit_concat(00010011011110010,1001101011101011000) = 000100110111100101001101011101011000
+ bit_concat(01111100101001010,1000111110000000010) = 011111001010010101000111110000000010
+ bit_concat(10100000110100000,1111111001001111010) = 101000001101000001111111001001111010
+ bit_concat(01010000001000110,1001101010111110100) = 010100000010001101001101010111110100
+ bit_concat(10111001110100110,1000011100010100000) = 101110011101001101000011100010100000
+ bit_concat(10001010001010010,1000001010010000000) = 100010100010100101000001010010000000
+ bit_concat(11111110111111110,1010000000001010110) = 111111101111111101010000000001010110
+ bit_concat(00010011100100000,0010101000011000110) = 000100111001000000010101000011000110
+ bit_concat(10101111101000010,0010011001011001100) = 101011111010000100010011001011001100
+ bit_concat(00110100101001100,0100101001110010100) = 001101001010011000100101001110010100
+ bit_concat(00010010100110110,1111000001000000100) = 000100101001101101111000001000000100
+ bit_concat(11100001010111000,0101011011101011100) = 111000010101110000101011011101011100
+ bit_concat(10011000001010000,1111001001111011000) = 100110000010100001111001001111011000
+ bit_concat(01101000010001110,1101011110010011100) = 011010000100011101101011110010011100
+ bit_concat(10111000111110100,0111110000110010000) = 101110001111101000111110000110010000
+ bit_concat(00010111001011000,1101101100100101100) = 000101110010110001101101100100101100
+ bit_concat(11011110011110100,1100110011101010000) = 110111100111101001100110011101010000
+ bit_concat(10001110101000000,1000111010011001000) = 100011101010000001000111010011001000
+ bit_concat(11100000000010000,1100111010110000100) = 111000000000100001100111010110000100
+ bit_concat(10010001001000100,0001000000010000010) = 100100010010001000001000000010000010
+ bit_concat(01110110100100010,0110111101100110100) = 011101101001000100110111101100110100
+ bit_concat(01010010110111010,0000100111101101100) = 010100101101110100000100111101101100
+ bit_concat(01110101110010010,0100100011111010000) = 011101011100100100100100011111010000
+ bit_concat(10101100111011010,0000101000000000100) = 101011001110110100000101000000000100
+ bit_concat(01010011111101100,1100100100111110000) = 010100111111011001100100100111110000
+ bit_concat(01110000110111110,1111010101101100010) = 011100001101111101111010101101100010
+ bit_concat(11101000111010100,0111001010001111110) = 111010001110101000111001010001111110
+ bit_concat(11001100100001110,0101101000110101100) = 110011001000011100101101000110101100
+ bit_concat(01001101011010010,1011110100000101100) = 010011010110100101011110100000101100
+ bit_concat(00010111100011100,0011011001000000010) = 000101111000111000011011001000000010
+ bit_concat(11001000100100010,0000000011010111110) = 110010001001000100000000011010111110
+ bit_concat(10010000010010110,1000110101110100010) = 100100000100101101000110101110100010
+ bit_concat(00111110101001000,1001110001000110000) = 001111101010010001001110001000110000
+ bit_concat(11100100010101100,0000111000000011110) = 111001000101011000000111000000011110
+ bit_concat(00111001111110010,1011001000011101110) = 001110011111100101011001000011101110
+ bit_concat(11000111110101010,0000000010101010010) = 110001111101010100000000010101010010
+ bit_concat(11110101000011010,0111110011011000110) = 111101010000110100111110011011000110
+ bit_concat(11110011110010010,1100001111101010110) = 111100111100100101100001111101010110
+ bit_concat(10100011010101100,0111011111000000000) = 101000110101011000111011111000000000
+ bit_concat(01000010010011100,0111010000100100100) = 010000100100111000111010000100100100
+ bit_concat(01100101111101010,0100110000000001100) = 011001011111010100100110000000001100
+ bit_concat(10101111011110110,0101101101101111010) = 101011110111101100101101101101111010
+ bit_concat(10011111100110100,1110000111010010000) = 100111111001101001110000111010010000
+ bit_concat(11010101101010110,1110010011001011000) = 110101011010101101110010011001011000
+ bit_concat(11001110100101000,1000110110010111110) = 110011101001010001000110110010111110
+ bit_concat(00111101001010110,0001000011001001110) = 001111010010101100001000011001001110
+ bit_concat(01111110100000110,1001101010001011000) = 011111101000001101001101010001011000
+ bit_concat(11100100110110100,0101101100000010110) = 111001001101101000101101100000010110
+ bit_concat(00011000000000010,0000101110100110000) = 000110000000000100000101110100110000
+ bit_concat(01011011010010010,1010100101100001010) = 010110110100100101010100101100001010
+ bit_concat(10111110100110010,0100110101000011110) = 101111101001100100100110101000011110
+ bit_concat(00110101100110110,1001101101010110000) = 001101011001101101001101101010110000
+ bit_concat(11001110110000010,0000111100000111110) = 110011101100000100000111100000111110
+ bit_concat(01110110111011110,0000000111010111110) = 011101101110111100000000111010111110
+ bit_concat(00100001011111110,0111010110001001100) = 001000010111111100111010110001001100
+ bit_concat(01100010101101000,0001011111100001100) = 011000101011010000001011111100001100
+ bit_concat(11110100010111000,1110000001101111000) = 111101000101110001110000001101111000
+ bit_concat(11110011111000100,1010100111000111010) = 111100111110001001010100111000111010
+ bit_concat(00011101111111010,1100000010111001010) = 000111011111110101100000010111001010
+ bit_concat(11101000101010000,0011001111010010110) = 111010001010100000011001111010010110
+ bit_concat(11110011001000100,0101000011001100010) = 111100110010001000101000011001100010
+ bit_concat(00000111101000010,0001110000111111100) = 000001111010000100001110000111111100
+ bit_concat(11101000001011000,1010001100110101010) = 111010000010110001010001100110101010
+ bit_concat(01100001001100000,1101110001100001100) = 011000010011000001101110001100001100
+ bit_concat(00000010010001010,1011101111001001000) = 000000100100010101011101111001001000
+ bit_concat(01001111011111000,1010110111001001110) = 010011110111110001010110111001001110
+ bit_concat(00101000101111010,0011101000111111100) = 001010001011110100011101000111111100
+ bit_concat(10110000111111100,1011001100010000110) = 101100001111111001011001100010000110
+ bit_concat(10101000010000110,0010111101011111010) = 101010000100001100010111101011111010
+ bit_concat(01000010100100100,0110110001100100110) = 010000101001001000110110001100100110
+ bit_concat(10100101111111000,1001111101110000110) = 101001011111110001001111101110000110
+ bit_concat(01010101001011000,1101110111000101100) = 010101010010110001101110111000101100
+ bit_concat(00011010101010010,1111011000110010100) = 000110101010100101111011000110010100
+ bit_concat(10000101100100010,1011000011100010010) = 100001011001000101011000011100010010
+ bit_concat(10110000001010100,0011101100111101110) = 101100000010101000011101100111101110
+ bit_concat(11011010010010100,1110111001011000010) = 110110100100101001110111001011000010
+ bit_concat(01000111101100100,0110010110000001010) = 010001111011001000110010110000001010
+ bit_concat(10010100110011100,1010010011100010000) = 100101001100111001010010011100010000
+ bit_concat(11100100100110010,0011101111111110010) = 111001001001100100011101111111110010
+ bit_concat(00110101100100000,1100011010010110000) = 001101011001000001100011010010110000
+ bit_concat(10101101001111010,1110100111100110000) = 101011010011110101110100111100110000
+ bit_concat(00100010111110010,0110110101111111010) = 001000101111100100110110101111111010
+ bit_concat(00000111010000100,0001110101000010010) = 000001110100001000001110101000010010
+ bit_concat(00101001011101110,0101001010011111010) = 001010010111011100101001010011111010
+ bit_concat(01001011100011000,1110011101110010000) = 010010111000110001110011101110010000
+ bit_concat(01000001111000100,0101010111111001000) = 010000011110001000101010111111001000
+ bit_concat(00011111101001010,1100111011111010000) = 000111111010010101100111011111010000
+ bit_concat(11111010111101100,1100100001010001110) = 111110101111011001100100001010001110
+ bit_concat(10111001111101010,0100011010001110000) = 101110011111010100100011010001110000
+ bit_concat(00100010111110000,1110110101100010110) = 001000101111100001110110101100010110
+ bit_concat(00110011111001100,1011100111000000100) = 001100111110011001011100111000000100
+ bit_concat(01010110000110010,1110010011011110100) = 010101100001100101110010011011110100
+ bit_concat(01011001000111010,1011110001011000010) = 010110010001110101011110001011000010
+ bit_concat(01001011100010100,1011111011010011010) = 010010111000101001011111011010011010
+ bit_concat(11101010001011110,1010100101001010000) = 111010100010111101010100101001010000
+ bit_concat(01101001000110010,0100101000000101010) = 011010010001100100100101000000101010
+ bit_concat(11011000000111110,1001100110101011000) = 110110000001111101001100110101011000
+ exit 0


Index: llvm-test/SingleSource/UnitTests/Integer/bit_reduce.c
diff -c /dev/null llvm-test/SingleSource/UnitTests/Integer/bit_reduce.c:1.1
*** /dev/null	Mon Feb 12 11:53:16 2007
--- llvm-test/SingleSource/UnitTests/Integer/bit_reduce.c	Mon Feb 12 11:52:59 2007
***************
*** 0 ****
--- 1,67 ----
+ //===--- bit_reduce.c --- Test The bit_reduce builtins --------------------===//
+ //
+ // This file was developed by Reid Spencer and is distributed under the 
+ // University of Illinois Open Source License. See LICENSE.TXT for details.
+ //
+ //===----------------------------------------------------------------------===//
+ //
+ // This test case tests the __builtin_bit_*_reduce builtin functions. These
+ // builtins apply and/or/nor/xor/nxor operations to the bits of an integer type
+ // in succession until a single final bit is produced.
+ //
+ //===----------------------------------------------------------------------===//
+ 
+ #include <stdio.h>
+ #include <stdlib.h>
+ 
+ #ifdef ENABLE_LARGE_INTEGERS
+ typedef int __attribute__((bitwidth(250))) BitType;
+ const BitType X = 0xAAAAAAAAAAAAAAAAULL;
+ int numbits = 250;
+ #else
+ typedef int __attribute__((bitwidth(47))) BitType;
+ const BitType X = 0xAAAAAAAAAAAAULL;
+ int numbits = 47;
+ #endif
+ 
+ printBits(BitType val, int numbits ) {
+   int j;
+   for (j = numbits-1; j >= 0; --j) {
+     if (__builtin_bit_select(val, j))
+       printf("1");
+     else
+       printf("0");
+   }
+ }
+ 
+ int main(int argc, char** argv)
+ {
+ 
+ #ifdef ENABLE_LARGE_INTEGERS
+   BitType Y = X * X;
+ #else
+   BitType Y = X;
+ #endif
+   int i, j;
+   int seed = (argc > 1 ? atoi(argv[1]): 31415927);
+ 
+   srand(seed);
+ 
+   for (i = 0; i < 128; i++) {
+     int num = rand();
+     BitType Val = Y * num;
+     {
+       unsigned char And  = __builtin_bit_and_reduce(Val);
+       unsigned char Nand = __builtin_bit_nand_reduce(Val);
+       unsigned char Or   = __builtin_bit_or_reduce(Val);
+       unsigned char Nor  = __builtin_bit_nor_reduce(Val);
+       unsigned char Xor  = __builtin_bit_xor_reduce(Val);
+       unsigned char Nxor = __builtin_bit_nxor_reduce(Val);
+       printf("Value=");
+       printBits(Val, numbits);
+       printf(", and=%d, nand=%d, or=%d, nor=%d, xor=%d, nxor=%d\n",
+           And, Nand, Or, Nor, Xor, Nxor);
+     }
+   }
+   return 0;
+ }


Index: llvm-test/SingleSource/UnitTests/Integer/bit_reduce.reference_output
diff -c /dev/null llvm-test/SingleSource/UnitTests/Integer/bit_reduce.reference_output:1.1
*** /dev/null	Mon Feb 12 11:53:16 2007
--- llvm-test/SingleSource/UnitTests/Integer/bit_reduce.reference_output	Mon Feb 12 11:52:59 2007
***************
*** 0 ****
--- 1,18 ----
+ Tried to execute an unknown external function: i1 (...) * __builtin_bit_and_reduce
+ /proj/llvm/llvm-2/Debug/bin/lli((anonymous namespace)::PrintStackTrace()+0x1a)[0x871c18a]
+ /proj/llvm/llvm-2/Debug/bin/lli((anonymous namespace)::SignalHandler(int)+0x110)[0x871c4b2]
+ [0x8e5420]
+ /lib/libc.so.6(abort+0x101)[0x3234f1]
+ /proj/llvm/llvm-2/Debug/bin/lli(llvm::Interpreter::callExternalFunction(llvm::Function*, std::vector<llvm::GenericValue, std::allocator<llvm::GenericValue> > const&)+0x138)[0x845428c]
+ /proj/llvm/llvm-2/Debug/bin/lli(llvm::Interpreter::callFunction(llvm::Function*, std::vector<llvm::GenericValue, std::allocator<llvm::GenericValue> > const&)+0x11a)[0x844f356]
+ /proj/llvm/llvm-2/Debug/bin/lli(llvm::Interpreter::visitCallSite(llvm::CallSite)+0x433)[0x844f9d9]
+ /proj/llvm/llvm-2/Debug/bin/lli(llvm::Interpreter::visitCallInst(llvm::CallInst&)+0x2a)[0x845a998]
+ /proj/llvm/llvm-2/Debug/bin/lli(llvm::InstVisitor<llvm::Interpreter, void>::visitCall(llvm::CallInst&)+0x18)[0x845a9b2]
+ /proj/llvm/llvm-2/Debug/bin/lli(llvm::InstVisitor<llvm::Interpreter, void>::visit(llvm::Instruction&)+0x422)[0x845b5cc]
+ /proj/llvm/llvm-2/Debug/bin/lli(llvm::Interpreter::run()+0x9d)[0x8450c21]
+ /proj/llvm/llvm-2/Debug/bin/lli(llvm::Interpreter::runFunction(llvm::Function*, std::vector<llvm::GenericValue, std::allocator<llvm::GenericValue> > const&)+0xc9)[0x84545a1]
+ /proj/llvm/llvm-2/Debug/bin/lli(llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, char const* const*)+0x218)[0x84729ac]
+ /proj/llvm/llvm-2/Debug/bin/lli(main+0x356)[0x83593aa]
+ /lib/libc.so.6(__libc_start_main+0xdc)[0x30f4e4]
+ /proj/llvm/llvm-2/Debug/bin/lli(__gxx_personality_v0+0x191)[0x8358fd1]
+ exit 134


Index: llvm-test/SingleSource/UnitTests/Integer/part_select.c
diff -c /dev/null llvm-test/SingleSource/UnitTests/Integer/part_select.c:1.1
*** /dev/null	Mon Feb 12 11:53:16 2007
--- llvm-test/SingleSource/UnitTests/Integer/part_select.c	Mon Feb 12 11:52:59 2007
***************
*** 0 ****
--- 1,54 ----
+ //===--- part_select.c --- Test The bit_select builtin --------------------===//
+ //
+ // This file was developed by Reid Spencer and is distributed under the 
+ // University of Illinois Open Source License. See LICENSE.TXT for details.
+ //
+ //===----------------------------------------------------------------------===//
+ //
+ // This test case tests the __builtin_part_select builtin function llvm-gcc.
+ // bit_select selects one bit out of a larger 
+ //
+ //===----------------------------------------------------------------------===//
+ 
+ #include <stdio.h>
+ #include <stdlib.h>
+ 
+ #ifdef ENABLE_LARGE_INTEGERS
+ typedef int __attribute__((bitwidth(256))) BitType;
+ const BitType X = 0xAAAAAAAAULL;
+ int numbits = 256;
+ #else
+ typedef int __attribute__((bitwidth(47))) BitType;
+ const BitType X = 0xAAAAAAAAULL;
+ int numbits = 47;
+ #endif
+ 
+ int main(int argc, char** argv)
+ {
+ 
+ #ifdef ENABLE_LARGE_INTEGERS
+   BitType Y = X * X;
+ #else
+   BitType Y = X;
+ #endif
+ 
+   srand(0);
+ 
+   int i, j;
+ 
+   for (i = 1; i <= numbits; ++i) {
+     BitType left = rand() % numbits;
+     BitType right = i;
+     BitType Z = __builtin_part_select(Y, left, right);
+     printf("part_select(Y, %3d, %3d) = ", (int)left, (int)right);
+     for (j = numbits; j > 0; --j) {
+       if (__builtin_bit_select(Z, j))
+         printf("1");
+       else
+         printf("0");
+     }
+     printf("\n");
+   }
+ 
+   return 0;
+ }




Index: llvm-test/SingleSource/UnitTests/Integer/bit_select.c
diff -u llvm-test/SingleSource/UnitTests/Integer/bit_select.c:1.1 llvm-test/SingleSource/UnitTests/Integer/bit_select.c:1.2
--- llvm-test/SingleSource/UnitTests/Integer/bit_select.c:1.1	Mon Feb  5 20:57:54 2007
+++ llvm-test/SingleSource/UnitTests/Integer/bit_select.c	Mon Feb 12 11:52:59 2007
@@ -14,11 +14,11 @@
 
 #ifdef ENABLE_LARGE_INTEGERS
 typedef int __attribute__((bitwidth(250))) BitType;
-const BitType X = 0xAAAAAAAAULL;
+const BitType X = 0xAAAAAAAAAAAAAAAAULL;
 int numbits = 250;
 #else
 typedef int __attribute__((bitwidth(47))) BitType;
-const BitType X = 0xAAAAAAAAULL;
+const BitType X = 0xAAAAAAAAAAAAULL;
 int numbits = 47;
 #endif
 
@@ -31,7 +31,7 @@
   BitType Y = X;
 #endif
 
-  int i;
+  BitType i;
 
   for (i = numbits-1; i >= 0; --i) {
     if (__builtin_bit_select(Y, i)) 






More information about the llvm-commits mailing list