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

Remove unnecessary functions from jsmath.c. NFC #23143

Merged
merged 1 commit into from
Dec 13, 2024

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Dec 12, 2024

See the comments at the top of emscripten/js_math.h for why JS versions of these functions are not needed.

As a followup I plan to map jsmath.c functions to em_math.h functions instead of using EM_JS here.

See #19284

@sbc100 sbc100 changed the title Remove unnecessary functions from JSMATH. NFC Remove unnecessary functions from jsmath.c. NFC Dec 12, 2024
@sbc100
Copy link
Collaborator Author

sbc100 commented Dec 12, 2024

See

// The following operations have very fast WebAssembly opcodes. Therefore they are not
// exposed as individual functions:
// Math.abs(x) -> f32.abs and f64.abs. (use fabsf() and fabs() from math.h)
// Math.ceil -> f32.ceil and f64.ceil (ceil() and ceilf() in math.h)
// Math.clz32(x) -> i32.clz and i64.clz (call __builtin_clz() and __builtin_clzll())
// Math.floor -> f32.floor and f64.floor (floor() and floorf() in math.h)
// Math.fround -> f64.promote_f32(f32.demote_f64()) (call double d = (double)(float)someDouble;)
// Math.imul(x, y) -> i32.mul and i64.mul (directly multiply two signed integers)
// Math.min -> f32.min and f64.min (fminf() and fmin() in math.h)
// Math.max -> f32.max and f64.max (fmaxf() and fmax() in math.h)
// Math.trunc -> f32.trunc and f64.trunc (truncf() and trunc() in math.h)

@sbc100 sbc100 force-pushed the simplify_jsmath branch 2 times, most recently from e724526 to f421b08 Compare December 12, 2024 20:05
@sbc100 sbc100 requested review from kripken and dschuff December 12, 2024 20:05
return (x - Math.floor(x) != .5) ? round(x) : round(x / 2) * 2;
})

double nearbyint(double x) { return rint(x); }
float nearbyintf(float x) { return rintf(x); }
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These two are already implement in musl in terms of rint and rintf

See the comments at the top of `emscripten/js_math.h` for why JS
versions of these functions are not needed.

As a followup I plan to map `jsmath.c` functions to `em_math.h`
functions instead of using EM_JS here.

See emscripten-core#19284
@sbc100 sbc100 merged commit d04f14a into emscripten-core:main Dec 13, 2024
26 of 28 checks passed
@sbc100 sbc100 deleted the simplify_jsmath branch December 13, 2024 00:15
hedwigz pushed a commit to hedwigz/emscripten that referenced this pull request Dec 18, 2024
See the comments at the top of `emscripten/js_math.h` for why JS
versions of these functions are not needed.

As a followup I plan to map `jsmath.c` functions to `em_math.h`
functions instead of using EM_JS here.

See emscripten-core#19284
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