1*4684ddb6SLionel Sambuc //===-- paritysi2_test.c - Test __paritysi2 -------------------------------===// 2*4684ddb6SLionel Sambuc // 3*4684ddb6SLionel Sambuc // The LLVM Compiler Infrastructure 4*4684ddb6SLionel Sambuc // 5*4684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open 6*4684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details. 7*4684ddb6SLionel Sambuc // 8*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===// 9*4684ddb6SLionel Sambuc // 10*4684ddb6SLionel Sambuc // This file tests __paritysi2 for the compiler_rt library. 11*4684ddb6SLionel Sambuc // 12*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===// 13*4684ddb6SLionel Sambuc 14*4684ddb6SLionel Sambuc #include "int_lib.h" 15*4684ddb6SLionel Sambuc #include <stdio.h> 16*4684ddb6SLionel Sambuc #include <stdlib.h> 17*4684ddb6SLionel Sambuc 18*4684ddb6SLionel Sambuc // Returns: 1 if number of bits is odd else returns 0 19*4684ddb6SLionel Sambuc 20*4684ddb6SLionel Sambuc si_int __paritysi2(si_int a); 21*4684ddb6SLionel Sambuc naive_parity(si_int a)22*4684ddb6SLionel Sambucint naive_parity(si_int a) 23*4684ddb6SLionel Sambuc { 24*4684ddb6SLionel Sambuc int r = 0; 25*4684ddb6SLionel Sambuc for (; a; a = a & (a - 1)) 26*4684ddb6SLionel Sambuc r = ~r; 27*4684ddb6SLionel Sambuc return r & 1; 28*4684ddb6SLionel Sambuc } 29*4684ddb6SLionel Sambuc test__paritysi2(si_int a)30*4684ddb6SLionel Sambucint test__paritysi2(si_int a) 31*4684ddb6SLionel Sambuc { 32*4684ddb6SLionel Sambuc si_int x = __paritysi2(a); 33*4684ddb6SLionel Sambuc si_int expected = naive_parity(a); 34*4684ddb6SLionel Sambuc if (x != expected) 35*4684ddb6SLionel Sambuc printf("error in __paritysi2(0x%X) = %d, expected %d\n", 36*4684ddb6SLionel Sambuc a, x, expected); 37*4684ddb6SLionel Sambuc return x != expected; 38*4684ddb6SLionel Sambuc } 39*4684ddb6SLionel Sambuc 40*4684ddb6SLionel Sambuc char assumption_2[sizeof(si_int)*CHAR_BIT == 32] = {0}; 41*4684ddb6SLionel Sambuc main()42*4684ddb6SLionel Sambucint main() 43*4684ddb6SLionel Sambuc { 44*4684ddb6SLionel Sambuc int i; 45*4684ddb6SLionel Sambuc for (i = 0; i < 10000; ++i) 46*4684ddb6SLionel Sambuc if (test__paritysi2(rand())) 47*4684ddb6SLionel Sambuc return 1; 48*4684ddb6SLionel Sambuc 49*4684ddb6SLionel Sambuc return 0; 50*4684ddb6SLionel Sambuc } 51