Home | History | Annotate | Download | only in Unit
      1 //===-- ucmpti2_test.c - Test __ucmpti2 -----------------------------------===//
      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 __ucmpti2 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:  if (a <  b) returns 0
     20 //           if (a == b) returns 1
     21 //           if (a >  b) returns 2
     22 
     23 si_int __ucmpti2(tu_int a, tu_int b);
     24 
     25 int test__ucmpti2(tu_int a, tu_int b, si_int expected)
     26 {
     27     si_int x = __ucmpti2(a, b);
     28     if (x != expected)
     29     {
     30         utwords at;
     31         at.all = a;
     32         utwords bt;
     33         bt.all = b;
     34         printf("error in __ucmpti2(0x%.16llX%.16llX, 0x%.16llX%.16llX) = %d, "
     35                "expected %d\n",
     36                at.s.high, at.s.low, bt.s.high, bt.s.low, x, expected);
     37     }
     38     return x != expected;
     39 }
     40 
     41 #endif
     42 
     43 int main()
     44 {
     45 #if __x86_64
     46     if (test__ucmpti2(0, 0, 1))
     47         return 1;
     48     if (test__ucmpti2(1, 1, 1))
     49         return 1;
     50     if (test__ucmpti2(2, 2, 1))
     51         return 1;
     52     if (test__ucmpti2(0x7FFFFFFF, 0x7FFFFFFF, 1))
     53         return 1;
     54     if (test__ucmpti2(0x80000000, 0x80000000, 1))
     55         return 1;
     56     if (test__ucmpti2(0x80000001, 0x80000001, 1))
     57         return 1;
     58     if (test__ucmpti2(0xFFFFFFFF, 0xFFFFFFFF, 1))
     59         return 1;
     60     if (test__ucmpti2(0x000000010000000LL, 0x000000010000000LL, 1))
     61         return 1;
     62     if (test__ucmpti2(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL, 1))
     63         return 1;
     64 
     65     if (test__ucmpti2(0x0000000200000002LL, 0x0000000300000001LL, 0))
     66         return 1;
     67     if (test__ucmpti2(0x0000000200000002LL, 0x0000000300000002LL, 0))
     68         return 1;
     69     if (test__ucmpti2(0x0000000200000002LL, 0x0000000300000003LL, 0))
     70         return 1;
     71 
     72     if (test__ucmpti2(0x0000000200000002LL, 0x0000000100000001LL, 2))
     73         return 1;
     74     if (test__ucmpti2(0x0000000200000002LL, 0x0000000100000002LL, 2))
     75         return 1;
     76     if (test__ucmpti2(0x0000000200000002LL, 0x0000000100000003LL, 2))
     77         return 1;
     78 
     79     if (test__ucmpti2(0x0000000200000002LL, 0x0000000200000001LL, 2))
     80         return 1;
     81     if (test__ucmpti2(0x0000000200000002LL, 0x0000000200000002LL, 1))
     82         return 1;
     83     if (test__ucmpti2(0x0000000200000002LL, 0x0000000200000003LL, 0))
     84         return 1;
     85 
     86     if (test__ucmpti2(make_tu(0x0000000000000001uLL, 0x0000000000000000uLL),
     87                       make_tu(0x0000000000000000uLL, 0xFFFFFFFFFFFFFFFFuLL), 2))
     88         return 1;
     89     if (test__ucmpti2(make_tu(0x0000000000000001uLL, 0x0000000000000000uLL),
     90                       make_tu(0x0000000000000001uLL, 0x0000000000000000uLL), 1))
     91         return 1;
     92     if (test__ucmpti2(make_tu(0x0000000000000001uLL, 0x0000000000000000uLL),
     93                       make_tu(0x0000000000000001uLL, 0x0000000000000001uLL), 0))
     94         return 1;
     95 
     96     if (test__ucmpti2(make_tu(0x8000000000000000uLL, 0x0000000000000000uLL),
     97                       make_tu(0x7FFFFFFFFFFFFFFFuLL, 0xFFFFFFFFFFFFFFFFuLL), 2))
     98         return 1;
     99     if (test__ucmpti2(make_tu(0x8000000000000000uLL, 0x0000000000000000uLL),
    100                       make_tu(0x8000000000000000uLL, 0x0000000000000000uLL), 1))
    101         return 1;
    102     if (test__ucmpti2(make_tu(0x8000000000000000uLL, 0x0000000000000000uLL),
    103                       make_tu(0x8000000000000000uLL, 0x0000000000000001uLL), 0))
    104         return 1;
    105 
    106     if (test__ucmpti2(make_tu(0xFFFFFFFFFFFFFFFFuLL, 0xFFFFFFFFFFFFFFFFuLL),
    107                       make_tu(0xFFFFFFFFFFFFFFFFuLL, 0xFFFFFFFFFFFFFFFEuLL), 2))
    108         return 1;
    109     if (test__ucmpti2(make_tu(0xFFFFFFFFFFFFFFFFuLL, 0xFFFFFFFFFFFFFFFFuLL),
    110                       make_tu(0xFFFFFFFFFFFFFFFFuLL, 0xFFFFFFFFFFFFFFFFuLL), 1))
    111         return 1;
    112 #else
    113     printf("skipped\n");
    114 #endif
    115    return 0;
    116 }
    117