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

-mfpmath=sse is not supported by Emscripten #1173

Closed
tetious opened this issue Jul 12, 2024 · 5 comments
Closed

-mfpmath=sse is not supported by Emscripten #1173

tetious opened this issue Jul 12, 2024 · 5 comments

Comments

@tetious
Copy link

tetious commented Jul 12, 2024

Hi!

The change in this commit to enable sse with 32 bit builds seems to have broken building with Emscripten:
godot-jolt@ebccdcb

It throws: error: unknown FP unit 'sse'

I'm not sure if this is the correct path, but I can workaround by excluding it like this:

if (NOT MSVC AND NOT EMSCRIPTEN)
	target_compile_options(Jolt PUBLIC -mfpmath=sse)
endif()

Perhaps there is a better way? I could file a PR to make this change, if you like.

@jrouwe
Copy link
Owner

jrouwe commented Jul 12, 2024

Sorry about that. I get an error on all the other instruction set flags too, so I opted to bypass the entire code block.

@tetious
Copy link
Author

tetious commented Jul 12, 2024

Awesome! Thank you!

@mihe
Copy link
Contributor

mihe commented Jul 12, 2024

I'm a bit confused by this.

Shouldn't Jolt be adding the -msimd128 flag itself instead, as well as any -msse* flags, based on the relevant CMake options? From what I can tell from Emscripten's documentation it still supports all these flags just fine, albeit with some gaps/emulation in the instructions themselves by the looks of it.

Clearly mfpmath=sse isn't supported though, judging by the error here, but seeing as how the user is forced to append the rest of them through something like CMAKE_CXX_FLAGS anyway I don't quite see the point in omitting them from Jolt altogether.

I'm also curious about the specific mention of -msse4.2 here:

# Emscripten uses no special flags, if you want to turn on SIMD you should use -msimd128 -msse4.2

Was SSE 4.2 just brought up as an example, or is there some limitation with Jolt and Emscripten that prevents targeting SSE2?

(I realize SSE 4.2 has pretty much 100% coverage these days, but Godot is still hanging on to SSE2 for now.)

EDIT: I see now that the browser coverage isn't great for WebAssembly SIMD in general, but that's beside the point I guess.

@jrouwe
Copy link
Owner

jrouwe commented Jul 13, 2024

Shouldn't Jolt be adding the -msimd128 flag itself instead, as well as any -msse* flags, based on the relevant CMake options?

Yes it should. I've just submitted a change that adds a cmake option USE_WASM_SIMD which will add the needed flags.

Was SSE 4.2 just brought up as an example, or is there some limitation with Jolt and Emscripten that prevents targeting SSE2?

Emscripten just translates the SSE/AVX instructions to WASM SIMD instructions. The reason why I didn't pick AVX is that Jolt uses 256 bit SIMD instructions when AVX is enabled, which is not supported by emscripten. I picked the next highest which is SSE 4.2. I don't think it matters which SSE version you pick as it all gets converted to WASM instructions and the browser is responsible for translating them to native (SSE / NEON) instructions based on the CPU architecture.

It may be that rewriting Jolt to use the WASM intrinsics gives better performance, but having the SSE instructions automatically convert to WASM instructions was a lot less work.

@mihe
Copy link
Contributor

mihe commented Jul 13, 2024

Yes it should. I've just submitted a change that adds a cmake option USE_WASM_SIMD which will add the needed flags.

Great, thank you! Now there's just the dilemma of whether to actually enable it or not I guess. 😅

I don't think it matters which SSE version you pick as it all gets converted to WASM instructions and the browser is responsible for translating them to native (SSE / NEON) instructions based on the CPU architecture.

I'm a bit surprised that the minimum hardware requirements for WASM SIMD isn't explicitly mentioned anywhere for any of the major browsers (that I could find at least). I had to dig through the V8 source code to find that it's SSE4.1 for Chromium-based browsers. The one SSE4.2 intrinsic that's mappable to WASM SIMD (_mm_cmpgt_epi64) seems to have an SSE3 fallback in V8, as far as I can tell, so I assume they aim for everything to run on the minimum instruction set (i.e. SSE4.1).

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

No branches or pull requests

3 participants