-
Notifications
You must be signed in to change notification settings - Fork 18
Add new implementation of math library (ibmcs), remove math library dependency from strtod.c #438
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
base: master
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @ayoopierre, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refactors the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request removes the dependency on the local math.h
implementation by deleting the math-related headers and updating strtod.c
to use compiler built-ins. The changes are generally good, but there are some issues with type correctness when assigning infinity and NaN values to long double
variables. I've pointed out several places where __builtin_inff()
(for float
) or __builtin_inf()
(for double
) are used instead of the correct __builtin_infl()
for long double
. This can lead to precision loss or incorrect behavior. Please address these to ensure type safety.
stdlib/strtod.c
Outdated
} | ||
|
||
*result = (*sign) * INFINITY; | ||
*result = (*sign) * __builtin_inff(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stdlib/strtod.c
Outdated
} | ||
|
||
*result = NAN; | ||
*result = __builtin_nanf(""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stdlib/strtod.c
Outdated
} | ||
else if (total_exp > exp_max) { | ||
result = INFINITY; | ||
result = __builtin_inff(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stdlib/strtod.c
Outdated
#if LDBL_MAX_10_EXP < (1 << POW10_LOOKUPS) | ||
if (exp >= (1 << POW10_LOOKUPS)) { | ||
return negative ? 0 : INFINITY; | ||
return negative ? 0 : __builtin_inf(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
09fa8de
to
d91df16
Compare
2 things regarding splitting this into commits:
Also it's worth noting that |
54ec7a8
to
3831e3b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pointed out just a few findings. Other notes:
- I don't know which version (and from where) we've imported the code. At least add some info in the commit (+maybe something like
README.phoenix
where you describe the imported version and eventual modifications + some rationale) - the build is still not splot into
libc.a
/libm.a
libm/math
->libm/phoenix
?- maybe consider forking libmcs instead if there will be some modifications to be made, I'm also not sure about importing all of the docs here
- why can't we use math headers in
strtod
?
Makefile
Outdated
mkdir -p "$(HEADERS_INSTALL_DIR)"; \ | ||
cp -a include/* "$(HEADERS_INSTALL_DIR)"; | ||
cp -a include/* "$(HEADERS_INSTALL_DIR)"; \ | ||
cp -a libm/libmcs/libm/include/* "$(HEADERS_INSTALL_DIR)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
always installing libmcs
headers?
Also - installing a global heder like config.h
is disaster-waiting-to-happen. Don't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, with the @lukileczo and @agkaminski, we have decided that libmcs headers should be installed at all times since they provide complete C99 set of function declarations, constants and macros, and If a need arises we will add Phoenix implementation of function that are currently not implemented in libphoenix. Also having multiple versions of header is a major headache due to installation in the toolchain. The config.h file will be removed, this requires some modification to the source files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no trace of this in any commit message or any file. How other developers could learn about it?
If there is no possibility to use the old headers - they are dead code? So - should they be removed?
We have some internal projects which depend on current libm implementation (and possibly header files) - maybe it's worth to check if they will still compile/work as expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Old header files have been removed, also libphoenix implementation has been modified for compatibility, with new headers (since there are no longer macros for sinf for instance, wrappers have been added). Apps such as voxeldemo, rotating rectangle or top that depended on math library seem to build just fine. Information about state of libphoenix implementation and compatibility with new headers has been placed in README.
libm/Makefile
Outdated
DEFINITIONS = $(filter-out #define, $(GET_DEFINITIONS)) | ||
|
||
# Setting sizes of floating point types | ||
TARGET_NAME := __SIZEOF_DOUBLE__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't use TARGET
if not related to TARGET architecture/subarch/device
libm/Makefile
Outdated
LIBMCS_WANT_DAZ := n | ||
LIBMCS_WANT_COMPLEX := y | ||
|
||
# Grab builitn definitions from gcc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Grab builitn definitions from gcc | |
# Grab builtin definitions from gcc |
libm/Makefile
Outdated
DOUBLE_SIZE = $(word 2, $(shell echo "$(DEFINITIONS)" | grep -E -o '$(TARGET_NAME)\s+(\w+)')) | ||
|
||
ifeq ($(DOUBLE_SIZE), 8) | ||
CFLAGS += -DLIBMCS_DOUBLE_IS_64BITS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- preprocessor flags should go to
CPPFLAGS
- use double-space (
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure but maybe those tests could simply be a part of our config.h (using preprocessor directly instead of grep
'ing?
libm/Makefile
Outdated
# %LICENSE% | ||
# | ||
LIBMCS_WANT_DAZ := n | ||
LIBMCS_WANT_COMPLEX := y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?=
to be able to change on per-project basis?
libm/Makefile
Outdated
# OBJS += $(addprefix $(PREFIX_O)libm/, $(patsubst %.c,%.o, math/common.c math/trig.c)) | ||
OBJS += $(addprefix $(PREFIX_O), $(patsubst %.c,%.o, $(patsubst %complex.c,, $(wildcard libm/math/*.c)))) | ||
|
||
ifeq ($(LIBMCS_WANT_COMPLEX), y) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LIBMCS_
define impacts non-libmcs build?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is required for compatibility with libmcs headers, name might be changed to LIBM_WANT_COMPLEX
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
externally-configurable variable can have different name, the libmcs-specific one can be local and depend on the external one (with LIBM_
prefix)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably USE_LIBMCS
should also have LIBM_
prefix - and all externally-configurable variables should be described (at the top of the makefile?)
CFLAGS += -DLIBMCS_WANT_COMPLEX | ||
endif | ||
|
||
CFLAGS += -Ilibm/libmcs/libm/include |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if this should be needed.
Please note that you include this file into the main Makefile, so you're passing these options to all files being compiled (polluting CFLAGS)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a major issue? Previously all header files are placed in include/ directory in libphoenix, since in the future this library is supposed to be build as a separate library, could we temporarily keep headers outside the main include directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, we can keep it, please note that when compiling libc these math headers would also be accessible (might be a good thing).
libm/Makefile
Outdated
OBJS += $(addprefix $(PREFIX_O), $(patsubst %.c,%.o,$(wildcard libm/libmcs/libm/mathf/*.c))) | ||
OBJS += $(addprefix $(PREFIX_O), $(patsubst %.c,%.o,$(wildcard libm/libmcs/libm/mathf/internal/*.c))) | ||
OBJS += $(addprefix $(PREFIX_O), $(patsubst %.c,%.o,$(wildcard libm/libmcs/libm/mathd/*.c))) | ||
OBJS += $(addprefix $(PREFIX_O), $(patsubst %.c,%.o,$(wildcard libm/libmcs/libm/mathd/internal/*.c))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uhhh, so it's still being archived into libc.a, not a separate libm.a?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed with @lukileczo and @agkaminski this is beyond scope of this PR, this would require some major changes to libphoenix Makefile, and also would probably cause a breaking change, since -lm flag would have to be added to projects using math library (currently since libm is symlinked to libphoenix this is not required, also as pointed out by @lukileczo there is some issues with installation paths of libraries in current build system)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so please add TODO/FIXME/comment. Leave some written trace for the next developer.
4fd26ca
to
975beef
Compare
another thing - |
975beef
to
d4966e9
Compare
JIRA: RTOS-1132
JIRA: RTOS-1132
9db5dd5
to
28fac68
Compare
JIRA: RTOS-1132
28fac68
to
fae9abe
Compare
Add new implementation of math library (libmcs).
Description
Add new implementation of math library (libmcs), move libphoenix implementation of math library, remove dependency of strtod.c on math library. Current configuration will fail to compile on ia32 because of patches on micropython applied before compilation.
Motivation and Context
Adding complete math library implementation with extensions for critical applications
Types of changes
All projects, that depend on math library should add appropriate flag for linking against new library
How Has This Been Tested?
Checklist:
Special treatment