| Weiming Zhao | 9b7bbec | 2017-03-21 05:32:51 +0000 | [diff] [blame] | 1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
| Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 2 | //===-- umodti3_test.c - Test __umodti3 -----------------------------------===// |
| 3 | // |
| 4 | // The LLVM Compiler Infrastructure |
| 5 | // |
| Howard Hinnant | 5b791f6 | 2010-11-16 22:13:33 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
| Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | // |
| 11 | // This file tests __umodti3 for the compiler_rt library. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 15 | #include "int_lib.h" |
| 16 | #include <stdio.h> |
| 17 | |
| Joerg Sonnenberger | 1474312 | 2014-03-18 21:35:30 +0000 | [diff] [blame] | 18 | #ifdef CRT_HAS_128BIT |
| 19 | |
| Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 20 | // Returns: a % b |
| 21 | |
| Derek Schuff | eb0ebc3 | 2015-04-24 15:45:57 +0000 | [diff] [blame] | 22 | COMPILER_RT_ABI tu_int __umodti3(tu_int a, tu_int b); |
| Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 23 | |
| 24 | int test__umodti3(tu_int a, tu_int b, tu_int expected_r) |
| 25 | { |
| 26 | tu_int r = __umodti3(a, b); |
| 27 | if (r != expected_r) |
| 28 | { |
| 29 | utwords at; |
| 30 | at.all = a; |
| 31 | utwords bt; |
| 32 | bt.all = b; |
| 33 | utwords rt; |
| 34 | rt.all = r; |
| 35 | utwords expected_rt; |
| 36 | expected_rt.all = expected_r; |
| 37 | printf("error in __umodti3: 0x%llX%.16llX %% 0x%llX%.16llX = " |
| 38 | "0x%llX%.16llX, expected 0x%llX%.16llX\n", |
| Daniel Dunbar | 6485720 | 2009-10-27 17:49:07 +0000 | [diff] [blame] | 39 | at.s.high, at.s.low, bt.s.high, bt.s.low, rt.s.high, rt.s.low, |
| 40 | expected_rt.s.high, expected_rt.s.low); |
| Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 41 | } |
| 42 | return r != expected_r; |
| 43 | } |
| 44 | |
| 45 | #endif |
| 46 | |
| 47 | int main() |
| 48 | { |
| Joerg Sonnenberger | 1474312 | 2014-03-18 21:35:30 +0000 | [diff] [blame] | 49 | #ifdef CRT_HAS_128BIT |
| Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 50 | if (test__umodti3(0, 1, 0)) |
| 51 | return 1; |
| 52 | if (test__umodti3(2, 1, 0)) |
| 53 | return 1; |
| 54 | if (test__umodti3(make_tu(0x8000000000000000uLL, 0), 1, 0x0uLL)) |
| 55 | return 1; |
| 56 | if (test__umodti3(make_tu(0x8000000000000000uLL, 0), 2, 0x0uLL)) |
| 57 | return 1; |
| 58 | if (test__umodti3(make_tu(0xFFFFFFFFFFFFFFFFuLL, 0xFFFFFFFFFFFFFFFFuLL), |
| 59 | 2, 0x1uLL)) |
| 60 | return 1; |
| 61 | |
| Joerg Sonnenberger | d9bcddd | 2011-05-29 21:43:29 +0000 | [diff] [blame] | 62 | #else |
| 63 | printf("skipped\n"); |
| Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 64 | #endif |
| 65 | return 0; |
| 66 | } |