70 lines · c
1// RUN: %clang_builtins %s %librt -o %t && %run %t2// REQUIRES: librt_has_divti33// REQUIRES: int1284 5#include "int_lib.h"6#include <stdio.h>7 8#ifdef CRT_HAS_128BIT9 10// Returns: a / b11 12COMPILER_RT_ABI ti_int __divti3(ti_int a, ti_int b);13 14int test__divti3(ti_int a, ti_int b, ti_int expected)15{16 ti_int x = __divti3(a, b);17 if (x != expected)18 {19 twords at;20 at.all = a;21 twords bt;22 bt.all = b;23 twords xt;24 xt.all = x;25 twords expectedt;26 expectedt.all = expected;27 printf("error in __divti3: 0x%llX%.16llX / 0x%llX%.16llX = "28 "0x%llX%.16llX, expected 0x%llX%.16llX\n",29 at.s.high, at.s.low, bt.s.high, bt.s.low, xt.s.high, xt.s.low,30 expectedt.s.high, expectedt.s.low);31 }32 return x != expected;33}34 35char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};36 37#endif38 39int main()40{41#ifdef CRT_HAS_128BIT42 if (test__divti3(0, 1, 0))43 return 1;44 if (test__divti3(0, -1, 0))45 return 1;46 47 if (test__divti3(2, 1, 2))48 return 1;49 if (test__divti3(2, -1, -2))50 return 1;51 if (test__divti3(-2, 1, -2))52 return 1;53 if (test__divti3(-2, -1, 2))54 return 1;55 56 if (test__divti3(make_ti(0x8000000000000000LL, 0), 1, make_ti(0x8000000000000000LL, 0)))57 return 1;58 if (test__divti3(make_ti(0x8000000000000000LL, 0), -1, make_ti(0x8000000000000000LL, 0)))59 return 1;60 if (test__divti3(make_ti(0x8000000000000000LL, 0), -2, make_ti(0x4000000000000000LL, 0)))61 return 1;62 if (test__divti3(make_ti(0x8000000000000000LL, 0), 2, make_ti(0xC000000000000000LL, 0)))63 return 1;64 65#else66 printf("skipped\n");67#endif68 return 0;69}70