blob: fcb5c2725f26ea1a01d10e508028b9146a6e4967 [file] [log] [blame]
Daniel Dunbarb3a69012009-06-26 16:47:03 +00001//===-- ffsti2_test.c - Test __ffsti2 -------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnant9ad441f2010-11-16 22:13:33 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Daniel Dunbarb3a69012009-06-26 16:47:03 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file tests __ffsti2 for the compiler_rt library.
11//
12//===----------------------------------------------------------------------===//
13
14#if __x86_64
15
16#include "int_lib.h"
17#include <stdio.h>
18
19// Returns: the index of the least significant 1-bit in a, or
20// the value zero if a is zero. The least significant bit is index one.
21
22si_int __ffsti2(ti_int a);
23
24int test__ffsti2(ti_int a, si_int expected)
25{
26 si_int x = __ffsti2(a);
27 if (x != expected)
28 {
29 twords at;
30 at.all = a;
31 printf("error in __ffsti2(0x%llX%.16llX) = %d, expected %d\n",
Daniel Dunbarcff52482009-10-27 17:49:07 +000032 at.s.high, at.s.low, x, expected);
Daniel Dunbarb3a69012009-06-26 16:47:03 +000033 }
34 return x != expected;
35}
36
37char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
38
39#endif
40
41int main()
42{
43#if __x86_64
44 if (test__ffsti2(0x00000000, 0))
45 return 1;
46 if (test__ffsti2(0x00000001, 1))
47 return 1;
48 if (test__ffsti2(0x00000002, 2))
49 return 1;
50 if (test__ffsti2(0x00000003, 1))
51 return 1;
52 if (test__ffsti2(0x00000004, 3))
53 return 1;
54 if (test__ffsti2(0x00000005, 1))
55 return 1;
56 if (test__ffsti2(0x0000000A, 2))
57 return 1;
58 if (test__ffsti2(0x10000000, 29))
59 return 1;
60 if (test__ffsti2(0x20000000, 30))
61 return 1;
62 if (test__ffsti2(0x60000000, 30))
63 return 1;
64 if (test__ffsti2(0x80000000uLL, 32))
65 return 1;
66 if (test__ffsti2(0x0000050000000000uLL, 41))
67 return 1;
68 if (test__ffsti2(0x0200080000000000uLL, 44))
69 return 1;
70 if (test__ffsti2(0x7200000000000000uLL, 58))
71 return 1;
72 if (test__ffsti2(0x8000000000000000uLL, 64))
73 return 1;
74 if (test__ffsti2(make_ti(0x8000000800000000uLL, 0), 100))
75 return 1;
76 if (test__ffsti2(make_ti(0x8000000000000000uLL, 0), 128))
77 return 1;
78
Joerg Sonnenberger74828152011-05-29 21:43:29 +000079#else
80 printf("skipped\n");
Daniel Dunbarb3a69012009-06-26 16:47:03 +000081#endif
82 return 0;
83}