Skip to content

Use -mfpu=vfpv3 instead of -march=native for cross compilation sdks.#1192

Merged
kripken merged 1 commit intoWebAssembly:masterfrom
flackr:arch-native
Feb 21, 2018
Merged

Use -mfpu=vfpv3 instead of -march=native for cross compilation sdks.#1192
kripken merged 1 commit intoWebAssembly:masterfrom
flackr:arch-native

Conversation

@flackr
Copy link
Copy Markdown
Contributor

@flackr flackr commented Sep 18, 2017

Some compiler environments (e.g. cross compilation sdk) do not support -march=native so we should test for support before adding the flag.

@dschuff
Copy link
Copy Markdown
Member

dschuff commented Sep 18, 2017

Hm, I actually don't think we should automatically have -march=native in here at all; even when not cross-compiling, you risk generating a binary that won't run on the deployed machine. It's something the user should be able to do (i.e. we should support adding extra cflags in the build), but not something we should do automatically. So to fix your issue specifically, I guess I'd prefer a PR that removes it entirely.

@dschuff
Copy link
Copy Markdown
Member

dschuff commented Sep 18, 2017

(We could replace it with something like -mfpu=neon which would enable NEON. That seems to have been the original intention, and should be safe, as practically every ARM chip that is likely to run wasm should have that.

@flackr
Copy link
Copy Markdown
Contributor Author

flackr commented Sep 22, 2017

Sure, that works. Done.

@flackr flackr changed the title Test for compiler support for -march=native Use -mfpu=neon instead of -march=native for cross compilation sdks. Sep 22, 2017
CMakeLists.txt Outdated
@@ -143,7 +143,7 @@ ELSE()
ADD_COMPILE_FLAG("-mfpmath=sse")
elseif(TARGET_ARCH STREQUAL "ARM")
# stub for ARM-specific instructions. GCC6 adds NEON with the below flags
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we just remove this comment altogether now?

@dschuff
Copy link
Copy Markdown
Member

dschuff commented Sep 22, 2017

Just the one nit, and then LGTM. @kripken do you have any objections or better ideas?

@kripken
Copy link
Copy Markdown
Member

kripken commented Sep 22, 2017

Looks ok to me (but not my area of expertise).

@sunfishcode
Copy link
Copy Markdown
Member

Does -mfpu=neon affect the handling of subnormals in the implementation of floating-point operators?

@dschuff
Copy link
Copy Markdown
Member

dschuff commented Sep 22, 2017

What I wanted from this particular change was to go from an essentially nondeterministic build (i.e. it depends on whatever the host machine has) to something that's at least reproduceable. If I remember correctly, ARMv7+NEON always uses FTZ for vectors, but I'm not sure about scalars, presumably it's the same. So it may not be compliant with wasm in that respect. I think vfpv4 would probably work. It would rule out Cortex-A9-class hardware which IIRC is very common, but realistically, because of the zoo of configurations, anyone doing an ARM build probably has to have a particular set of configurations in mind, and at least I don't have one. Perhaps @flackr or whoever added this code does?

@dschuff
Copy link
Copy Markdown
Member

dschuff commented Sep 22, 2017

actually vfpv3 supports denormals too, and it looks like vfpv4 just adds half-precision and FMA. It looks like if you use -mfpu=vfpv3 it assumes 32 D registers, and FPUs which also support NEON have that many. If we use -mfpu=vfpv3-d16 then it includes e.g. cortex-a9 cpus without NEON. I think pretty much everything these days supports NEON. That was almost the case when we decided several years ago that NaCl on ARM would require NEON support, so it should be pretty safe now.

So yeah in summary, let's make this -mfpu=vfpv3.

@gczuczy
Copy link
Copy Markdown

gczuczy commented Feb 21, 2018

May I ask whether this has been merged?

FreeBSD/aarch64 hit this issue, and the relevant bug report is https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=225600 .

So, this would most probably solve the current issue with the FreeBSD port.

@flackr
Copy link
Copy Markdown
Contributor Author

flackr commented Feb 21, 2018

Apologies for the delay - I didn't notice we had arrived at a resolution. I've adopted the suggested flag and dropped the comment.

In my case I'm targeting a raspberry pi, building using a cross compilation sdk from a high end x86_64 desktop.

@flackr flackr changed the title Use -mfpu=neon instead of -march=native for cross compilation sdks. Use -mfpu=vfpv3 instead of -march=native for cross compilation sdks. Feb 21, 2018
@jbeich
Copy link
Copy Markdown
Contributor

jbeich commented Feb 21, 2018

@gczuczy, aarch64 doesn't support any -mfpu= value e.g.,

$ gcc7 -mfpu=vfpv3 test.c
gcc7: error: unrecognized command line option '-mfpu=vfpv3'
$ clang60 -mfpu=vfpv3 test.c
clang-6.0: warning: argument unused during compilation: '-mfpu=vfpv3' [-Wunused-command-line-argument]

@jbeich
Copy link
Copy Markdown
Contributor

jbeich commented Feb 21, 2018

@flackr, can you squash commits into one and rebase against master branch? I plan #1438 to depend on this one but it doesn't look pretty atm.

@flackr
Copy link
Copy Markdown
Contributor Author

flackr commented Feb 21, 2018

Done.

@kripken
Copy link
Copy Markdown
Member

kripken commented Feb 21, 2018

Thanks!

@kripken kripken merged commit 07f6dfb into WebAssembly:master Feb 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants