1 1.1 joerg //===-- parityti2_test.c - Test __parityti2 -------------------------------===// 2 1.1 joerg // 3 1.1 joerg // The LLVM Compiler Infrastructure 4 1.1 joerg // 5 1.1 joerg // This file is dual licensed under the MIT and the University of Illinois Open 6 1.1 joerg // Source Licenses. See LICENSE.TXT for details. 7 1.1 joerg // 8 1.1 joerg //===----------------------------------------------------------------------===// 9 1.1 joerg // 10 1.1 joerg // This file tests __parityti2 for the compiler_rt library. 11 1.1 joerg // 12 1.1 joerg //===----------------------------------------------------------------------===// 13 1.1 joerg 14 1.1 joerg #if __x86_64 15 1.1 joerg 16 1.1 joerg #include "int_lib.h" 17 1.1 joerg #include <stdio.h> 18 1.1 joerg #include <stdlib.h> 19 1.1 joerg 20 1.1 joerg // Returns: 1 if number of bits is odd else returns 0 21 1.1 joerg 22 1.1 joerg si_int __parityti2(ti_int a); 23 1.1 joerg 24 1.1 joerg int naive_parity(ti_int a) 25 1.1 joerg { 26 1.1 joerg int r = 0; 27 1.1 joerg for (; a; a = a & (a - 1)) 28 1.1 joerg r = ~r; 29 1.1 joerg return r & 1; 30 1.1 joerg } 31 1.1 joerg 32 1.1 joerg int test__parityti2(ti_int a) 33 1.1 joerg { 34 1.1 joerg si_int x = __parityti2(a); 35 1.1 joerg si_int expected = naive_parity(a); 36 1.1 joerg if (x != expected) 37 1.1 joerg { 38 1.1 joerg twords at; 39 1.1 joerg at.all = a; 40 1.1 joerg printf("error in __parityti2(0x%.16llX%.16llX) = %d, expected %d\n", 41 1.1 joerg at.s.high, at.s.low, x, expected); 42 1.1 joerg } 43 1.1 joerg return x != expected; 44 1.1 joerg } 45 1.1 joerg 46 1.1 joerg char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0}; 47 1.1 joerg char assumption_2[sizeof(di_int)*CHAR_BIT == 64] = {0}; 48 1.1 joerg 49 1.1 joerg #endif 50 1.1 joerg 51 1.1 joerg int main() 52 1.1 joerg { 53 1.1 joerg #if __x86_64 54 1.1 joerg int i; 55 1.1 joerg for (i = 0; i < 10000; ++i) 56 1.1 joerg if (test__parityti2(((ti_int)rand() << 96) + ((ti_int)rand() << 64) + 57 1.1 joerg ((ti_int)rand() << 32) + rand())) 58 1.1 joerg return 1; 59 1.1 joerg 60 1.1 joerg #else 61 1.1 joerg printf("skipped\n"); 62 1.1 joerg #endif 63 1.1 joerg return 0; 64 1.1 joerg } 65