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

allow tomsfastmath to be built without stdlib #34

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

ryancdotorg
Copy link
Contributor

This commit enables tomsfastmath to be built with --no-standard-libraries provided TFM_NO_STDLIB is defined, which happens automatically if a web assembly build target is detected.

The only functionality this disables is the fp_rand function.

This pull request is also contains the required changes in #32 and #33.

The only use of `malloc`/`free` in tomfastmath is in
src/numtheory/fp_prime_random_ex.c, and the size required can be
calculated from the function arguments, so we can just use
a variable-length automatic array instead.

Variable-length automatic arrays are a C99 feature, and TFM already doesn’t
compile as C90, so we might as well take advantage of it.
fp_ident is the only place tomsfast math uses string manipulation
functions when built as a library. This commit replaces them with
safe, trivial functions for concatonating static strings and numbers
together.
This commit enables tomsfastmath to be built with
`--no-standard-libraries` provided `TFM_NO_STDLIB` is defined, which
happens automatically if a web assembly build target is detected.

The only functionality this disables is the `fp_rand` function.
@ryancdotorg ryancdotorg marked this pull request as draft January 6, 2024 13:15
Comment on lines +12 to +13
#if TFM_NO_STDLIB
/* do nothing */
Copy link
Collaborator

Choose a reason for hiding this comment

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

This worries me a bit, 'cause it allows anyone to defined -DTOM_NO_STDLIB=1 regardless of compiler, and when looking through the code, this feature makes heavy use of GCC features.

People might want to build without having to link with stdlib for other reasons than webasm...

It's possible that this should simply be documented with fierce warnings not to try this with other compilers than GCC or derivatives thereof (like clang)

@ryancdotorg
Copy link
Contributor Author

ryancdotorg commented Sep 16, 2024 via email

@levitte
Copy link
Collaborator

levitte commented Sep 16, 2024

That would be a good thing, methinks

I use clang for webasm builds, it does work there. I can add some guards to try to verify the compiler, though.

On September 16, 2024 6:17:20 AM GMT+01:00, Richard Levitte @.**> wrote: @levitte commented on this pull request. > +#if TFM_NO_STDLIB +/ do nothing */ This worries me a bit, 'cause it allows anyone to defined -DTOM_NO_STDLIB=1 regardless of compiler, and when looking through the code, this feature makes heavy use of GCC features. People might want to build without having to link with stdlib for other reasons than webasm... It's possible that this should simply be documented with fierce warnings not to try this with other compilers than GCC or derivatives thereof (like clang)

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