brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · 2ad9ebf Raw
97 lines · c
1// RUN: %clang_builtins %s %librt -o %t && %run %t2// REQUIRES: librt_has_fixunsdfdi3 4#include "int_lib.h"5#include <stdio.h>6 7// Returns: convert a to a unsigned long long, rounding toward zero.8//          Negative values all become zero.9 10// Assumption: double is a IEEE 64 bit floating point type 11//             du_int is a 64 bit integral type12//             value in double is representable in du_int or is negative 13//                 (no range checking performed)14 15// seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm16 17COMPILER_RT_ABI du_int __fixunsdfdi(double a);18 19int test__fixunsdfdi(double a, du_int expected)20{21    du_int x = __fixunsdfdi(a);22    if (x != expected)23        printf("error in __fixunsdfdi(%A) = %llX, expected %llX\n", a, x, expected);24    return x != expected;25}26 27char assumption_1[sizeof(du_int) == 2*sizeof(su_int)] = {0};28char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0};29char assumption_3[sizeof(double)*CHAR_BIT == 64] = {0};30 31int main()32{33    if (test__fixunsdfdi(0.0, 0))34        return 1;35 36    if (test__fixunsdfdi(0.5, 0))37        return 1;38    if (test__fixunsdfdi(0.99, 0))39        return 1;40    if (test__fixunsdfdi(1.0, 1))41        return 1;42    if (test__fixunsdfdi(1.5, 1))43        return 1;44    if (test__fixunsdfdi(1.99, 1))45        return 1;46    if (test__fixunsdfdi(2.0, 2))47        return 1;48    if (test__fixunsdfdi(2.01, 2))49        return 1;50    if (test__fixunsdfdi(-0.5, 0))51        return 1;52    if (test__fixunsdfdi(-0.99, 0))53        return 1;54#if !TARGET_LIBGCC55    if (test__fixunsdfdi(-1.0, 0))  // libgcc ignores "returns 0 for negative input" spec56        return 1;57    if (test__fixunsdfdi(-1.5, 0))58        return 1;59    if (test__fixunsdfdi(-1.99, 0))60        return 1;61    if (test__fixunsdfdi(-2.0, 0))62        return 1;63    if (test__fixunsdfdi(-2.01, 0))64        return 1;65#endif66 67    if (test__fixunsdfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000LL))68        return 1;69    if (test__fixunsdfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000LL))70        return 1;71 72#if !TARGET_LIBGCC73    if (test__fixunsdfdi(-0x1.FFFFFEp+62, 0))74        return 1;75    if (test__fixunsdfdi(-0x1.FFFFFCp+62, 0))76        return 1;77#endif78 79    if (test__fixunsdfdi(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800LL))80        return 1;81    if (test__fixunsdfdi(0x1.0000000000000p+63, 0x8000000000000000LL))82        return 1;83    if (test__fixunsdfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00LL))84        return 1;85    if (test__fixunsdfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800LL))86        return 1;87 88#if !TARGET_LIBGCC89    if (test__fixunsdfdi(-0x1.FFFFFFFFFFFFFp+62, 0))90        return 1;91    if (test__fixunsdfdi(-0x1.FFFFFFFFFFFFEp+62, 0))92        return 1;93#endif94 95   return 0;96}97