Home | History | Annotate | Line # | Download | only in Unit
      1  1.1  joerg //===-- modti3_test.c - Test __modti3 -------------------------------------===//
      2  1.1  joerg //
      3  1.1  joerg //                     The LLVM Compiler Infrastructure
      4  1.1  joerg //
      5  1.1  joerg // This file is dual licensed under the MIT and the University of Illinois Open
      6  1.1  joerg // Source Licenses. See LICENSE.TXT for details.
      7  1.1  joerg //
      8  1.1  joerg //===----------------------------------------------------------------------===//
      9  1.1  joerg //
     10  1.1  joerg // This file tests __modti3 for the compiler_rt library.
     11  1.1  joerg //
     12  1.1  joerg //===----------------------------------------------------------------------===//
     13  1.1  joerg 
     14  1.1  joerg #if __x86_64
     15  1.1  joerg 
     16  1.1  joerg #include "int_lib.h"
     17  1.1  joerg #include <stdio.h>
     18  1.1  joerg 
     19  1.1  joerg // Returns: a % b
     20  1.1  joerg 
     21  1.1  joerg ti_int __modti3(ti_int a, ti_int b);
     22  1.1  joerg 
     23  1.1  joerg int test__modti3(ti_int a, ti_int b, ti_int expected)
     24  1.1  joerg {
     25  1.1  joerg     ti_int x = __modti3(a, b);
     26  1.1  joerg     if (x != expected)
     27  1.1  joerg     {
     28  1.1  joerg         twords at;
     29  1.1  joerg         at.all = a;
     30  1.1  joerg         twords bt;
     31  1.1  joerg         bt.all = b;
     32  1.1  joerg         twords xt;
     33  1.1  joerg         xt.all = x;
     34  1.1  joerg         twords expectedt;
     35  1.1  joerg         expectedt.all = expected;
     36  1.1  joerg         printf("error in __modti3: 0x%.16llX%.16llX %% 0x%.16llX%.16llX = "
     37  1.1  joerg                "0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
     38  1.1  joerg                at.s.high, at.s.low, bt.s.high, bt.s.low, xt.s.high, xt.s.low,
     39  1.1  joerg                expectedt.s.high, expectedt.s.low);
     40  1.1  joerg     }
     41  1.1  joerg     return x != expected;
     42  1.1  joerg }
     43  1.1  joerg 
     44  1.1  joerg char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
     45  1.1  joerg 
     46  1.1  joerg #endif
     47  1.1  joerg 
     48  1.1  joerg int main()
     49  1.1  joerg {
     50  1.1  joerg #if __x86_64
     51  1.1  joerg     if (test__modti3(0, 1, 0))
     52  1.1  joerg         return 1;
     53  1.1  joerg     if (test__modti3(0, -1, 0))
     54  1.1  joerg         return 1;
     55  1.1  joerg 
     56  1.1  joerg     if (test__modti3(5, 3, 2))
     57  1.1  joerg         return 1;
     58  1.1  joerg     if (test__modti3(5, -3, 2))
     59  1.1  joerg         return 1;
     60  1.1  joerg     if (test__modti3(-5, 3, -2))
     61  1.1  joerg         return 1;
     62  1.1  joerg     if (test__modti3(-5, -3, -2))
     63  1.1  joerg         return 1;
     64  1.1  joerg 
     65  1.1  joerg     if (test__modti3(0x8000000000000000LL, 1, 0x0LL))
     66  1.1  joerg         return 1;
     67  1.1  joerg     if (test__modti3(0x8000000000000000LL, -1, 0x0LL))
     68  1.1  joerg         return 1;
     69  1.1  joerg     if (test__modti3(0x8000000000000000LL, 2, 0x0LL))
     70  1.1  joerg         return 1;
     71  1.1  joerg     if (test__modti3(0x8000000000000000LL, -2, 0x0LL))
     72  1.1  joerg         return 1;
     73  1.1  joerg     if (test__modti3(0x8000000000000000LL, 3, 2))
     74  1.1  joerg         return 1;
     75  1.1  joerg     if (test__modti3(0x8000000000000000LL, -3, 2))
     76  1.1  joerg         return 1;
     77  1.1  joerg 
     78  1.1  joerg     if (test__modti3(make_ti(0x8000000000000000LL, 0), 1, 0x0LL))
     79  1.1  joerg         return 1;
     80  1.1  joerg     if (test__modti3(make_ti(0x8000000000000000LL, 0), -1, 0x0LL))
     81  1.1  joerg         return 1;
     82  1.1  joerg     if (test__modti3(make_ti(0x8000000000000000LL, 0), 2, 0x0LL))
     83  1.1  joerg         return 1;
     84  1.1  joerg     if (test__modti3(make_ti(0x8000000000000000LL, 0), -2, 0x0LL))
     85  1.1  joerg         return 1;
     86  1.1  joerg     if (test__modti3(make_ti(0x8000000000000000LL, 0), 3, -2))
     87  1.1  joerg         return 1;
     88  1.1  joerg     if (test__modti3(make_ti(0x8000000000000000LL, 0), -3, -2))
     89  1.1  joerg         return 1;
     90  1.1  joerg 
     91  1.1  joerg #else
     92  1.1  joerg     printf("skipped\n");
     93  1.1  joerg #endif
     94  1.1  joerg     return 0;
     95  1.1  joerg }
     96