blob: 8233c18ff09adf7ca6db055172f8dcd34a843fcc [file] [log] [blame]
Daniel Dunbarb3a69012009-06-26 16:47:03 +00001//===-- absvti2_test.c - Test __absvti2 -----------------------------------===//
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 __absvti2 for the compiler_rt library.
11//
12//===----------------------------------------------------------------------===//
13
14#if __x86_64
15
16#include "int_lib.h"
17#include <stdio.h>
Shantonu Sen8973a272009-10-28 15:46:10 +000018#include <stdlib.h>
Daniel Dunbarb3a69012009-06-26 16:47:03 +000019
20// Returns: absolute value
21
22// Effects: aborts if abs(x) < 0
23
24ti_int __absvti2(ti_int a);
25
26int test__absvti2(ti_int a)
27{
28 ti_int x = __absvti2(a);
29 ti_int expected = a;
30 if (expected < 0)
31 expected = -expected;
32 if (x != expected || expected < 0)
33 {
34 twords at;
35 at.all = a;
36 twords xt;
37 xt.all = x;
38 twords expectedt;
39 expectedt.all = expected;
40 printf("error in __absvti2(0x%llX%.16llX) = "
41 "0x%llX%.16llX, expected positive 0x%llX%.16llX\n",
Daniel Dunbarcff52482009-10-27 17:49:07 +000042 at.s.high, at.s.low, xt.s.high, xt.s.low,
43 expectedt.s.high, expectedt.s.low);
Daniel Dunbarb3a69012009-06-26 16:47:03 +000044 }
45 return x != expected;
46}
47
48#endif
49
50int main()
51{
52#if __x86_64
53
54// if (test__absvti2(make_ti(0x8000000000000000LL, 0))) // should abort
55// return 1;
56 if (test__absvti2(0x0000000000000000LL))
57 return 1;
58 if (test__absvti2(0x0000000000000001LL))
59 return 1;
60 if (test__absvti2(0x0000000000000002LL))
61 return 1;
62 if (test__absvti2(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFELL)))
63 return 1;
64 if (test__absvti2(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
65 return 1;
66 if (test__absvti2(make_ti(0x8000000000000000LL, 0x0000000000000001LL)))
67 return 1;
68 if (test__absvti2(make_ti(0x8000000000000000LL, 0x0000000000000002LL)))
69 return 1;
70 if (test__absvti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFELL)))
71 return 1;
72 if (test__absvti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
73 return 1;
74
75 int i;
76 for (i = 0; i < 10000; ++i)
77 if (test__absvti2(make_ti(((ti_int)rand() << 32) | rand(),
78 ((ti_int)rand() << 32) | rand())))
79 return 1;
Joerg Sonnenberger74828152011-05-29 21:43:29 +000080#else
81 printf("skipped\n");
Daniel Dunbarb3a69012009-06-26 16:47:03 +000082#endif
83 return 0;
84}