88 lines · c
1// RUN: %clang_builtins %s %librt -o %t && %run %t2// REQUIRES: librt_has_extendhfsf23 4#include <stdio.h>5 6#include "fp_test.h"7 8float __extendhfsf2(TYPE_FP16 a);9 10int test__extendhfsf2(TYPE_FP16 a, uint32_t expected)11{12 float x = __extendhfsf2(a);13 int ret = compareResultF(x, expected);14 15 if (ret){16 printf("error in test__extendhfsf2(%#.4x) = %f, "17 "expected %f\n", toRep16(a), x, fromRep32(expected));18 }19 return ret;20}21 22char assumption_1[sizeof(TYPE_FP16) * CHAR_BIT == 16] = {0};23 24int main()25{26 // qNaN27 if (test__extendhfsf2(fromRep16(0x7e00),28 UINT32_C(0x7fc00000)))29 return 1;30 // NaN31 if (test__extendhfsf2(fromRep16(0x7f80),32 UINT32_C(0x7ff00000)))33 return 1;34 // inf35 if (test__extendhfsf2(fromRep16(0x7c00),36 UINT32_C(0x7f800000)))37 return 1;38 // -inf39 if (test__extendhfsf2(fromRep16(0xfc00),40 UINT32_C(0xff800000)))41 return 1;42 // zero43 if (test__extendhfsf2(fromRep16(0x0),44 UINT32_C(0x00000000)))45 return 1;46 // -zero47 if (test__extendhfsf2(fromRep16(0x8000),48 UINT32_C(0x80000000)))49 return 1;50 if (test__extendhfsf2(fromRep16(0x4248),51 UINT32_C(0x40490000)))52 return 1;53 if (test__extendhfsf2(fromRep16(0xc248),54 UINT32_C(0xc0490000)))55 return 1;56 if (test__extendhfsf2(fromRep16(0x6e62),57 UINT32_C(0x45cc4000)))58 return 1;59 if (test__extendhfsf2(fromRep16(0x3c00),60 UINT32_C(0x3f800000)))61 return 1;62 if (test__extendhfsf2(fromRep16(0x0400),63 UINT32_C(0x38800000)))64 return 1;65 // denormal66 if (test__extendhfsf2(fromRep16(0x0010),67 UINT32_C(0x35800000)))68 return 1;69 if (test__extendhfsf2(fromRep16(0x0001),70 UINT32_C(0x33800000)))71 return 1;72 if (test__extendhfsf2(fromRep16(0x8001),73 UINT32_C(0xb3800000)))74 return 1;75 if (test__extendhfsf2(fromRep16(0x0001),76 UINT32_C(0x33800000)))77 return 1;78 // max (precise)79 if (test__extendhfsf2(fromRep16(0x7bff),80 UINT32_C(0x477fe000)))81 return 1;82 // max (rounded)83 if (test__extendhfsf2(fromRep16(0x7bff),84 UINT32_C(0x477fe000)))85 return 1;86 return 0;87}88