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