Author: rjmccall Date: Thu May 30 18:21:36 2019 New Revision: 362183 URL: http://llvm.org/viewvc/llvm-project?rev=362183&view=rev Log: Fix the predefined exponent limit macros for the 16-bit IEEE format.
The magnitude range of normalized _Float16 is 2^-14 (~6e-5) to (2-2^-10)*2^15 (65504). You might think, then, that the code is correct to defne FLT16_MIN_EXP and FLT16_MAX_EXP to be -14 and 15 respectively. However, for some reason the C specification actually specifies a bias for these macros: C11 5.2.4.2.2: - minimum negative integer such that FLT_RADIX raised to one less than that power is a normalized floating-point number, e_min: FLT_MIN_EXP DBL_MIN_EXP LDBL_MIN_EXP - maximum integer such that FLT_RADIX raised to one less than that power is a representable finite floating-point number, e_max: FLT_MAX_EXP DBL_MAX_EXP LDBL_MAX_EXP FLT16_MIN_EXP and FLT16_MAX_EXP should clearly be biased the same way, and other compilers do in fact do so, as do our OpenCL headers for `half`. Additionally, FLT16_MIN_10_EXP is just wrong. Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp cfe/trunk/test/Headers/float16.c cfe/trunk/test/Preprocessor/init.c Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=362183&r1=362182&r2=362183&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original) +++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Thu May 30 18:21:36 2019 @@ -122,10 +122,10 @@ static void DefineFloatMacros(MacroBuild "4.94065645841246544176568792868221e-324", "1.92592994438723585305597794258492732e-34"); int MantissaDigits = PickFP(Sem, 11, 24, 53, 64, 106, 113); - int Min10Exp = PickFP(Sem, -13, -37, -307, -4931, -291, -4931); + int Min10Exp = PickFP(Sem, -4, -37, -307, -4931, -291, -4931); int Max10Exp = PickFP(Sem, 4, 38, 308, 4932, 308, 4932); - int MinExp = PickFP(Sem, -14, -125, -1021, -16381, -968, -16381); - int MaxExp = PickFP(Sem, 15, 128, 1024, 16384, 1024, 16384); + int MinExp = PickFP(Sem, -13, -125, -1021, -16381, -968, -16381); + int MaxExp = PickFP(Sem, 16, 128, 1024, 16384, 1024, 16384); Min = PickFP(Sem, "6.103515625e-5", "1.17549435e-38", "2.2250738585072014e-308", "3.36210314311209350626e-4932", "2.00416836000897277799610805135016e-292", Modified: cfe/trunk/test/Headers/float16.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/float16.c?rev=362183&r1=362182&r2=362183&view=diff ============================================================================== --- cfe/trunk/test/Headers/float16.c (original) +++ cfe/trunk/test/Headers/float16.c Thu May 30 18:21:36 2019 @@ -13,7 +13,7 @@ #ifndef FLT16_MIN_10_EXP #error "Macro FLT16_MIN_10_EXP is missing." -#elif FLT16_MIN_10_EXP > -13 +#elif FLT16_MIN_10_EXP > -4 #error "Macro FLT16_MIN_10_EXP is invalid." #endif @@ -21,7 +21,7 @@ _Static_assert(FLT16_MIN_10_EXP == __FLT #ifndef FLT16_MIN_EXP #error "Macro FLT16_MIN_EXP is missing." -#elif FLT16_MIN_EXP > -14 +#elif FLT16_MIN_EXP > -13 #error "Macro FLT16_MIN_EXP is invalid." #endif @@ -37,7 +37,7 @@ _Static_assert(FLT16_MAX_10_EXP == __FLT #ifndef FLT16_MAX_EXP #error "Macro FLT16_MAX_EXP is missing." -#elif FLT16_MAX_EXP < 15 +#elif FLT16_MAX_EXP < 16 #error "Macro FLT16_MAX_EXP is invalid." #endif Modified: cfe/trunk/test/Preprocessor/init.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/init.c?rev=362183&r1=362182&r2=362183&view=diff ============================================================================== --- cfe/trunk/test/Preprocessor/init.c (original) +++ cfe/trunk/test/Preprocessor/init.c Thu May 30 18:21:36 2019 @@ -310,10 +310,10 @@ // AARCH64:#define __FLT16_HAS_QUIET_NAN__ 1 // AARCH64:#define __FLT16_MANT_DIG__ 11 // AARCH64:#define __FLT16_MAX_10_EXP__ 4 -// AARCH64:#define __FLT16_MAX_EXP__ 15 +// AARCH64:#define __FLT16_MAX_EXP__ 16 // AARCH64:#define __FLT16_MAX__ 6.5504e+4F16 -// AARCH64:#define __FLT16_MIN_10_EXP__ (-13) -// AARCH64:#define __FLT16_MIN_EXP__ (-14) +// AARCH64:#define __FLT16_MIN_10_EXP__ (-4) +// AARCH64:#define __FLT16_MIN_EXP__ (-13) // AARCH64:#define __FLT16_MIN__ 6.103515625e-5F16 // AARCH64:#define __FLT_DENORM_MIN__ 1.40129846e-45F // AARCH64:#define __FLT_DIG__ 6 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits