1 // RUN: %clang_builtins %s %librt -o %t && %run %t 2 // REQUIRES: librt_has_multf3 3 //===--------------- multf3_test.c - Test __multf3 ------------------------===// 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 __multf3 for the compiler_rt library. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #include <stdio.h> 16 17 #if __LDBL_MANT_DIG__ == 113 18 19 #include "int_lib.h" 20 #include "fp_test.h" 21 22 // Returns: a * b 23 COMPILER_RT_ABI long double __multf3(long double a, long double b); 24 25 int test__multf3(long double a, long double b, 26 uint64_t expectedHi, uint64_t expectedLo) 27 { 28 long double x = __multf3(a, b); 29 int ret = compareResultLD(x, expectedHi, expectedLo); 30 31 if (ret){ 32 printf("error in test__multf3(%.20Lf, %.20Lf) = %.20Lf, " 33 "expected %.20Lf\n", a, b, x, 34 fromRep128(expectedHi, expectedLo)); 35 } 36 return ret; 37 } 38 39 char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; 40 41 #endif 42 43 int main() 44 { 45 #if __LDBL_MANT_DIG__ == 113 46 // qNaN * any = qNaN 47 if (test__multf3(makeQNaN128(), 48 0x1.23456789abcdefp+5L, 49 UINT64_C(0x7fff800000000000), 50 UINT64_C(0x0))) 51 return 1; 52 // NaN * any = NaN 53 if (test__multf3(makeNaN128(UINT64_C(0x800030000000)), 54 0x1.23456789abcdefp+5L, 55 UINT64_C(0x7fff800000000000), 56 UINT64_C(0x0))) 57 return 1; 58 // inf * any = inf 59 if (test__multf3(makeInf128(), 60 0x1.23456789abcdefp+5L, 61 UINT64_C(0x7fff000000000000), 62 UINT64_C(0x0))) 63 return 1; 64 // any * any 65 if (test__multf3(0x1.2eab345678439abcdefea56782346p+5L, 66 0x1.edcb34a235253948765432134674fp-1L, 67 UINT64_C(0x400423e7f9e3c9fc), 68 UINT64_C(0xd906c2c2a85777c4))) 69 return 1; 70 if (test__multf3(0x1.353e45674d89abacc3a2ebf3ff4ffp-50L, 71 0x1.ed8764648369535adf4be3214567fp-9L, 72 UINT64_C(0x3fc52a163c6223fc), 73 UINT64_C(0xc94c4bf0430768b4))) 74 return 1; 75 if (test__multf3(0x1.234425696abcad34a35eeffefdcbap+456L, 76 0x451.ed98d76e5d46e5f24323dff21ffp+600L, 77 UINT64_C(0x44293a91de5e0e94), 78 UINT64_C(0xe8ed17cc2cdf64ac))) 79 return 1; 80 if (test__multf3(0x1.4356473c82a9fabf2d22ace345defp-234L, 81 0x1.eda98765476743ab21da23d45678fp-455L, 82 UINT64_C(0x3d4f37c1a3137cae), 83 UINT64_C(0xfc6807048bc2836a))) 84 return 1; 85 // underflow 86 if (test__multf3(0x1.23456734245345p-10000L, 87 0x1.edcba524498724p-6497L, 88 UINT64_C(0x0), 89 UINT64_C(0x0))) 90 return 1; 91 92 #else 93 printf("skipped\n"); 94 95 #endif 96 return 0; 97 } 98