rjmccall created this revision. rjmccall added a reviewer: scanon. Herald added subscribers: cfe-commits, Anastasia. Herald added a project: clang.
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. Repository: rC Clang https://reviews.llvm.org/D62708 Files: clang/lib/Frontend/InitPreprocessor.cpp clang/test/Headers/float16.c clang/test/Preprocessor/init.c Index: clang/test/Preprocessor/init.c =================================================================== --- clang/test/Preprocessor/init.c +++ clang/test/Preprocessor/init.c @@ -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 Index: clang/test/Headers/float16.c =================================================================== --- clang/test/Headers/float16.c +++ clang/test/Headers/float16.c @@ -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 @@ #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 @@ #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 Index: clang/lib/Frontend/InitPreprocessor.cpp =================================================================== --- clang/lib/Frontend/InitPreprocessor.cpp +++ clang/lib/Frontend/InitPreprocessor.cpp @@ -122,10 +122,10 @@ "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",
Index: clang/test/Preprocessor/init.c =================================================================== --- clang/test/Preprocessor/init.c +++ clang/test/Preprocessor/init.c @@ -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 Index: clang/test/Headers/float16.c =================================================================== --- clang/test/Headers/float16.c +++ clang/test/Headers/float16.c @@ -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 @@ #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 @@ #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 Index: clang/lib/Frontend/InitPreprocessor.cpp =================================================================== --- clang/lib/Frontend/InitPreprocessor.cpp +++ clang/lib/Frontend/InitPreprocessor.cpp @@ -122,10 +122,10 @@ "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",
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits