Skip to content

wasm2c: optimize performance of float handling - #2822

Merged
shravanrn merged 1 commit into
WebAssembly:mainfrom
UT-Security:floatperf
Aug 13, 2026
Merged

shravanrn merged 1 commit into
WebAssembly:mainfrom
UT-Security:floatperf

Conversation

@shravanrn

@shravanrn shravanrn commented Aug 13, 2026 •

Copy link
Copy Markdown
Collaborator

Optimize performance of float handling in wasm2c

  • The sqrt and sqrtf calls currently use the libc functions. The libc version of this function goes through the PLT and has extra operations to do with setting errno. However, using the __builtin_elementwise_sqrt (available only in clang), reduces this to a single instruction in x86-64. __builtin_sqrt works on gcc/clang but requires the caller to pass in the -fno-math-errno flag.
  • Currently f32 constants are emitted without a "f" suffix, i.e., it is emitted as doubles. Unfortunately, with -frounding-math, this means that double to float conversion is done at runtime instead of compile time.

Together these 2 changes shave off another 3% when running a sandboxed libsoundtouch which is used by Firefox to adjust the playback speed of audio files.

@sbc100 sbc100 left a comment

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.

Nice!

@shravanrn
shravanrn enabled auto-merge (rebase) August 13, 2026 05:34
@shravanrn
shravanrn merged commit 279aac0 into WebAssembly:main Aug 13, 2026
17 checks passed
@shravanrn
shravanrn deleted the floatperf branch August 13, 2026 06:10
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.

2 participants