Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FP env issues #11087

Merged
merged 3 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ See docs/process.md for how version tagging works.

Current Trunk
-------------
- Stop defining `FE_INEXACT` and other floating point exception macros in libc,
since we don't support them. That also prevents musl from including code using
pragmas that don't make sense for wasm. Ifdef out other uses of those pragmas
as well, as tip of tree LLVM now fails to compile them on wasm. (#11087)
- Update libcxx and libcxxabi to LLVM 10 release branch (#11038).
- Remove `BINARYEN_PASSES` setting (#11057). We still have
`BINARYEN_EXTRA_PASSES` (the removed setting completely overrides the set
Expand Down
9 changes: 1 addition & 8 deletions system/lib/libc/musl/arch/emscripten/bits/fenv.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
#define FE_INVALID 1
#define __FE_DENORM 2
#define FE_DIVBYZERO 4
#define FE_OVERFLOW 8
#define FE_UNDERFLOW 16
#define FE_INEXACT 32
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these designed to be disabled by simply not being defined? That seems unusual, but I don't know this part of the standard.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I learned this today as well. It is quite unusual for the C spec, I agree.

Libraries may define in <fenv.h> only the macro values above they support (the others may not be defined).

http://www.cplusplus.com/reference/cfenv/FE_INEXACT/

And musl in fact checks whether things are defined in order to ifdef relevant code. Which actually is helpful in this case!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if they are designed that way exactly, but musl code seems to use them that way: see e.g. https://github.com/emscripten-core/emscripten/blob/master/system/lib/libc/musl/src/fenv/__flt_rounds.c and in particular https://github.com/emscripten-core/emscripten/blob/2bca083cbbd5a4133db61fbd74d04f7feecfa907/system/lib/libc/musl/src/math/lrint.c gates its use of the FENV_ACCESS pragma on FE_INEXACT being defined.


#define FE_ALL_EXCEPT 63
#define FE_ALL_EXCEPT 0

#define FE_TONEAREST 0
#define FE_DOWNWARD 0x400
Expand Down
4 changes: 4 additions & 0 deletions system/lib/libc/musl/src/math/fma.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ static int getexp(long double x)

double fma(double x, double y, double z)
{
#ifndef __EMSCRIPTEN__
#pragma STDC FENV_ACCESS ON
#endif
long double hi, lo1, lo2, xy;
int round, ez, exy;

Expand Down Expand Up @@ -331,7 +333,9 @@ static inline struct dd dd_mul(double a, double b)
*/
double fma(double x, double y, double z)
{
#ifndef __EMSCRIPTEN__
#pragma STDC FENV_ACCESS ON
#endif
double xs, ys, zs, adj;
struct dd xy, r;
int oround;
Expand Down
2 changes: 2 additions & 0 deletions system/lib/libc/musl/src/math/fmaf.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
*/
float fmaf(float x, float y, float z)
{
#ifndef __EMSCRIPTEN__
#pragma STDC FENV_ACCESS ON
#endif
double xy, result;
union {double f; uint64_t i;} u;
int e;
Expand Down
2 changes: 2 additions & 0 deletions system/lib/libc/musl/src/math/fmal.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ static inline struct dd dd_mul(long double a, long double b)
*/
long double fmal(long double x, long double y, long double z)
{
#ifndef __EMSCRIPTEN__
#pragma STDC FENV_ACCESS ON
#endif
long double xs, ys, zs, adj;
struct dd xy, r;
int oround;
Expand Down
2 changes: 2 additions & 0 deletions system/lib/libc/musl/src/math/ilogb.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

int ilogb(double x)
{
#ifndef __EMSCRIPTEN__
#pragma STDC FENV_ACCESS ON
#endif
union {double f; uint64_t i;} u = {x};
uint64_t i = u.i;
int e = i>>52 & 0x7ff;
Expand Down
2 changes: 2 additions & 0 deletions system/lib/libc/musl/src/math/ilogbf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

int ilogbf(float x)
{
#ifndef __EMSCRIPTEN__
#pragma STDC FENV_ACCESS ON
#endif
union {float f; uint32_t i;} u = {x};
uint32_t i = u.i;
int e = i>>23 & 0xff;
Expand Down
4 changes: 4 additions & 0 deletions system/lib/libc/musl/src/math/ilogbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ int ilogbl(long double x)
#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
int ilogbl(long double x)
{
#ifndef __EMSCRIPTEN__
#pragma STDC FENV_ACCESS ON
#endif
union ldshape u = {x};
uint64_t m = u.i.m;
int e = u.i.se & 0x7fff;
Expand All @@ -32,7 +34,9 @@ int ilogbl(long double x)
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
int ilogbl(long double x)
{
#ifndef __EMSCRIPTEN__
#pragma STDC FENV_ACCESS ON
#endif
union ldshape u = {x};
int e = u.i.se & 0x7fff;

Expand Down