Home | History | Annotate | Download | only in Unit
      1 //===-- ctzsi2_test.c - Test __ctzsi2 -------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file tests __ctzsi2 for the compiler_rt library.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #include "int_lib.h"
     15 #include <stdio.h>
     16 
     17 // Returns: the number of trailing 0-bits
     18 
     19 // Precondition: a != 0
     20 
     21 si_int __ctzsi2(si_int a);
     22 
     23 int test__ctzsi2(si_int a, si_int expected)
     24 {
     25     si_int x = __ctzsi2(a);
     26     if (x != expected)
     27         printf("error in __ctzsi2(0x%X) = %d, expected %d\n", a, x, expected);
     28     return x != expected;
     29 }
     30 
     31 char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
     32 char assumption_2[sizeof(si_int)*CHAR_BIT == 32] = {0};
     33 
     34 int main()
     35 {
     36 //     if (test__ctzsi2(0x00000000, 32))  // undefined
     37 //         return 1;
     38     if (test__ctzsi2(0x00000001, 0))
     39         return 1;
     40     if (test__ctzsi2(0x00000002, 1))
     41         return 1;
     42     if (test__ctzsi2(0x00000003, 0))
     43         return 1;
     44     if (test__ctzsi2(0x00000004, 2))
     45         return 1;
     46     if (test__ctzsi2(0x00000005, 0))
     47         return 1;
     48     if (test__ctzsi2(0x00000006, 1))
     49         return 1;
     50     if (test__ctzsi2(0x00000007, 0))
     51         return 1;
     52     if (test__ctzsi2(0x00000008, 3))
     53         return 1;
     54     if (test__ctzsi2(0x00000009, 0))
     55         return 1;
     56     if (test__ctzsi2(0x0000000A, 1))
     57         return 1;
     58     if (test__ctzsi2(0x0000000B, 0))
     59         return 1;
     60     if (test__ctzsi2(0x0000000C, 2))
     61         return 1;
     62     if (test__ctzsi2(0x0000000D, 0))
     63         return 1;
     64     if (test__ctzsi2(0x0000000E, 1))
     65         return 1;
     66     if (test__ctzsi2(0x0000000F, 0))
     67         return 1;
     68     if (test__ctzsi2(0x00000010, 4))
     69         return 1;
     70     if (test__ctzsi2(0x00000012, 1))
     71         return 1;
     72     if (test__ctzsi2(0x00000013, 0))
     73         return 1;
     74     if (test__ctzsi2(0x00000014, 2))
     75         return 1;
     76     if (test__ctzsi2(0x00000015, 0))
     77         return 1;
     78     if (test__ctzsi2(0x00000016, 1))
     79         return 1;
     80     if (test__ctzsi2(0x00000017, 0))
     81         return 1;
     82     if (test__ctzsi2(0x00000018, 3))
     83         return 1;
     84     if (test__ctzsi2(0x00000019, 0))
     85         return 1;
     86     if (test__ctzsi2(0x0000001A, 1))
     87         return 1;
     88     if (test__ctzsi2(0x0000001B, 0))
     89         return 1;
     90     if (test__ctzsi2(0x0000001C, 2))
     91         return 1;
     92     if (test__ctzsi2(0x0000001D, 0))
     93         return 1;
     94     if (test__ctzsi2(0x0000001E, 1))
     95         return 1;
     96     if (test__ctzsi2(0x0000001F, 0))
     97         return 1;
     98     if (test__ctzsi2(0x00000020, 5))
     99         return 1;
    100     if (test__ctzsi2(0x00000022, 1))
    101         return 1;
    102     if (test__ctzsi2(0x00000023, 0))
    103         return 1;
    104     if (test__ctzsi2(0x00000024, 2))
    105         return 1;
    106     if (test__ctzsi2(0x00000025, 0))
    107         return 1;
    108     if (test__ctzsi2(0x00000026, 1))
    109         return 1;
    110     if (test__ctzsi2(0x00000027, 0))
    111         return 1;
    112     if (test__ctzsi2(0x00000028, 3))
    113         return 1;
    114     if (test__ctzsi2(0x00000029, 0))
    115         return 1;
    116     if (test__ctzsi2(0x0000002A, 1))
    117         return 1;
    118     if (test__ctzsi2(0x0000002B, 0))
    119         return 1;
    120     if (test__ctzsi2(0x0000002C, 2))
    121         return 1;
    122     if (test__ctzsi2(0x0000002D, 0))
    123         return 1;
    124     if (test__ctzsi2(0x0000002E, 1))
    125         return 1;
    126     if (test__ctzsi2(0x0000002F, 0))
    127         return 1;
    128     if (test__ctzsi2(0x00000030, 4))
    129         return 1;
    130     if (test__ctzsi2(0x00000032, 1))
    131         return 1;
    132     if (test__ctzsi2(0x00000033, 0))
    133         return 1;
    134     if (test__ctzsi2(0x00000034, 2))
    135         return 1;
    136     if (test__ctzsi2(0x00000035, 0))
    137         return 1;
    138     if (test__ctzsi2(0x00000036, 1))
    139         return 1;
    140     if (test__ctzsi2(0x00000037, 0))
    141         return 1;
    142     if (test__ctzsi2(0x00000038, 3))
    143         return 1;
    144     if (test__ctzsi2(0x00000039, 0))
    145         return 1;
    146     if (test__ctzsi2(0x0000003A, 1))
    147         return 1;
    148     if (test__ctzsi2(0x0000003B, 0))
    149         return 1;
    150     if (test__ctzsi2(0x0000003C, 2))
    151         return 1;
    152     if (test__ctzsi2(0x0000003D, 0))
    153         return 1;
    154     if (test__ctzsi2(0x0000003E, 1))
    155         return 1;
    156     if (test__ctzsi2(0x0000003F, 0))
    157         return 1;
    158     if (test__ctzsi2(0x00000040, 6))
    159         return 1;
    160     if (test__ctzsi2(0x00000042, 1))
    161         return 1;
    162     if (test__ctzsi2(0x00000043, 0))
    163         return 1;
    164     if (test__ctzsi2(0x00000044, 2))
    165         return 1;
    166     if (test__ctzsi2(0x00000045, 0))
    167         return 1;
    168     if (test__ctzsi2(0x00000046, 1))
    169         return 1;
    170     if (test__ctzsi2(0x00000047, 0))
    171         return 1;
    172     if (test__ctzsi2(0x00000048, 3))
    173         return 1;
    174     if (test__ctzsi2(0x00000049, 0))
    175         return 1;
    176     if (test__ctzsi2(0x0000004A, 1))
    177         return 1;
    178     if (test__ctzsi2(0x0000004B, 0))
    179         return 1;
    180     if (test__ctzsi2(0x0000004C, 2))
    181         return 1;
    182     if (test__ctzsi2(0x0000004D, 0))
    183         return 1;
    184     if (test__ctzsi2(0x0000004E, 1))
    185         return 1;
    186     if (test__ctzsi2(0x0000004F, 0))
    187         return 1;
    188     if (test__ctzsi2(0x00000050, 4))
    189         return 1;
    190     if (test__ctzsi2(0x00000052, 1))
    191         return 1;
    192     if (test__ctzsi2(0x00000053, 0))
    193         return 1;
    194     if (test__ctzsi2(0x00000054, 2))
    195         return 1;
    196     if (test__ctzsi2(0x00000055, 0))
    197         return 1;
    198     if (test__ctzsi2(0x00000056, 1))
    199         return 1;
    200     if (test__ctzsi2(0x00000057, 0))
    201         return 1;
    202     if (test__ctzsi2(0x00000058, 3))
    203         return 1;
    204     if (test__ctzsi2(0x00000059, 0))
    205         return 1;
    206     if (test__ctzsi2(0x0000005A, 1))
    207         return 1;
    208     if (test__ctzsi2(0x0000005B, 0))
    209         return 1;
    210     if (test__ctzsi2(0x0000005C, 2))
    211         return 1;
    212     if (test__ctzsi2(0x0000005D, 0))
    213         return 1;
    214     if (test__ctzsi2(0x0000005E, 1))
    215         return 1;
    216     if (test__ctzsi2(0x0000005F, 0))
    217         return 1;
    218     if (test__ctzsi2(0x00000060, 5))
    219         return 1;
    220     if (test__ctzsi2(0x00000062, 1))
    221         return 1;
    222     if (test__ctzsi2(0x00000063, 0))
    223         return 1;
    224     if (test__ctzsi2(0x00000064, 2))
    225         return 1;
    226     if (test__ctzsi2(0x00000065, 0))
    227         return 1;
    228     if (test__ctzsi2(0x00000066, 1))
    229         return 1;
    230     if (test__ctzsi2(0x00000067, 0))
    231         return 1;
    232     if (test__ctzsi2(0x00000068, 3))
    233         return 1;
    234     if (test__ctzsi2(0x00000069, 0))
    235         return 1;
    236     if (test__ctzsi2(0x0000006A, 1))
    237         return 1;
    238     if (test__ctzsi2(0x0000006B, 0))
    239         return 1;
    240     if (test__ctzsi2(0x0000006C, 2))
    241         return 1;
    242     if (test__ctzsi2(0x0000006D, 0))
    243         return 1;
    244     if (test__ctzsi2(0x0000006E, 1))
    245         return 1;
    246     if (test__ctzsi2(0x0000006F, 0))
    247         return 1;
    248     if (test__ctzsi2(0x00000070, 4))
    249         return 1;
    250     if (test__ctzsi2(0x00000072, 1))
    251         return 1;
    252     if (test__ctzsi2(0x00000073, 0))
    253         return 1;
    254     if (test__ctzsi2(0x00000074, 2))
    255         return 1;
    256     if (test__ctzsi2(0x00000075, 0))
    257         return 1;
    258     if (test__ctzsi2(0x00000076, 1))
    259         return 1;
    260     if (test__ctzsi2(0x00000077, 0))
    261         return 1;
    262     if (test__ctzsi2(0x00000078, 3))
    263         return 1;
    264     if (test__ctzsi2(0x00000079, 0))
    265         return 1;
    266     if (test__ctzsi2(0x0000007A, 1))
    267         return 1;
    268     if (test__ctzsi2(0x0000007B, 0))
    269         return 1;
    270     if (test__ctzsi2(0x0000007C, 2))
    271         return 1;
    272     if (test__ctzsi2(0x0000007D, 0))
    273         return 1;
    274     if (test__ctzsi2(0x0000007E, 1))
    275         return 1;
    276     if (test__ctzsi2(0x0000007F, 0))
    277         return 1;
    278     if (test__ctzsi2(0x00000080, 7))
    279         return 1;
    280     if (test__ctzsi2(0x00000082, 1))
    281         return 1;
    282     if (test__ctzsi2(0x00000083, 0))
    283         return 1;
    284     if (test__ctzsi2(0x00000084, 2))
    285         return 1;
    286     if (test__ctzsi2(0x00000085, 0))
    287         return 1;
    288     if (test__ctzsi2(0x00000086, 1))
    289         return 1;
    290     if (test__ctzsi2(0x00000087, 0))
    291         return 1;
    292     if (test__ctzsi2(0x00000088, 3))
    293         return 1;
    294     if (test__ctzsi2(0x00000089, 0))
    295         return 1;
    296     if (test__ctzsi2(0x0000008A, 1))
    297         return 1;
    298     if (test__ctzsi2(0x0000008B, 0))
    299         return 1;
    300     if (test__ctzsi2(0x0000008C, 2))
    301         return 1;
    302     if (test__ctzsi2(0x0000008D, 0))
    303         return 1;
    304     if (test__ctzsi2(0x0000008E, 1))
    305         return 1;
    306     if (test__ctzsi2(0x0000008F, 0))
    307         return 1;
    308     if (test__ctzsi2(0x00000090, 4))
    309         return 1;
    310     if (test__ctzsi2(0x00000092, 1))
    311         return 1;
    312     if (test__ctzsi2(0x00000093, 0))
    313         return 1;
    314     if (test__ctzsi2(0x00000094, 2))
    315         return 1;
    316     if (test__ctzsi2(0x00000095, 0))
    317         return 1;
    318     if (test__ctzsi2(0x00000096, 1))
    319         return 1;
    320     if (test__ctzsi2(0x00000097, 0))
    321         return 1;
    322     if (test__ctzsi2(0x00000098, 3))
    323         return 1;
    324     if (test__ctzsi2(0x00000099, 0))
    325         return 1;
    326     if (test__ctzsi2(0x0000009A, 1))
    327         return 1;
    328     if (test__ctzsi2(0x0000009B, 0))
    329         return 1;
    330     if (test__ctzsi2(0x0000009C, 2))
    331         return 1;
    332     if (test__ctzsi2(0x0000009D, 0))
    333         return 1;
    334     if (test__ctzsi2(0x0000009E, 1))
    335         return 1;
    336     if (test__ctzsi2(0x0000009F, 0))
    337         return 1;
    338     if (test__ctzsi2(0x000000A0, 5))
    339         return 1;
    340     if (test__ctzsi2(0x000000A2, 1))
    341         return 1;
    342     if (test__ctzsi2(0x000000A3, 0))
    343         return 1;
    344     if (test__ctzsi2(0x000000A4, 2))
    345         return 1;
    346     if (test__ctzsi2(0x000000A5, 0))
    347         return 1;
    348     if (test__ctzsi2(0x000000A6, 1))
    349         return 1;
    350     if (test__ctzsi2(0x000000A7, 0))
    351         return 1;
    352     if (test__ctzsi2(0x000000A8, 3))
    353         return 1;
    354     if (test__ctzsi2(0x000000A9, 0))
    355         return 1;
    356     if (test__ctzsi2(0x000000AA, 1))
    357         return 1;
    358     if (test__ctzsi2(0x000000AB, 0))
    359         return 1;
    360     if (test__ctzsi2(0x000000AC, 2))
    361         return 1;
    362     if (test__ctzsi2(0x000000AD, 0))
    363         return 1;
    364     if (test__ctzsi2(0x000000AE, 1))
    365         return 1;
    366     if (test__ctzsi2(0x000000AF, 0))
    367         return 1;
    368     if (test__ctzsi2(0x000000B0, 4))
    369         return 1;
    370     if (test__ctzsi2(0x000000B2, 1))
    371         return 1;
    372     if (test__ctzsi2(0x000000B3, 0))
    373         return 1;
    374     if (test__ctzsi2(0x000000B4, 2))
    375         return 1;
    376     if (test__ctzsi2(0x000000B5, 0))
    377         return 1;
    378     if (test__ctzsi2(0x000000B6, 1))
    379         return 1;
    380     if (test__ctzsi2(0x000000B7, 0))
    381         return 1;
    382     if (test__ctzsi2(0x000000B8, 3))
    383         return 1;
    384     if (test__ctzsi2(0x000000B9, 0))
    385         return 1;
    386     if (test__ctzsi2(0x000000BA, 1))
    387         return 1;
    388     if (test__ctzsi2(0x000000BB, 0))
    389         return 1;
    390     if (test__ctzsi2(0x000000BC, 2))
    391         return 1;
    392     if (test__ctzsi2(0x000000BD, 0))
    393         return 1;
    394     if (test__ctzsi2(0x000000BE, 1))
    395         return 1;
    396     if (test__ctzsi2(0x000000BF, 0))
    397         return 1;
    398     if (test__ctzsi2(0x000000C0, 6))
    399         return 1;
    400     if (test__ctzsi2(0x000000C2, 1))
    401         return 1;
    402     if (test__ctzsi2(0x000000C3, 0))
    403         return 1;
    404     if (test__ctzsi2(0x000000C4, 2))
    405         return 1;
    406     if (test__ctzsi2(0x000000C5, 0))
    407         return 1;
    408     if (test__ctzsi2(0x000000C6, 1))
    409         return 1;
    410     if (test__ctzsi2(0x000000C7, 0))
    411         return 1;
    412     if (test__ctzsi2(0x000000C8, 3))
    413         return 1;
    414     if (test__ctzsi2(0x000000C9, 0))
    415         return 1;
    416     if (test__ctzsi2(0x000000CA, 1))
    417         return 1;
    418     if (test__ctzsi2(0x000000CB, 0))
    419         return 1;
    420     if (test__ctzsi2(0x000000CC, 2))
    421         return 1;
    422     if (test__ctzsi2(0x000000CD, 0))
    423         return 1;
    424     if (test__ctzsi2(0x000000CE, 1))
    425         return 1;
    426     if (test__ctzsi2(0x000000CF, 0))
    427         return 1;
    428     if (test__ctzsi2(0x000000D0, 4))
    429         return 1;
    430     if (test__ctzsi2(0x000000D2, 1))
    431         return 1;
    432     if (test__ctzsi2(0x000000D3, 0))
    433         return 1;
    434     if (test__ctzsi2(0x000000D4, 2))
    435         return 1;
    436     if (test__ctzsi2(0x000000D5, 0))
    437         return 1;
    438     if (test__ctzsi2(0x000000D6, 1))
    439         return 1;
    440     if (test__ctzsi2(0x000000D7, 0))
    441         return 1;
    442     if (test__ctzsi2(0x000000D8, 3))
    443         return 1;
    444     if (test__ctzsi2(0x000000D9, 0))
    445         return 1;
    446     if (test__ctzsi2(0x000000DA, 1))
    447         return 1;
    448     if (test__ctzsi2(0x000000DB, 0))
    449         return 1;
    450     if (test__ctzsi2(0x000000DC, 2))
    451         return 1;
    452     if (test__ctzsi2(0x000000DD, 0))
    453         return 1;
    454     if (test__ctzsi2(0x000000DE, 1))
    455         return 1;
    456     if (test__ctzsi2(0x000000DF, 0))
    457         return 1;
    458     if (test__ctzsi2(0x000000E0, 5))
    459         return 1;
    460     if (test__ctzsi2(0x000000E2, 1))
    461         return 1;
    462     if (test__ctzsi2(0x000000E3, 0))
    463         return 1;
    464     if (test__ctzsi2(0x000000E4, 2))
    465         return 1;
    466     if (test__ctzsi2(0x000000E5, 0))
    467         return 1;
    468     if (test__ctzsi2(0x000000E6, 1))
    469         return 1;
    470     if (test__ctzsi2(0x000000E7, 0))
    471         return 1;
    472     if (test__ctzsi2(0x000000E8, 3))
    473         return 1;
    474     if (test__ctzsi2(0x000000E9, 0))
    475         return 1;
    476     if (test__ctzsi2(0x000000EA, 1))
    477         return 1;
    478     if (test__ctzsi2(0x000000EB, 0))
    479         return 1;
    480     if (test__ctzsi2(0x000000EC, 2))
    481         return 1;
    482     if (test__ctzsi2(0x000000ED, 0))
    483         return 1;
    484     if (test__ctzsi2(0x000000EE, 1))
    485         return 1;
    486     if (test__ctzsi2(0x000000EF, 0))
    487         return 1;
    488     if (test__ctzsi2(0x000000F0, 4))
    489         return 1;
    490     if (test__ctzsi2(0x000000F2, 1))
    491         return 1;
    492     if (test__ctzsi2(0x000000F3, 0))
    493         return 1;
    494     if (test__ctzsi2(0x000000F4, 2))
    495         return 1;
    496     if (test__ctzsi2(0x000000F5, 0))
    497         return 1;
    498     if (test__ctzsi2(0x000000F6, 1))
    499         return 1;
    500     if (test__ctzsi2(0x000000F7, 0))
    501         return 1;
    502     if (test__ctzsi2(0x000000F8, 3))
    503         return 1;
    504     if (test__ctzsi2(0x000000F9, 0))
    505         return 1;
    506     if (test__ctzsi2(0x000000FA, 1))
    507         return 1;
    508     if (test__ctzsi2(0x000000FB, 0))
    509         return 1;
    510     if (test__ctzsi2(0x000000FC, 2))
    511         return 1;
    512     if (test__ctzsi2(0x000000FD, 0))
    513         return 1;
    514     if (test__ctzsi2(0x000000FE, 1))
    515         return 1;
    516     if (test__ctzsi2(0x000000FF, 0))
    517         return 1;
    518 
    519     if (test__ctzsi2(0x00000100, 8))
    520         return 1;
    521     if (test__ctzsi2(0x00000200, 9))
    522         return 1;
    523     if (test__ctzsi2(0x00000400, 10))
    524         return 1;
    525     if (test__ctzsi2(0x00000800, 11))
    526         return 1;
    527     if (test__ctzsi2(0x00001000, 12))
    528         return 1;
    529     if (test__ctzsi2(0x00002000, 13))
    530         return 1;
    531     if (test__ctzsi2(0x00004000, 14))
    532         return 1;
    533     if (test__ctzsi2(0x00008000, 15))
    534         return 1;
    535     if (test__ctzsi2(0x00010000, 16))
    536         return 1;
    537     if (test__ctzsi2(0x00020000, 17))
    538         return 1;
    539     if (test__ctzsi2(0x00040000, 18))
    540         return 1;
    541     if (test__ctzsi2(0x00080000, 19))
    542         return 1;
    543     if (test__ctzsi2(0x00100000, 20))
    544         return 1;
    545     if (test__ctzsi2(0x00200000, 21))
    546         return 1;
    547     if (test__ctzsi2(0x00400000, 22))
    548         return 1;
    549     if (test__ctzsi2(0x00800000, 23))
    550         return 1;
    551     if (test__ctzsi2(0x01000000, 24))
    552         return 1;
    553     if (test__ctzsi2(0x02000000, 25))
    554         return 1;
    555     if (test__ctzsi2(0x04000000, 26))
    556         return 1;
    557     if (test__ctzsi2(0x08000000, 27))
    558         return 1;
    559     if (test__ctzsi2(0x10000000, 28))
    560         return 1;
    561     if (test__ctzsi2(0x20000000, 29))
    562         return 1;
    563     if (test__ctzsi2(0x40000000, 30))
    564         return 1;
    565     if (test__ctzsi2(0x80000000, 31))
    566         return 1;
    567 
    568    return 0;
    569 }
    570