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