Changes in directory llvm-test/SingleSource/UnitTests/Integer:
bit_concat_cpp.cpp added (r1.1) bit_concat_cpp.reference_output added (r1.1) bit_select_cpp.cpp added (r1.1) bit_select_cpp.reference_output added (r1.1) part_select_cpp.cpp added (r1.1) part_select_cpp.reference_output added (r1.1) --- Log message: Add new test cases for C++ form of bit builtins --- Diffs of the changes: (+333 -0) bit_concat_cpp.cpp | 62 ++++++++++++++++++++ bit_concat_cpp.reference_output | 119 +++++++++++++++++++++++++++++++++++++++ bit_select_cpp.cpp | 45 ++++++++++++++ bit_select_cpp.reference_output | 2 part_select_cpp.cpp | 57 ++++++++++++++++++ part_select_cpp.reference_output | 48 +++++++++++++++ 6 files changed, 333 insertions(+) Index: llvm-test/SingleSource/UnitTests/Integer/bit_concat_cpp.cpp diff -c /dev/null llvm-test/SingleSource/UnitTests/Integer/bit_concat_cpp.cpp:1.1 *** /dev/null Wed Mar 28 11:32:00 2007 --- llvm-test/SingleSource/UnitTests/Integer/bit_concat_cpp.cpp Wed Mar 28 11:31:50 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; 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_cpp.reference_output diff -c /dev/null llvm-test/SingleSource/UnitTests/Integer/bit_concat_cpp.reference_output:1.1 *** /dev/null Wed Mar 28 11:32:07 2007 --- llvm-test/SingleSource/UnitTests/Integer/bit_concat_cpp.reference_output Wed Mar 28 11:31:50 2007 *************** *** 0 **** --- 1,119 ---- + bit_concat(00111100000001110,0010011010011011100) = 001111000000011100010011010011011100 + bit_concat(01011110001011010,0000001001101010000) = 010111100010110100000001001101010000 + bit_concat(01001100001011000,0101011010000011010) = 010011000010110000101011010000011010 + bit_concat(00000100110101110,0100100011111011011) = 000001001101011100100100011111011011 + bit_concat(01110100110111110,0100100001100001010) = 011101001101111100100100001100001010 + bit_concat(01000010101001000,0000111111111110111) = 010000101010010000000111111111110111 + bit_concat(01111011100100110,0010101010110011100) = 011110111001001100010101010110011100 + bit_concat(00010000001001001,0010001000110010000) = 000100000010010010010001000110010000 + bit_concat(00100011011111010,0001001100100000101) = 001000110111110100001001100100000101 + bit_concat(01010100111100110,0011011011100011010) = 010101001111001100011011011100011010 + bit_concat(01000110110000101,0111101101000001000) = 010001101100001010111101101000001000 + bit_concat(00011011111011110,0010111101101101100) = 000110111110111100010111101101101100 + bit_concat(01010110001001111,0001111000000001010) = 010101100010011110001111000000001010 + bit_concat(00000111000110001,0010010000101101111) = 000001110001100010010010000101101111 + bit_concat(00010000000100100,0000001111010110001) = 000100000001001000000001111010110001 + bit_concat(01111101011001101,0100101101001100010) = 011111010110011010100101101001100010 + bit_concat(00111101010001000,0001101011111101000) = 001111010100010000001101011111101000 + bit_concat(00001001101011000,0111100010110110111) = 000010011010110000111100010110110111 + bit_concat(01011011111011100,0000011100101110100) = 010110111110111000000011100101110100 + bit_concat(01110011101111110,0011101010111100011) = 011100111011111100011101010111100011 + bit_concat(00000011110111000,0100011100101010110) = 000000111101110000100011100101010110 + bit_concat(00001001101111001,0100110101110101100) = 000010011011110010100110101110101100 + bit_concat(00111110010100101,0100011111000000001) = 001111100101001010100011111000000001 + bit_concat(01010000011010000,0111111100100111101) = 010100000110100000111111100100111101 + bit_concat(00101000000100011,0100110101011111010) = 001010000001000110100110101011111010 + bit_concat(01011100111010011,0100001110001010000) = 010111001110100110100001110001010000 + bit_concat(01000101000101001,0100000101001000000) = 010001010001010010100000101001000000 + bit_concat(01111111011111111,0101000000000101011) = 011111110111111110101000000000101011 + bit_concat(00001001110010000,0001010100001100011) = 000010011100100000001010100001100011 + bit_concat(01010111110100001,0001001100101100110) = 010101111101000010001001100101100110 + bit_concat(00011010010100110,0010010100111001010) = 000110100101001100010010100111001010 + bit_concat(00001001010011011,0111100000100000010) = 000010010100110110111100000100000010 + bit_concat(01110000101011100,0010101101110101110) = 011100001010111000010101101110101110 + bit_concat(01001100000101000,0111100100111101100) = 010011000001010000111100100111101100 + bit_concat(00110100001000111,0110101111001001110) = 001101000010001110110101111001001110 + bit_concat(01011100011111010,0011111000011001000) = 010111000111110100011111000011001000 + bit_concat(00001011100101100,0110110110010010110) = 000010111001011000110110110010010110 + bit_concat(01101111001111010,0110011001110101000) = 011011110011110100110011001110101000 + bit_concat(01000111010100000,0100011101001100100) = 010001110101000000100011101001100100 + bit_concat(01110000000001000,0110011101011000010) = 011100000000010000110011101011000010 + bit_concat(01001000100100010,0000100000001000001) = 010010001001000100000100000001000001 + bit_concat(00111011010010001,0011011110110011010) = 001110110100100010011011110110011010 + bit_concat(00101001011011101,0000010011110110110) = 001010010110111010000010011110110110 + bit_concat(00111010111001001,0010010001111101000) = 001110101110010010010010001111101000 + bit_concat(01010110011101101,0000010100000000010) = 010101100111011010000010100000000010 + bit_concat(00101001111110110,0110010010011111000) = 001010011111101100110010010011111000 + bit_concat(00111000011011111,0111101010110110001) = 001110000110111110111101010110110001 + bit_concat(01110100011101010,0011100101000111111) = 011101000111010100011100101000111111 + bit_concat(01100110010000111,0010110100011010110) = 011001100100001110010110100011010110 + bit_concat(00100110101101001,0101111010000010110) = 001001101011010010101111010000010110 + bit_concat(00001011110001110,0001101100100000001) = 000010111100011100001101100100000001 + bit_concat(01100100010010001,0000000001101011111) = 011001000100100010000000001101011111 + bit_concat(01001000001001011,0100011010111010001) = 010010000010010110100011010111010001 + bit_concat(00011111010100100,0100111000100011000) = 000111110101001000100111000100011000 + bit_concat(01110010001010110,0000011100000001111) = 011100100010101100000011100000001111 + bit_concat(00011100111111001,0101100100001110111) = 000111001111110010101100100001110111 + bit_concat(01100011111010101,0000000001010101001) = 011000111110101010000000001010101001 + bit_concat(01111010100001101,0011111001101100011) = 011110101000011010011111001101100011 + bit_concat(01111001111001001,0110000111110101011) = 011110011110010010110000111110101011 + bit_concat(01010001101010110,0011101111100000000) = 010100011010101100011101111100000000 + bit_concat(00100001001001110,0011101000010010010) = 001000010010011100011101000010010010 + bit_concat(00110010111110101,0010011000000000110) = 001100101111101010010011000000000110 + bit_concat(01010111101111011,0010110110110111101) = 010101111011110110010110110110111101 + bit_concat(01001111110011010,0111000011101001000) = 010011111100110100111000011101001000 + bit_concat(01101010110101011,0111001001100101100) = 011010101101010110111001001100101100 + bit_concat(01100111010010100,0100011011001011111) = 011001110100101000100011011001011111 + bit_concat(00011110100101011,0000100001100100111) = 000111101001010110000100001100100111 + bit_concat(00111111010000011,0100110101000101100) = 001111110100000110100110101000101100 + bit_concat(01110010011011010,0010110110000001011) = 011100100110110100010110110000001011 + bit_concat(00001100000000001,0000010111010011000) = 000011000000000010000010111010011000 + bit_concat(00101101101001001,0101010010110000101) = 001011011010010010101010010110000101 + bit_concat(01011111010011001,0010011010100001111) = 010111110100110010010011010100001111 + bit_concat(00011010110011011,0100110110101011000) = 000110101100110110100110110101011000 + bit_concat(01100111011000001,0000011110000011111) = 011001110110000010000011110000011111 + bit_concat(00111011011101111,0000000011101011111) = 001110110111011110000000011101011111 + bit_concat(00010000101111111,0011101011000100110) = 000100001011111110011101011000100110 + bit_concat(00110001010110100,0000101111110000110) = 001100010101101000000101111110000110 + bit_concat(01111010001011100,0111000000110111100) = 011110100010111000111000000110111100 + bit_concat(01111001111100010,0101010011100011101) = 011110011111000100101010011100011101 + bit_concat(00001110111111101,0110000001011100101) = 000011101111111010110000001011100101 + bit_concat(01110100010101000,0001100111101001011) = 011101000101010000001100111101001011 + bit_concat(01111001100100010,0010100001100110001) = 011110011001000100010100001100110001 + bit_concat(00000011110100001,0000111000011111110) = 000000111101000010000111000011111110 + bit_concat(01110100000101100,0101000110011010101) = 011101000001011000101000110011010101 + bit_concat(00110000100110000,0110111000110000110) = 001100001001100000110111000110000110 + bit_concat(00000001001000101,0101110111100100100) = 000000010010001010101110111100100100 + bit_concat(00100111101111100,0101011011100100111) = 001001111011111000101011011100100111 + bit_concat(00010100010111101,0001110100011111110) = 000101000101111010001110100011111110 + bit_concat(01011000011111110,0101100110001000011) = 010110000111111100101100110001000011 + bit_concat(01010100001000011,0001011110101111101) = 010101000010000110001011110101111101 + bit_concat(00100001010010010,0011011000110010011) = 001000010100100100011011000110010011 + bit_concat(01010010111111100,0100111110111000011) = 010100101111111000100111110111000011 + bit_concat(00101010100101100,0110111011100010110) = 001010101001011000110111011100010110 + bit_concat(00001101010101001,0111101100011001010) = 000011010101010010111101100011001010 + bit_concat(01000010110010001,0101100001110001001) = 010000101100100010101100001110001001 + bit_concat(01011000000101010,0001110110011110111) = 010110000001010100001110110011110111 + bit_concat(01101101001001010,0111011100101100001) = 011011010010010100111011100101100001 + bit_concat(00100011110110010,0011001011000000101) = 001000111101100100011001011000000101 + bit_concat(01001010011001110,0101001001110001000) = 010010100110011100101001001110001000 + bit_concat(01110010010011001,0001110111111111001) = 011100100100110010001110111111111001 + bit_concat(00011010110010000,0110001101001011000) = 000110101100100000110001101001011000 + bit_concat(01010110100111101,0111010011110011000) = 010101101001111010111010011110011000 + bit_concat(00010001011111001,0011011010111111101) = 000100010111110010011011010111111101 + bit_concat(00000011101000010,0000111010100001001) = 000000111010000100000111010100001001 + bit_concat(00010100101110111,0010100101001111101) = 000101001011101110010100101001111101 + bit_concat(00100101110001100,0111001110111001000) = 001001011100011000111001110111001000 + bit_concat(00100000111100010,0010101011111100100) = 001000001111000100010101011111100100 + bit_concat(00001111110100101,0110011101111101000) = 000011111101001010110011101111101000 + bit_concat(01111101011110110,0110010000101000111) = 011111010111101100110010000101000111 + bit_concat(01011100111110101,0010001101000111000) = 010111001111101010010001101000111000 + bit_concat(00010001011111000,0111011010110001011) = 000100010111110000111011010110001011 + bit_concat(00011001111100110,0101110011100000010) = 000110011111001100101110011100000010 + bit_concat(00101011000011001,0111001001101111010) = 001010110000110010111001001101111010 + bit_concat(00101100100011101,0101111000101100001) = 001011001000111010101111000101100001 + bit_concat(00100101110001010,0101111101101001101) = 001001011100010100101111101101001101 + bit_concat(01110101000101111,0101010010100101000) = 011101010001011110101010010100101000 + bit_concat(00110100100011001,0010010100000010101) = 001101001000110010010010100000010101 + bit_concat(01101100000011111,0100110011010101100) = 011011000000111110100110011010101100 + exit 0 Index: llvm-test/SingleSource/UnitTests/Integer/bit_select_cpp.cpp diff -c /dev/null llvm-test/SingleSource/UnitTests/Integer/bit_select_cpp.cpp:1.1 *** /dev/null Wed Mar 28 11:32:07 2007 --- llvm-test/SingleSource/UnitTests/Integer/bit_select_cpp.cpp Wed Mar 28 11:31:50 2007 *************** *** 0 **** --- 1,45 ---- + //===--- bit_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_bit_select builtin function llvm-gcc. + // bit_select selects one bit out of a larger + // + //===----------------------------------------------------------------------===// + + #include <stdio.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 + + int main(int argc, char** argv) + { + + #ifdef ENABLE_LARGE_INTEGERS + BitType Y = X * X; + #else + BitType Y = X; + #endif + + BitType i; + + for (i = numbits-1; i >= 0; --i) { + if (__builtin_bit_select(Y, i)) + printf("1"); + else + printf("0"); + } + + printf("\n"); + return 0; + } Index: llvm-test/SingleSource/UnitTests/Integer/bit_select_cpp.reference_output diff -c /dev/null llvm-test/SingleSource/UnitTests/Integer/bit_select_cpp.reference_output:1.1 *** /dev/null Wed Mar 28 11:32:07 2007 --- llvm-test/SingleSource/UnitTests/Integer/bit_select_cpp.reference_output Wed Mar 28 11:31:50 2007 *************** *** 0 **** --- 1,2 ---- + 01010101010101010101010101010101010101010101010 + exit 0 Index: llvm-test/SingleSource/UnitTests/Integer/part_select_cpp.cpp diff -c /dev/null llvm-test/SingleSource/UnitTests/Integer/part_select_cpp.cpp:1.1 *** /dev/null Wed Mar 28 11:32:07 2007 --- llvm-test/SingleSource/UnitTests/Integer/part_select_cpp.cpp Wed Mar 28 11:31:50 2007 *************** *** 0 **** --- 1,57 ---- + //===--- 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> + #include <stdint.h> + + #ifdef ENABLE_LARGE_INTEGERS + typedef unsigned __attribute__((bitwidth(256))) BitType; + const BitType X = 0xFEDCBA9876543210ULL; + unsigned numbits = 256; + #else + typedef unsigned __attribute__((bitwidth(47))) BitType; + const BitType X = 0xFEDCBA9876543210ULL; + unsigned numbits = 47; + #endif + + int main(int argc, char** argv) + { + + #ifdef ENABLE_LARGE_INTEGERS + BitType Y = X * X; + #else + BitType Y = X; + #endif + + srand(0); + + unsigned i, j; + + for (i = 0; i < numbits; ++i) { + BitType left = rand() % numbits; + BitType right = i; + printf("part_select(Y, %3u, %3u) = ", (unsigned)left, (unsigned)right); + BitType Z = __builtin_bit_part_select(Y, left, right); + for (j = numbits; j > 0; --j) { + if (__builtin_bit_select(Z, j-1)) + printf("1"); + else + printf("0"); + } + uint64_t val = Z; + printf(" (%lx)", val); + printf("\n"); + } + + return 0; + } Index: llvm-test/SingleSource/UnitTests/Integer/part_select_cpp.reference_output diff -c /dev/null llvm-test/SingleSource/UnitTests/Integer/part_select_cpp.reference_output:1.1 *** /dev/null Wed Mar 28 11:32:07 2007 --- llvm-test/SingleSource/UnitTests/Integer/part_select_cpp.reference_output Wed Mar 28 11:31:50 2007 *************** *** 0 **** --- 1,48 ---- + part_select(Y, 38, 0) = 00000000001100001110110010101000011001000010000 (76543210) + part_select(Y, 4, 1) = 00000000000000000000000000000000000000000001000 (8) + part_select(Y, 18, 2) = 00000000000000000000000000000010000110010000100 (10c84) + part_select(Y, 23, 3) = 00000000000000000000000000010101000011001000010 (a8642) + part_select(Y, 17, 4) = 00000000000000000000000000000000000001100100001 (321) + part_select(Y, 26, 5) = 00000000000000000000000001100101010000110010000 (32a190) + part_select(Y, 16, 6) = 00000000000000000000000000000000000000011001000 (c8) + part_select(Y, 3, 7) = 00000000000000000000000000000000000000000001000 (8) + part_select(Y, 28, 8) = 00000000000000000000000000101100101010000110010 (165432) + part_select(Y, 28, 9) = 00000000000000000000000000010110010101000011001 (b2a19) + part_select(Y, 10, 10) = 00000000000000000000000000000000000000000000000 (0) + part_select(Y, 17, 11) = 00000000000000000000000000000000000000000000110 (6) + part_select(Y, 44, 12) = 00000000000000110101001100001110110010101000011 (a9876543) + part_select(Y, 28, 13) = 00000000000000000000000000000001011001010100001 (b2a1) + part_select(Y, 2, 14) = 00000000000000000000000000000000000010000100110 (426) + part_select(Y, 20, 15) = 00000000000000000000000000000000000000000101000 (28) + part_select(Y, 22, 16) = 00000000000000000000000000000000000000001010100 (54) + part_select(Y, 21, 17) = 00000000000000000000000000000000000000000001010 (a) + part_select(Y, 18, 18) = 00000000000000000000000000000000000000000000001 (1) + part_select(Y, 36, 19) = 00000000000000000000000000000110000111011001010 (30eca) + part_select(Y, 34, 20) = 00000000000000000000000000000000000011101100101 (765) + part_select(Y, 37, 21) = 00000000000000000000000000000001100001110110010 (c3b2) + part_select(Y, 18, 22) = 00000000000000000000000000000000000000000010101 (15) + part_select(Y, 38, 23) = 00000000000000000000000000000000011000011101100 (30ec) + part_select(Y, 20, 24) = 00000000000000000000000000000000000000000010100 (14) + part_select(Y, 1, 25) = 00000000000000000000000001000010011000010101001 (2130a9) + part_select(Y, 31, 26) = 00000000000000000000000000000000000000000011101 (1d) + part_select(Y, 17, 27) = 00000000000000000000000000000000000001010100110 (2a6) + part_select(Y, 20, 28) = 00000000000000000000000000000000000000101001101 (14d) + part_select(Y, 6, 29) = 00000000000000000000000000100110000101010011011 (130a9b) + part_select(Y, 27, 30) = 00000000000000000000000000000000000000000000111 (7) + part_select(Y, 37, 31) = 00000000000000000000000000000000000000000110000 (30) + part_select(Y, 11, 32) = 00000000000000000000000000110000101010011011100 (1854dc) + part_select(Y, 24, 33) = 00000000000000000000000000000000000000110111000 (1b8) + part_select(Y, 39, 34) = 00000000000000000000000000000000000000000100110 (26) + part_select(Y, 7, 35) = 00000000000000000000100110000101010011011100001 (4c2a6e1) + part_select(Y, 3, 36) = 00000000000000100001001100001010100110111000011 (9854dc3) + part_select(Y, 9, 37) = 00000000000000000010011000010101001101110000110 (130a9b86) + part_select(Y, 36, 38) = 00000000000000000000000000000000000000000000100 (4) + part_select(Y, 31, 39) = 00000000000000000000000000000000000000000011001 (19) + part_select(Y, 16, 40) = 00000000000000000000000010101001101110000110010 (54dc32) + part_select(Y, 46, 41) = 00000000000000000000000000000000000000000011101 (1d) + part_select(Y, 27, 42) = 00000000000000000000000000000000111000011001010 (70ca) + part_select(Y, 13, 43) = 00000000000000001000010101001101110000110010101 (42a6e195) + part_select(Y, 6, 44) = 00000000000100110000101010011011100001100101011 (854dc32b) + part_select(Y, 9, 45) = 00000000001001100001010100110111000011001010111 (a9b8657) + part_select(Y, 13, 46) = 00000000000001000010101001101110000110010101110 (15370cae) + exit 0 _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits