1// RUN: %clang_builtins %s %librt -o %t && %run %t 2// REQUIRES: int128 3//===-- umodti3_test.c - Test __umodti3 -----------------------------------===// 4// 5// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 6// See https://llvm.org/LICENSE.txt for license information. 7// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 8// 9//===----------------------------------------------------------------------===// 10// 11// This file tests __umodti3 for the compiler_rt library. 12// 13//===----------------------------------------------------------------------===// 14 15#include "int_lib.h" 16#include <stdio.h> 17 18#ifdef CRT_HAS_128BIT 19 20// Returns: a % b 21 22COMPILER_RT_ABI tu_int __umodti3(tu_int a, tu_int b); 23 24int 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", 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); 41 } 42 return r != expected_r; 43} 44 45#endif 46 47int main() 48{ 49#ifdef CRT_HAS_128BIT 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 62#else 63 printf("skipped\n"); 64#endif 65 return 0; 66} 67