11.1Sjoerg//===-- paritysi2_test.c - Test __paritysi2 -------------------------------===// 21.1Sjoerg// 31.1Sjoerg// The LLVM Compiler Infrastructure 41.1Sjoerg// 51.1Sjoerg// This file is dual licensed under the MIT and the University of Illinois Open 61.1Sjoerg// Source Licenses. See LICENSE.TXT for details. 71.1Sjoerg// 81.1Sjoerg//===----------------------------------------------------------------------===// 91.1Sjoerg// 101.1Sjoerg// This file tests __paritysi2 for the compiler_rt library. 111.1Sjoerg// 121.1Sjoerg//===----------------------------------------------------------------------===// 131.1Sjoerg 141.1Sjoerg#include "int_lib.h" 151.1Sjoerg#include <stdio.h> 161.1Sjoerg#include <stdlib.h> 171.1Sjoerg 181.1Sjoerg// Returns: 1 if number of bits is odd else returns 0 191.1Sjoerg 201.1Sjoergsi_int __paritysi2(si_int a); 211.1Sjoerg 221.1Sjoergint naive_parity(si_int a) 231.1Sjoerg{ 241.1Sjoerg int r = 0; 251.1Sjoerg for (; a; a = a & (a - 1)) 261.1Sjoerg r = ~r; 271.1Sjoerg return r & 1; 281.1Sjoerg} 291.1Sjoerg 301.1Sjoergint test__paritysi2(si_int a) 311.1Sjoerg{ 321.1Sjoerg si_int x = __paritysi2(a); 331.1Sjoerg si_int expected = naive_parity(a); 341.1Sjoerg if (x != expected) 351.1Sjoerg printf("error in __paritysi2(0x%X) = %d, expected %d\n", 361.1Sjoerg a, x, expected); 371.1Sjoerg return x != expected; 381.1Sjoerg} 391.1Sjoerg 401.1Sjoergchar assumption_2[sizeof(si_int)*CHAR_BIT == 32] = {0}; 411.1Sjoerg 421.1Sjoergint main() 431.1Sjoerg{ 441.1Sjoerg int i; 451.1Sjoerg for (i = 0; i < 10000; ++i) 461.1Sjoerg if (test__paritysi2(rand())) 471.1Sjoerg return 1; 481.1Sjoerg 491.1Sjoerg return 0; 501.1Sjoerg} 51