[PATCH] D34695: _Float16 preprocessor macro definitions
This revision was automatically updated to reflect the committed changes. Closed by commit rL313152: This adds the _Float16 preprocessor macro definitions. (authored by SjoerdMeijer). Changed prior to commit: https://reviews.llvm.org/D34695?vs=114998&id=115050#toc Repository: rL LLVM https://reviews.llvm.org/D34695 Files: cfe/trunk/lib/Frontend/InitPreprocessor.cpp cfe/trunk/lib/Headers/float.h cfe/trunk/test/Headers/float16.c cfe/trunk/test/Preprocessor/init.c Index: cfe/trunk/lib/Headers/float.h === --- cfe/trunk/lib/Headers/float.h +++ cfe/trunk/lib/Headers/float.h @@ -143,4 +143,18 @@ # define LDBL_DECIMAL_DIG __LDBL_DECIMAL_DIG__ #endif +#ifdef __STDC_WANT_IEC_60559_TYPES_EXT__ +# define FLT16_MANT_DIG__FLT16_MANT_DIG__ +# define FLT16_DECIMAL_DIG __FLT16_DECIMAL_DIG__ +# define FLT16_DIG __FLT16_DIG__ +# define FLT16_MIN_EXP __FLT16_MIN_EXP__ +# define FLT16_MIN_10_EXP __FLT16_MIN_10_EXP__ +# define FLT16_MAX_EXP __FLT16_MAX_EXP__ +# define FLT16_MAX_10_EXP __FLT16_MAX_10_EXP__ +# define FLT16_MAX __FLT16_MAX__ +# define FLT16_EPSILON __FLT16_EPSILON__ +# define FLT16_MIN __FLT16_MIN__ +# define FLT16_TRUE_MIN__FLT16_TRUE_MIN__ +#endif /* __STDC_WANT_IEC_60559_TYPES_EXT__ */ + #endif /* __FLOAT_H */ Index: cfe/trunk/lib/Frontend/InitPreprocessor.cpp === --- cfe/trunk/lib/Frontend/InitPreprocessor.cpp +++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp @@ -110,9 +110,11 @@ /// PickFP - This is used to pick a value based on the FP semantics of the /// specified FP model. template -static T PickFP(const llvm::fltSemantics *Sem, T IEEESingleVal, +static T PickFP(const llvm::fltSemantics *Sem, T IEEEHalfVal, T IEEESingleVal, T IEEEDoubleVal, T X87DoubleExtendedVal, T PPCDoubleDoubleVal, T IEEEQuadVal) { + if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEhalf()) +return IEEEHalfVal; if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEsingle()) return IEEESingleVal; if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEdouble()) @@ -128,26 +130,26 @@ static void DefineFloatMacros(MacroBuilder &Builder, StringRef Prefix, const llvm::fltSemantics *Sem, StringRef Ext) { const char *DenormMin, *Epsilon, *Max, *Min; - DenormMin = PickFP(Sem, "1.40129846e-45", "4.9406564584124654e-324", - "3.64519953188247460253e-4951", + DenormMin = PickFP(Sem, "5.9604644775390625e-8", "1.40129846e-45", + "4.9406564584124654e-324", "3.64519953188247460253e-4951", "4.94065645841246544176568792868221e-324", "6.47517511943802511092443895822764655e-4966"); - int Digits = PickFP(Sem, 6, 15, 18, 31, 33); - int DecimalDigits = PickFP(Sem, 9, 17, 21, 33, 36); - Epsilon = PickFP(Sem, "1.19209290e-7", "2.2204460492503131e-16", - "1.08420217248550443401e-19", + int Digits = PickFP(Sem, 3, 6, 15, 18, 31, 33); + int DecimalDigits = PickFP(Sem, 5, 9, 17, 21, 33, 36); + Epsilon = PickFP(Sem, "9.765625e-4", "1.19209290e-7", + "2.2204460492503131e-16", "1.08420217248550443401e-19", "4.94065645841246544176568792868221e-324", "1.92592994438723585305597794258492732e-34"); - int MantissaDigits = PickFP(Sem, 24, 53, 64, 106, 113); - int Min10Exp = PickFP(Sem, -37, -307, -4931, -291, -4931); - int Max10Exp = PickFP(Sem, 38, 308, 4932, 308, 4932); - int MinExp = PickFP(Sem, -125, -1021, -16381, -968, -16381); - int MaxExp = PickFP(Sem, 128, 1024, 16384, 1024, 16384); - Min = PickFP(Sem, "1.17549435e-38", "2.2250738585072014e-308", + int MantissaDigits = PickFP(Sem, 11, 24, 53, 64, 106, 113); + int Min10Exp = PickFP(Sem, -13, -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); + Min = PickFP(Sem, "6.103515625e-5", "1.17549435e-38", "2.2250738585072014e-308", "3.36210314311209350626e-4932", "2.00416836000897277799610805135016e-292", "3.36210314311209350626267781732175260e-4932"); - Max = PickFP(Sem, "3.40282347e+38", "1.7976931348623157e+308", + Max = PickFP(Sem, "6.5504e+4", "3.40282347e+38", "1.7976931348623157e+308", "1.18973149535723176502e+4932", "1.79769313486231580793728971405301e+308", "1.18973149535723176508575932662800702e+4932"); @@ -802,6 +804,7 @@ DefineFmt("__UINTPTR", TI.getUIntPtrType(), TI, Builder); DefineTypeWidth("__UINTPTR_WIDTH__", TI.getUIntPtrType(), TI, Builder); + DefineFloatMacros(Builder, "FLT16", &TI.getHalfFormat(), "F16"); DefineFloatMacros(Builder, "FLT", &TI.getFl
[PATCH] D34695: _Float16 preprocessor macro definitions
SjoerdMeijer added a comment. many thanks for reviewing and your help. https://reviews.llvm.org/D34695 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34695: _Float16 preprocessor macro definitions
scanon accepted this revision. scanon added a comment. LGTM as well. https://reviews.llvm.org/D34695 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34695: _Float16 preprocessor macro definitions
rogfer01 accepted this revision. rogfer01 added a subscriber: rsmith. rogfer01 added a comment. This revision is now accepted and ready to land. This LGTM, but wait a couple of days before comitting in case @rsmith or @scanon (or others!) have further comments. https://reviews.llvm.org/D34695 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34695: _Float16 preprocessor macro definitions
SjoerdMeijer updated this revision to Diff 114998. SjoerdMeijer added a comment. Fixed the typos, and added tests. https://reviews.llvm.org/D34695 Files: lib/Frontend/InitPreprocessor.cpp lib/Headers/float.h test/Headers/float16.c test/Preprocessor/init.c Index: test/Preprocessor/init.c === --- test/Preprocessor/init.c +++ test/Preprocessor/init.c @@ -301,6 +301,20 @@ // AARCH64:#define __DBL_MIN_EXP__ (-1021) // AARCH64:#define __DBL_MIN__ 2.2250738585072014e-308 // AARCH64:#define __DECIMAL_DIG__ __LDBL_DECIMAL_DIG__ +// AARCH64:#define __FLT16_DECIMAL_DIG__ 5 +// AARCH64:#define __FLT16_DENORM_MIN__ 5.9604644775390625e-8F16 +// AARCH64:#define __FLT16_DIG__ 3 +// AARCH64:#define __FLT16_EPSILON__ 9.765625e-4F16 +// AARCH64:#define __FLT16_HAS_DENORM__ 1 +// AARCH64:#define __FLT16_HAS_INFINITY__ 1 +// 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__ 6.5504e+4F16 +// AARCH64:#define __FLT16_MIN_10_EXP__ (-13) +// AARCH64:#define __FLT16_MIN_EXP__ (-14) +// AARCH64:#define __FLT16_MIN__ 6.103515625e-5F16 // AARCH64:#define __FLT_DENORM_MIN__ 1.40129846e-45F // AARCH64:#define __FLT_DIG__ 6 // AARCH64:#define __FLT_EPSILON__ 1.19209290e-7F @@ -9071,7 +9085,7 @@ // WEBASSEMBLY32-NEXT:#define __DECIMAL_DIG__ __LDBL_DECIMAL_DIG__ // WEBASSEMBLY32-NOT:#define __ELF__ // WEBASSEMBLY32-NEXT:#define __FINITE_MATH_ONLY__ 0 -// WEBASSEMBLY32-NEXT:#define __FLT_DECIMAL_DIG__ 9 +// WEBASSEMBLY32:#define __FLT_DECIMAL_DIG__ 9 // WEBASSEMBLY32-NEXT:#define __FLT_DENORM_MIN__ 1.40129846e-45F // WEBASSEMBLY32-NEXT:#define __FLT_DIG__ 6 // WEBASSEMBLY32-NEXT:#define __FLT_EPSILON__ 1.19209290e-7F @@ -9402,7 +9416,7 @@ // WEBASSEMBLY64-NEXT:#define __DECIMAL_DIG__ __LDBL_DECIMAL_DIG__ // WEBASSEMBLY64-NOT:#define __ELF__ // WEBASSEMBLY64-NEXT:#define __FINITE_MATH_ONLY__ 0 -// WEBASSEMBLY64-NEXT:#define __FLT_DECIMAL_DIG__ 9 +// WEBASSEMBLY64:#define __FLT_DECIMAL_DIG__ 9 // WEBASSEMBLY64-NEXT:#define __FLT_DENORM_MIN__ 1.40129846e-45F // WEBASSEMBLY64-NEXT:#define __FLT_DIG__ 6 // WEBASSEMBLY64-NEXT:#define __FLT_EPSILON__ 1.19209290e-7F Index: test/Headers/float16.c === --- /dev/null +++ test/Headers/float16.c @@ -0,0 +1,65 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -ffreestanding %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c99 -ffreestanding %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -ffreestanding %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -x c++ -ffreestanding %s +// expected-no-diagnostics + +#define __STDC_WANT_IEC_60559_TYPES_EXT__ +#include + +#ifndef FLT16_MIN_10_EXP +#error "Macro FLT16_MIN_10_EXP is missing." +#elif FLT16_MIN_10_EXP > -13 +#error "Macro FLT16_MIN_10_EXP is invalid." +#endif + +_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 +#error "Macro FLT16_MIN_EXP is invalid." +#endif + +_Static_assert(FLT16_MIN_EXP == __FLT16_MIN_EXP__, ""); + +#ifndef FLT16_MAX_10_EXP +#error "Macro FLT16_MAX_10_EXP is missing." +#elif FLT16_MAX_10_EXP < 4 +#error "Macro FLT16_MAX_10_EXP is invalid." +#endif + +_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 +#error "Macro FLT16_MAX_EXP is invalid." +#endif + +_Static_assert(FLT16_MAX_EXP == __FLT16_MAX_EXP__, ""); + +#ifndef FLT16_DECIMAL_DIG +#error "Macro FLT16_DECIMAL_DIG is missing." +#elif FLT16_DECIMAL_DIG < 5 +#error "Macro FLT16_DECIMAL_DIG is invalid." +#endif + +_Static_assert(FLT16_DECIMAL_DIG == __FLT16_DECIMAL_DIG__, ""); + +#ifndef FLT16_DIG +#error "Macro FLT16_DIG is missing." +#elif FLT16_DIG < 3 +#error "Macro FLT16_DIG is invalid." +#endif + +_Static_assert(FLT16_DIG == __FLT16_DIG__, ""); + +#ifndef FLT16_MANT_DIG +#error "Macro FLT16_MANT_DIG is missing." +#elif FLT16_MANT_DIG < 11 +#error "Macro FLT16_MANT_DIG is invalid." +#endif + +_Static_assert(FLT16_MANT_DIG == __FLT16_MANT_DIG__, ""); + Index: lib/Headers/float.h === --- lib/Headers/float.h +++ lib/Headers/float.h @@ -143,4 +143,18 @@ # define LDBL_DECIMAL_DIG __LDBL_DECIMAL_DIG__ #endif +#ifdef __STDC_WANT_IEC_60559_TYPES_EXT__ +# define FLT16_MANT_DIG__FLT16_MANT_DIG__ +# define FLT16_DECIMAL_DIG __FLT16_DECIMAL_DIG__ +# define FLT16_DIG __FLT16_DIG__ +# define FLT16_MIN_EXP __FLT16_MIN_EXP__ +# define FLT16_MIN_10_EXP __FLT16_MIN_10_EXP__ +# define FLT16_MAX_EXP __FLT16_MAX_EXP__ +# define FLT16_MAX_10_EXP __FLT16_MAX_10_EXP__ +# define FLT16_MAX __FLT16_MAX
[PATCH] D34695: _Float16 preprocessor macro definitions
SjoerdMeijer added inline comments. Comment at: lib/Headers/float.h:137 +#ifdef __STDC_WANT_IEC_60559_TYPES_EXT__ +# define FLT16_MANT_DIG __FLT16_MANT_DIG__ scanon wrote: > rogfer01 wrote: > > scanon wrote: > > > rogfer01 wrote: > > > > My understanding is that, given that we support TS18661-2 by default, > > > > this macro should be predefined by clang and then there is no need to > > > > protect these macros. > > > > > > > > You may want to add a test for this in `test/Preprocessor/init.c`. > > > Where do you see that the `__STDC_WANT_IEC_60559_TYPES_EXT__` macro > > > should be predefined by clang? > > Hi Steve, > > > > certainly you're right, the TS says > > > > > The new identifiers added to C11 library headers by this part of ISO/IEC > > > TS-18661 are defined or declared by their respective headers only if > > > `__STDC_WANT_IEC_60559_TYPES_EXT__` is defined as a macro at the point in > > > the source file where the appropriate header is first included. > > > > so (if I read this right) these identifiers are only available if such > > macro is defined when including `float.h`. > > > > Can I assume from your comment that someone else should define it? Perhaps > > the `float.h` header itself, some other file in the C-library > > implementation or the user of the compiler via some > > `-D__STDC_WANT_IEC_60559_TYPES_EXT__`, but not be predefined by the > > compiler? If this is the case, then the macros still have to be guarded > > conditionally (as they were in the original patch). > > > > Does this make sense? Thanks. > I think we could justify defining it ourselves under non-strict compilation > modes; alternatively, system headers might define it for users in non-strict > modes. > > My reading of the TS is that in strict mode, these types and macros should be > hidden unless the user explicitly requests them by defining > `__STDC_WANT_IEC_60559_TYPES_EXT__` themselves. Thanks, very useful discussion and clarification. I will add some tests for this, which I indeed forgot. Cheers. https://reviews.llvm.org/D34695 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34695: _Float16 preprocessor macro definitions
scanon added inline comments. Comment at: lib/Headers/float.h:137 +#ifdef __STDC_WANT_IEC_60559_TYPES_EXT__ +# define FLT16_MANT_DIG __FLT16_MANT_DIG__ rogfer01 wrote: > scanon wrote: > > rogfer01 wrote: > > > My understanding is that, given that we support TS18661-2 by default, > > > this macro should be predefined by clang and then there is no need to > > > protect these macros. > > > > > > You may want to add a test for this in `test/Preprocessor/init.c`. > > Where do you see that the `__STDC_WANT_IEC_60559_TYPES_EXT__` macro should > > be predefined by clang? > Hi Steve, > > certainly you're right, the TS says > > > The new identifiers added to C11 library headers by this part of ISO/IEC > > TS-18661 are defined or declared by their respective headers only if > > `__STDC_WANT_IEC_60559_TYPES_EXT__` is defined as a macro at the point in > > the source file where the appropriate header is first included. > > so (if I read this right) these identifiers are only available if such macro > is defined when including `float.h`. > > Can I assume from your comment that someone else should define it? Perhaps > the `float.h` header itself, some other file in the C-library implementation > or the user of the compiler via some `-D__STDC_WANT_IEC_60559_TYPES_EXT__`, > but not be predefined by the compiler? If this is the case, then the macros > still have to be guarded conditionally (as they were in the original patch). > > Does this make sense? Thanks. I think we could justify defining it ourselves under non-strict compilation modes; alternatively, system headers might define it for users in non-strict modes. My reading of the TS is that in strict mode, these types and macros should be hidden unless the user explicitly requests them by defining `__STDC_WANT_IEC_60559_TYPES_EXT__` themselves. https://reviews.llvm.org/D34695 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34695: _Float16 preprocessor macro definitions
rogfer01 added inline comments. Comment at: lib/Headers/float.h:137 +#ifdef __STDC_WANT_IEC_60559_TYPES_EXT__ +# define FLT16_MANT_DIG __FLT16_MANT_DIG__ scanon wrote: > rogfer01 wrote: > > My understanding is that, given that we support TS18661-2 by default, this > > macro should be predefined by clang and then there is no need to protect > > these macros. > > > > You may want to add a test for this in `test/Preprocessor/init.c`. > Where do you see that the `__STDC_WANT_IEC_60559_TYPES_EXT__` macro should be > predefined by clang? Hi Steve, certainly you're right, the TS says > The new identifiers added to C11 library headers by this part of ISO/IEC > TS-18661 are defined or declared by their respective headers only if > `__STDC_WANT_IEC_60559_TYPES_EXT__` is defined as a macro at the point in the > source file where the appropriate header is first included. so (if I read this right) these identifiers are only available if such macro is defined when including `float.h`. Can I assume from your comment that someone else should define it? Perhaps the `float.h` header itself, some other file in the C-library implementation or the user of the compiler via some `-D__STDC_WANT_IEC_60559_TYPES_EXT__`, but not be predefined by the compiler? If this is the case, then the macros still have to be guarded conditionally (as they were in the original patch). Does this make sense? Thanks. https://reviews.llvm.org/D34695 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34695: _Float16 preprocessor macro definitions
scanon added inline comments. Comment at: lib/Headers/float.h:137 +#ifdef __STDC_WANT_IEC_60559_TYPES_EXT__ +# define FLT16_MANT_DIG __FLT16_MANT_DIG__ rogfer01 wrote: > My understanding is that, given that we support TS18661-2 by default, this > macro should be predefined by clang and then there is no need to protect > these macros. > > You may want to add a test for this in `test/Preprocessor/init.c`. Where do you see that the `__STDC_WANT_IEC_60559_TYPES_EXT__` macro should be predefined by clang? https://reviews.llvm.org/D34695 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34695: _Float16 preprocessor macro definitions
rogfer01 added inline comments. Comment at: lib/Headers/float.h:137 +#ifdef __STDC_WANT_IEC_60559_TYPES_EXT__ +# define FLT16_MANT_DIG __FLT16_MANT_DIG__ My understanding is that, given that we support TS18661-2 by default, this macro should be predefined by clang and then there is no need to protect these macros. You may want to add a test for this in `test/Preprocessor/init.c`. Comment at: lib/Headers/float.h:139-142 +# define FLT16_DECIMAL_DIG __LT16_DECIMAL_DIG__ +# define FLT16_DIG __LT16_DIG__ +# define FLT16_MIN_EXP __LT16_MIN_EXP__ +# define FLT16_MIN_10_EXP __FLT16_MIN_10_EXP__ There is a typo here, these macros should start with `__FLT16_`. Add a test for these names `test/Headers/float.c`. https://reviews.llvm.org/D34695 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34695: _Float16 preprocessor macro definitions
SjoerdMeijer created this revision. Herald added subscribers: aheejin, dschuff, jfb. This adds the _Float16 preprocessor macro definitions. https://reviews.llvm.org/D34695 Files: lib/Frontend/InitPreprocessor.cpp lib/Headers/float.h test/Preprocessor/init.c Index: test/Preprocessor/init.c === --- test/Preprocessor/init.c +++ test/Preprocessor/init.c @@ -285,6 +285,20 @@ // AARCH64:#define __DBL_MIN_EXP__ (-1021) // AARCH64:#define __DBL_MIN__ 2.2250738585072014e-308 // AARCH64:#define __DECIMAL_DIG__ __LDBL_DECIMAL_DIG__ +// AARCH64:#define __FLT16_DECIMAL_DIG__ 5 +// AARCH64:#define __FLT16_DENORM_MIN__ 5.9604644775390625e-8F16 +// AARCH64:#define __FLT16_DIG__ 3 +// AARCH64:#define __FLT16_EPSILON__ 9.765625e-4F16 +// AARCH64:#define __FLT16_HAS_DENORM__ 1 +// AARCH64:#define __FLT16_HAS_INFINITY__ 1 +// 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__ 6.5504e+4F16 +// AARCH64:#define __FLT16_MIN_10_EXP__ (-13) +// AARCH64:#define __FLT16_MIN_EXP__ (-14) +// AARCH64:#define __FLT16_MIN__ 6.103515625e-5F16 // AARCH64:#define __FLT_DENORM_MIN__ 1.40129846e-45F // AARCH64:#define __FLT_DIG__ 6 // AARCH64:#define __FLT_EPSILON__ 1.19209290e-7F @@ -8884,7 +8898,7 @@ // WEBASSEMBLY32-NEXT:#define __DECIMAL_DIG__ __LDBL_DECIMAL_DIG__ // WEBASSEMBLY32-NOT:#define __ELF__ // WEBASSEMBLY32-NEXT:#define __FINITE_MATH_ONLY__ 0 -// WEBASSEMBLY32-NEXT:#define __FLT_DECIMAL_DIG__ 9 +// WEBASSEMBLY32:#define __FLT_DECIMAL_DIG__ 9 // WEBASSEMBLY32-NEXT:#define __FLT_DENORM_MIN__ 1.40129846e-45F // WEBASSEMBLY32-NEXT:#define __FLT_DIG__ 6 // WEBASSEMBLY32-NEXT:#define __FLT_EPSILON__ 1.19209290e-7F @@ -9210,7 +9224,7 @@ // WEBASSEMBLY64-NEXT:#define __DECIMAL_DIG__ __LDBL_DECIMAL_DIG__ // WEBASSEMBLY64-NOT:#define __ELF__ // WEBASSEMBLY64-NEXT:#define __FINITE_MATH_ONLY__ 0 -// WEBASSEMBLY64-NEXT:#define __FLT_DECIMAL_DIG__ 9 +// WEBASSEMBLY64:#define __FLT_DECIMAL_DIG__ 9 // WEBASSEMBLY64-NEXT:#define __FLT_DENORM_MIN__ 1.40129846e-45F // WEBASSEMBLY64-NEXT:#define __FLT_DIG__ 6 // WEBASSEMBLY64-NEXT:#define __FLT_EPSILON__ 1.19209290e-7F Index: lib/Headers/float.h === --- lib/Headers/float.h +++ lib/Headers/float.h @@ -134,4 +134,18 @@ # define LDBL_DECIMAL_DIG __LDBL_DECIMAL_DIG__ #endif +#ifdef __STDC_WANT_IEC_60559_TYPES_EXT__ +# define FLT16_MANT_DIG __FLT16_MANT_DIG__ +# define FLT16_DECIMAL_DIG __LT16_DECIMAL_DIG__ +# define FLT16_DIG __LT16_DIG__ +# define FLT16_MIN_EXP __LT16_MIN_EXP__ +# define FLT16_MIN_10_EXP __FLT16_MIN_10_EXP__ +# define FLT16_MAX_EXP __FLT16_MAX_EXP__ +# define FLT16_MAX_10_EXP __FLT16_MAX_10_EXP__ +# define FLT16_MAX __FLT16_MAX__ +# define FLT16_EPSILON __FLT16_EPSILON__ +# define FLT16_MIN __FLT16_MIN__ +# define FLT_TRUE_MIN __FLT_TRUE_MIN__ +#endif /* __STDC_WANT_IEC_60559_TYPES_EXT__ */ + #endif /* __FLOAT_H */ Index: lib/Frontend/InitPreprocessor.cpp === --- lib/Frontend/InitPreprocessor.cpp +++ lib/Frontend/InitPreprocessor.cpp @@ -109,9 +109,11 @@ /// PickFP - This is used to pick a value based on the FP semantics of the /// specified FP model. template -static T PickFP(const llvm::fltSemantics *Sem, T IEEESingleVal, +static T PickFP(const llvm::fltSemantics *Sem, T IEEEHalfVal, T IEEESingleVal, T IEEEDoubleVal, T X87DoubleExtendedVal, T PPCDoubleDoubleVal, T IEEEQuadVal) { + if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEhalf()) +return IEEEHalfVal; if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEsingle()) return IEEESingleVal; if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEdouble()) @@ -127,26 +129,26 @@ static void DefineFloatMacros(MacroBuilder &Builder, StringRef Prefix, const llvm::fltSemantics *Sem, StringRef Ext) { const char *DenormMin, *Epsilon, *Max, *Min; - DenormMin = PickFP(Sem, "1.40129846e-45", "4.9406564584124654e-324", - "3.64519953188247460253e-4951", + DenormMin = PickFP(Sem, "5.9604644775390625e-8", "1.40129846e-45", + "4.9406564584124654e-324", "3.64519953188247460253e-4951", "4.94065645841246544176568792868221e-324", "6.47517511943802511092443895822764655e-4966"); - int Digits = PickFP(Sem, 6, 15, 18, 31, 33); - int DecimalDigits = PickFP(Sem, 9, 17, 21, 33, 36); - Epsilon = PickFP(Sem, "1.19209290e-7", "2.2204460492503131e-16", - "1.08420217248550443401e-19", + int Digits = PickFP(Sem, 3, 6, 15, 18, 31, 33); + int DecimalDigits = PickFP(Sem, 5, 9, 17, 21, 33, 36); + Epsilon = PickFP(Sem, "9.765625e-4", "1.19209290e-7", + "2.2