1// RUN: %clang_builtins %s %librt -o %t && %run %t 2// REQUIRES: int128 3//===-- divti3_test.c - Test __divti3 -------------------------------------===// 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 __divti3 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 ti_int __divti3(ti_int a, ti_int b); 23 24int test__divti3(ti_int a, ti_int b, ti_int expected) 25{ 26 ti_int x = __divti3(a, b); 27 if (x != expected) 28 { 29 twords at; 30 at.all = a; 31 twords bt; 32 bt.all = b; 33 twords xt; 34 xt.all = x; 35 twords expectedt; 36 expectedt.all = expected; 37 printf("error in __divti3: 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, xt.s.high, xt.s.low, 40 expectedt.s.high, expectedt.s.low); 41 } 42 return x != expected; 43} 44 45char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0}; 46 47#endif 48 49int main() 50{ 51#ifdef CRT_HAS_128BIT 52 if (test__divti3(0, 1, 0)) 53 return 1; 54 if (test__divti3(0, -1, 0)) 55 return 1; 56 57 if (test__divti3(2, 1, 2)) 58 return 1; 59 if (test__divti3(2, -1, -2)) 60 return 1; 61 if (test__divti3(-2, 1, -2)) 62 return 1; 63 if (test__divti3(-2, -1, 2)) 64 return 1; 65 66 if (test__divti3(make_ti(0x8000000000000000LL, 0), 1, make_ti(0x8000000000000000LL, 0))) 67 return 1; 68 if (test__divti3(make_ti(0x8000000000000000LL, 0), -1, make_ti(0x8000000000000000LL, 0))) 69 return 1; 70 if (test__divti3(make_ti(0x8000000000000000LL, 0), -2, make_ti(0x4000000000000000LL, 0))) 71 return 1; 72 if (test__divti3(make_ti(0x8000000000000000LL, 0), 2, make_ti(0xC000000000000000LL, 0))) 73 return 1; 74 75#else 76 printf("skipped\n"); 77#endif 78 return 0; 79} 80