Skip to content

Ayopierre/libm#507

Open
ayoopierre wants to merge 3 commits into
masterfrom
ayopierre/libm
Open

Ayopierre/libm#507
ayoopierre wants to merge 3 commits into
masterfrom
ayopierre/libm

Conversation

@ayoopierre

Copy link
Copy Markdown

Add secondary math libary implementation

Description

Add new math library implementation, with selection which version to build and selection for usage of hw intrinsics for math operations.

Motivation and Context

Libmcs provides complete C99 math library implementation.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: (list targets here).

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

@ayoopierre
ayoopierre requested a review from a team July 21, 2026 09:58
Comment thread libm/arch/aarch64/ceild.c
*
* %LICENSE%
*/

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[clang-format-pr] reported by reviewdog 🐶
suggested fix

Suggested change

Comment thread libm/README.md
For documentation please refer to /docs directory present on the main repo linked above.

# Phoenix
This is implementation of math library developed alongside Pheonix RTOS operating system. Keep in mind that this implementation is not complete, not all functions in C99 standard are implemented.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[codespell] reported by reviewdog 🐶
Pheonix ==> Phoenix

Comment thread libm/README.md

# Notes
1. This is a temporary state, moving math library to be separate to libphoenix
2. Some hardware instrinsics for math functions are still not implemented

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[codespell] reported by reviewdog 🐶
instrinsics ==> intrinsics

init->i.mantisa |= (0x1ull << 51);
}

/* Reciprocal sqare root iters (avoiding division): */

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[codespell] reported by reviewdog 🐶
sqare ==> square

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

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 refactors the math library by moving it from libphoenix to a standalone libm directory, introducing architecture-specific hardware-accelerated implementations alongside a software-based fallback. The review identified several critical issues, including a logic error in sinhf, a function name typo in truncf, a C99 linkage issue with inline functions, a syntax error in nanf, and potential build failures in the Makefile. Additionally, minor typos in the documentation were addressed.

Comment on lines +19 to +22
float sinhf(float x)
{
return (double)sin((double)x);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

The implementation of sinhf incorrectly calls sin (trigonometric sine) instead of sinh (hyperbolic sine). This will return completely incorrect results for hyperbolic sine calculations.

float sinhf(float x)
{
	return (float)sinh((double)x);
}


#include <math.h>


Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The function name is misspelled as trunf instead of truncf. This will cause linker errors or prevent the hardware-accelerated version of truncf from being used.

float truncf(float x)

Comment thread libm/arch/ia32/sqrtd.c Outdated
#include <errno.h>


inline double sqrt(double x)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Defining sqrt as inline in a .c file without static or extern means that under C99 rules, no external symbol is emitted for sqrt. This will cause 'undefined reference to sqrt' errors at link time. The inline keyword should be removed.

double sqrt(double x)

Comment on lines +30 to +33
float nanf(const char *)
{
return __builtin_nanf("");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

In C, omitting the parameter name in a function definition is a syntax error. An identifier must be provided for the parameter, even if it is unused.

Suggested change
float nanf(const char *)
{
return __builtin_nanf("");
}
float nanf(const char *tagp)
{
return __builtin_nanf("");
}

Comment thread Makefile
Comment on lines +89 to +90
cp -a include/* "$(HEADERS_INSTALL_DIR)"; \
cp -a libm/libmcs/libm/include/* "$(HEADERS_INSTALL_DIR)";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

If the libm/libmcs submodule is not checked out or initialized, the directory libm/libmcs/libm/include will not exist, causing the cp -a command to fail and halt the installation. It is safer to conditionally copy the headers only if the directory exists.

	cp -a include/* "$(HEADERS_INSTALL_DIR)"; \
	if [ -d libm/libmcs/libm/include ]; then cp -a libm/libmcs/libm/include/. "$(HEADERS_INSTALL_DIR)"; fi

Comment thread libm/README.md Outdated
@@ -0,0 +1,38 @@
# Libm
This directory contains implementation of math library. It currently links to libphoenix with intention to be compiled to separate libm.a library. There are two implementation for two follo>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The sentence is cut off at the end with follo>. It should be completed (e.g., following implementations:).

Suggested change
This directory contains implementation of math library. It currently links to libphoenix with intention to be compiled to separate libm.a library. There are two implementation for two follo>
This directory contains implementation of math library. It currently links to libphoenix with intention to be compiled to separate libm.a library. There are two implementations for the following cases:

Comment thread libm/README.md
For documentation please refer to /docs directory present on the main repo linked above.

# Phoenix
This is implementation of math library developed alongside Pheonix RTOS operating system. Keep in mind that this implementation is not complete, not all functions in C99 standard are implemented.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Typo: Pheonix should be Phoenix.

Suggested change
This is implementation of math library developed alongside Pheonix RTOS operating system. Keep in mind that this implementation is not complete, not all functions in C99 standard are implemented.
This is implementation of math library developed alongside Phoenix RTOS operating system. Keep in mind that this implementation is not complete, not all functions in C99 standard are implemented.

@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown

Unit Test Results

11 307 tests  ±0   10 583 ✅  - 17   1h 1m 27s ⏱️ + 8m 6s
   690 suites ±0      707 💤 ± 0 
     1 files   ±0       17 ❌ +17 

For more details on these failures, see this check.

Results for commit c948336. ± Comparison against base commit fb3245b.

♻️ This comment has been updated with latest results.

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.

1 participant