]> git.proxmox.com Git - rustc.git/blame - src/libcompiler_builtins/compiler-rt/test/builtins/Unit/ffsdi2_test.c
New upstream version 1.28.0+dfsg1
[rustc.git] / src / libcompiler_builtins / compiler-rt / test / builtins / Unit / ffsdi2_test.c
CommitLineData
2c00a5a8 1// RUN: %clang_builtins %s %librt -o %t && %run %t
1a4d82fc
JJ
2//===-- ffsdi2_test.c - Test __ffsdi2 -------------------------------------===//
3//
4// The LLVM Compiler Infrastructure
5//
6// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10//
11// This file tests __ffsdi2 for the compiler_rt library.
12//
13//===----------------------------------------------------------------------===//
14
15#include "int_lib.h"
16#include <stdio.h>
17
18// Returns: the index of the least significant 1-bit in a, or
19// the value zero if a is zero. The least significant bit is index one.
20
92a42be0 21COMPILER_RT_ABI si_int __ffsdi2(di_int a);
1a4d82fc
JJ
22
23int test__ffsdi2(di_int a, si_int expected)
24{
25 si_int x = __ffsdi2(a);
26 if (x != expected)
27 printf("error in __ffsdi2(0x%llX) = %d, expected %d\n", a, x, expected);
28 return x != expected;
29}
30
31char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
32
33int main()
34{
35 if (test__ffsdi2(0x00000000, 0))
36 return 1;
37 if (test__ffsdi2(0x00000001, 1))
38 return 1;
39 if (test__ffsdi2(0x00000002, 2))
40 return 1;
41 if (test__ffsdi2(0x00000003, 1))
42 return 1;
43 if (test__ffsdi2(0x00000004, 3))
44 return 1;
45 if (test__ffsdi2(0x00000005, 1))
46 return 1;
47 if (test__ffsdi2(0x0000000A, 2))
48 return 1;
49 if (test__ffsdi2(0x10000000, 29))
50 return 1;
51 if (test__ffsdi2(0x20000000, 30))
52 return 1;
53 if (test__ffsdi2(0x60000000, 30))
54 return 1;
55 if (test__ffsdi2(0x80000000uLL, 32))
56 return 1;
57 if (test__ffsdi2(0x0000050000000000uLL, 41))
58 return 1;
59 if (test__ffsdi2(0x0200080000000000uLL, 44))
60 return 1;
61 if (test__ffsdi2(0x7200000000000000uLL, 58))
62 return 1;
63 if (test__ffsdi2(0x8000000000000000uLL, 64))
64 return 1;
65
66 return 0;
67}