117 lines · c
1// RUN: %clang_builtins %s %librt -o %t && %run %t2// REQUIRES: librt_has_fixunstfdi3 4#include <stdio.h>5#include "int_lib.h"6 7#if defined(CRT_HAS_TF_MODE)8 9#define QUAD_PRECISION10#include "fp_lib.h"11 12// Returns: convert a to a unsigned long long, rounding toward zero.13// Negative values all become zero.14 15// Assumption: fp_t is a 128 bit floating point type16// du_int is a 64 bit integral type17// value in fp_t is representable in du_int or is negative 18// (no range checking performed)19 20COMPILER_RT_ABI du_int __fixunstfdi(fp_t a);21 22int test__fixunstfdi(fp_t a, du_int expected)23{24 du_int x = __fixunstfdi(a);25 if (x != expected)26 printf("error in __fixunstfdi(%LA) = %llX, expected %llX\n",27 a, x, expected);28 return x != expected;29}30 31char assumption_1[sizeof(du_int) == 2*sizeof(su_int)] = {0};32char assumption_2[sizeof(du_int)*CHAR_BIT == 64] = {0};33char assumption_3[sizeof(fp_t)*CHAR_BIT == 128] = {0};34 35#endif36 37int main()38{39#if defined(CRT_HAS_TF_MODE)40 if (test__fixunstfdi(0.0, 0))41 return 1;42 43 if (test__fixunstfdi(0.5, 0))44 return 1;45 if (test__fixunstfdi(0.99, 0))46 return 1;47 if (test__fixunstfdi(1.0, 1))48 return 1;49 if (test__fixunstfdi(1.5, 1))50 return 1;51 if (test__fixunstfdi(1.99, 1))52 return 1;53 if (test__fixunstfdi(2.0, 2))54 return 1;55 if (test__fixunstfdi(2.01, 2))56 return 1;57 if (test__fixunstfdi(-0.5, 0))58 return 1;59 if (test__fixunstfdi(-0.99, 0))60 return 1;61 if (test__fixunstfdi(-1.0, 0))62 return 1;63 if (test__fixunstfdi(-1.5, 0))64 return 1;65 if (test__fixunstfdi(-1.99, 0))66 return 1;67 if (test__fixunstfdi(-2.0, 0))68 return 1;69 if (test__fixunstfdi(-2.01, 0))70 return 1;71 72 if (test__fixunstfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000LL))73 return 1;74 if (test__fixunstfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000LL))75 return 1;76 77 if (test__fixunstfdi(-0x1.FFFFFEp+62, 0))78 return 1;79 if (test__fixunstfdi(-0x1.FFFFFCp+62, 0))80 return 1;81 82 if (test__fixunstfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00LL))83 return 1;84 if (test__fixunstfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800LL))85 return 1;86 87 if (test__fixunstfdi(-0x1.FFFFFFFFFFFFFp+62, 0))88 return 1;89 if (test__fixunstfdi(-0x1.FFFFFFFFFFFFEp+62, 0))90 return 1;91 92 if (test__fixunstfdi(0x1.FFFFFFFFFFFFFFFEp+63L, 0xFFFFFFFFFFFFFFFFLL))93 return 1;94 if (test__fixunstfdi(0x1.0000000000000002p+63L, 0x8000000000000001LL))95 return 1;96 if (test__fixunstfdi(0x1.0000000000000000p+63L, 0x8000000000000000LL))97 return 1;98 if (test__fixunstfdi(0x1.FFFFFFFFFFFFFFFCp+62L, 0x7FFFFFFFFFFFFFFFLL))99 return 1;100 if (test__fixunstfdi(0x1.FFFFFFFFFFFFFFF8p+62L, 0x7FFFFFFFFFFFFFFELL))101 return 1;102 if (test__fixunstfdi(0x1.p+64L, 0xFFFFFFFFFFFFFFFFLL))103 return 1;104 105 if (test__fixunstfdi(-0x1.0000000000000000p+63L, 0))106 return 1;107 if (test__fixunstfdi(-0x1.FFFFFFFFFFFFFFFCp+62L, 0))108 return 1;109 if (test__fixunstfdi(-0x1.FFFFFFFFFFFFFFF8p+62L, 0))110 return 1;111 112#else113 printf("skipped\n");114#endif115 return 0;116}117