Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 1 | //===-- fixsfdi_test.c - Test __fixsfdi -----------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file tests __fixsfdi for the compiler_rt library. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "int_lib.h" |
| 15 | #include <stdio.h> |
| 16 | |
| 17 | // Returns: convert a to a signed long long, rounding toward zero. |
| 18 | |
| 19 | // Assumption: float is a IEEE 32 bit floating point type |
| 20 | // su_int is a 32 bit integral type |
| 21 | // value in float is representable in di_int (no range checking performed) |
| 22 | |
| 23 | // seee eeee emmm mmmm mmmm mmmm mmmm mmmm |
| 24 | |
| 25 | di_int __fixsfdi(float a); |
| 26 | |
| 27 | int test__fixsfdi(float a, di_int expected) |
| 28 | { |
| 29 | di_int x = __fixsfdi(a); |
| 30 | if (x != expected) |
| 31 | printf("error in __fixsfdi(%A) = %llX, expected %llX\n", a, x, expected); |
| 32 | return x != expected; |
| 33 | } |
| 34 | |
| 35 | char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0}; |
| 36 | char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0}; |
| 37 | char assumption_3[sizeof(float)*CHAR_BIT == 32] = {0}; |
| 38 | |
| 39 | int main() |
| 40 | { |
| 41 | if (test__fixsfdi(0.0F, 0)) |
| 42 | return 1; |
| 43 | |
| 44 | if (test__fixsfdi(0.5F, 0)) |
| 45 | return 1; |
| 46 | if (test__fixsfdi(0.99F, 0)) |
| 47 | return 1; |
| 48 | if (test__fixsfdi(1.0F, 1)) |
| 49 | return 1; |
| 50 | if (test__fixsfdi(1.5F, 1)) |
| 51 | return 1; |
| 52 | if (test__fixsfdi(1.99F, 1)) |
| 53 | return 1; |
| 54 | if (test__fixsfdi(2.0F, 2)) |
| 55 | return 1; |
| 56 | if (test__fixsfdi(2.01F, 2)) |
| 57 | return 1; |
| 58 | if (test__fixsfdi(-0.5F, 0)) |
| 59 | return 1; |
| 60 | if (test__fixsfdi(-0.99F, 0)) |
| 61 | return 1; |
| 62 | if (test__fixsfdi(-1.0F, -1)) |
| 63 | return 1; |
| 64 | if (test__fixsfdi(-1.5F, -1)) |
| 65 | return 1; |
| 66 | if (test__fixsfdi(-1.99F, -1)) |
| 67 | return 1; |
| 68 | if (test__fixsfdi(-2.0F, -2)) |
| 69 | return 1; |
| 70 | if (test__fixsfdi(-2.01F, -2)) |
| 71 | return 1; |
| 72 | |
| 73 | if (test__fixsfdi(0x1.FFFFFEp+62F, 0x7FFFFF8000000000LL)) |
| 74 | return 1; |
| 75 | if (test__fixsfdi(0x1.FFFFFCp+62F, 0x7FFFFF0000000000LL)) |
| 76 | return 1; |
| 77 | |
| 78 | if (test__fixsfdi(-0x1.FFFFFEp+62F, 0x8000008000000000LL)) |
| 79 | return 1; |
| 80 | if (test__fixsfdi(-0x1.FFFFFCp+62F, 0x8000010000000000LL)) |
| 81 | return 1; |
| 82 | |
| 83 | return 0; |
| 84 | } |