diff options
author | John McCall <rjmccall@apple.com> | 2019-05-31 01:21:36 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2019-05-31 01:21:36 +0000 |
commit | 059b823e709a90d3b5d2d24663830e59b3bdded9 (patch) | |
tree | 39392b05b6b230e4acec135a3ed95dbf1e6cb95c | |
parent | b5a45bb77e05647f04bbd9780d70aabe9f251155 (diff) | |
download | bcm5719-llvm-059b823e709a90d3b5d2d24663830e59b3bdded9.tar.gz bcm5719-llvm-059b823e709a90d3b5d2d24663830e59b3bdded9.zip |
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.
llvm-svn: 362183
-rw-r--r-- | clang/lib/Frontend/InitPreprocessor.cpp | 6 | ||||
-rw-r--r-- | clang/test/Headers/float16.c | 6 | ||||
-rw-r--r-- | clang/test/Preprocessor/init.c | 6 |
3 files changed, 9 insertions, 9 deletions
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index cc479dd010f..1741ba5e520 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -122,10 +122,10 @@ static void DefineFloatMacros(MacroBuilder &Builder, StringRef Prefix, "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", diff --git a/clang/test/Headers/float16.c b/clang/test/Headers/float16.c index 90ba053b287..8d39bf957f4 100644 --- a/clang/test/Headers/float16.c +++ b/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 @@ _Static_assert(FLT16_MIN_10_EXP == __FLT16_MIN_10_EXP__, ""); #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 == __FLT16_MAX_10_EXP__, ""); #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 diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 8eb101c6a41..8df3b4bd2cc 100644 --- a/clang/test/Preprocessor/init.c +++ b/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 |