brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · ec4cf45 Raw
56 lines · c
1// RUN: %clang_builtins %s %librt -o %t && %run %t2// REQUIRES: librt_has_parityti23// REQUIRES: int1284 5#include "int_lib.h"6#include <stdio.h>7#include <stdlib.h>8 9#ifdef CRT_HAS_128BIT10 11// Returns: 1 if number of bits is odd else returns 012 13COMPILER_RT_ABI int __parityti2(ti_int a);14 15int naive_parity(ti_int a)16{17    int r = 0;18    for (; a; a = a & (a - 1))19        r = ~r;20    return r & 1;21}22 23int test__parityti2(ti_int a)24{25    si_int x = __parityti2(a);26    si_int expected = naive_parity(a);27    if (x != expected)28    {29        twords at;30        at.all = a;31        printf("error in __parityti2(0x%.16llX%.16llX) = %d, expected %d\n",32               at.s.high, at.s.low, x, expected);33    }34    return x != expected;35}36 37char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};38char assumption_2[sizeof(di_int)*CHAR_BIT == 64] = {0};39 40#endif41 42int main()43{44#ifdef CRT_HAS_128BIT45    int i;46    for (i = 0; i < 10000; ++i)47        if (test__parityti2(((ti_int)rand() << 96) + ((ti_int)rand() << 64) +48                            ((ti_int)rand() << 32) + rand()))49            return 1;50 51#else52    printf("skipped\n");53#endif54   return 0;55}56