Skip to content

libm: Import secondary math library implementation - #507

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

ayoopierre wants to merge 8 commits into
masterfrom
ayopierre/libm

Conversation

@ayoopierre

@ayoopierre ayoopierre commented Jul 21, 2026 •

Copy link
Copy Markdown

Add secondary math libary implementation

Description

Import secondary math library implementation, with selection which version to build (external libmcs implementation/libphoenix implementation) 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

@ayoopierre
ayoopierre requested a review from a team July 21, 2026 09:58
Comment thread libm/arch/aarch64/ceild.c Outdated
*
* %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 Outdated
Comment thread libm/README.md Outdated

# 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

Comment thread libm/phoenix/mathd/sqrtd.c Outdated
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 thread libm/phoenix/mathf/sinhf.c
Comment thread libm/arch/aarch64/truncf.c
Comment thread libm/arch/ia32/sqrtd.c Outdated
Comment thread libm/phoenix/compatibility.c
Comment thread Makefile Outdated
Comment thread libm/README.md Outdated
Comment thread libm/README.md Outdated
@github-actions

github-actions Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

Unit Test Results

13 730 tests  ±0   12 871 ✅ ±0   57m 13s ⏱️ +41s
   780 suites ±0      859 💤 ±0 
     1 files   ±0        0 ❌ ±0 

Results for commit 7df046f. ± Comparison against base commit 9bffcee.

♻️ This comment has been updated with latest results.

Comment thread libm/arch/aarch64/ceild.c Outdated
oI0ck
oI0ck previously requested changes Jul 23, 2026

@oI0ck oI0ck 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.

Please apply the suggested codespell changes

@ayoopierre
ayoopierre force-pushed the ayopierre/libm branch 3 times, most recently from 10d5b21 to 55e5cb1 Compare July 24, 2026 13:37
Comment thread libm/arch/armv8m/sqrtd.c Outdated
@ayoopierre
ayoopierre requested a review from oI0ck July 31, 2026 15:42
Darchiv
Darchiv previously approved these changes Aug 7, 2026

@Darchiv Darchiv 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.

Minor nitpicks. Also please address all typos (those revealed by gemini, in commit messages, etc.), change PR's name to something meaningful, and rerun CI.

Please make it clear in PR's description that you import an external math library (libmcs) as a submodule. ("Adding a new math library implementation" looks a bit too vague and may be misinterpreted.)

Comment thread libm/Makefile Outdated
Comment thread libm/README.md Outdated
@Darchiv
Darchiv requested a review from kber-ps August 7, 2026 17:21
@ayoopierre ayoopierre changed the title Ayopierre/libm libm: Import secondary math library implementiaion Aug 11, 2026
Darchiv
Darchiv previously approved these changes Aug 18, 2026

@Darchiv Darchiv 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.

Not all nitpicks were addressed (typos) but LGTM nonetheless.

Please rerun CI by rebase + force push in order to run cpptest (recently enabled by default on stm32n6)

kber-ps
kber-ps previously approved these changes Aug 24, 2026

@kber-ps kber-ps 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.

LMGT

@ziemleszcz

Copy link
Copy Markdown
Contributor

complex.h header is broken when using libphoenix implementation (default settings from libm/Makefile):

/src/_build/ia32-generic-qemu/sysroot/usr/include/complex.h:21:6: error: #error During the configure step you have chosen not to compile complex procedures as such you should not include complex.h in your software.

Comment thread libm/Makefile Outdated
LIBM_USE_HW ?= y

# Set options for denormals on the FPU
ifeq ($(LIBM_LIBMCS_DAZ), y)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

README.md says it's applicable only for libmcs. Guard it by LIBM_USE_LIBMCS?

@ayoopierre ayoopierre Aug 26, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Suggestion was applied.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it LIBM_LIBMCS_DAZ or LIBMCS_FPU_DAZ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@ayoopierre provide Your response here so we can sloe this

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The LIBM_LIBMCS_DAZ is a build system level flag, while internally macro used in libmcs code is LIBMCS_FPU_DAZ. Wanted to keep all math library configuration flags with LIBM prefix.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LIBM_LIBMCS_DAZ seems to be dead variable.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I guess it is not required to be here. It is used in in top makefile for feature config. I can delete it but it provides default configuration in one place and clearly shows what configuration is possible.

@ayoopierre
ayoopierre dismissed stale reviews from kber-ps and Darchiv via 455ff6d August 26, 2026 15:32
@ayoopierre
ayoopierre force-pushed the ayopierre/libm branch 3 times, most recently from 59e720b to f13ac41 Compare September 25, 2026 11:43
@phoenix-rtos phoenix-rtos deleted a comment from github-actions Bot Sep 25, 2026
@phoenix-rtos phoenix-rtos deleted a comment from github-actions Bot Sep 25, 2026
@phoenix-rtos phoenix-rtos deleted a comment from github-actions Bot Sep 25, 2026
@phoenix-rtos phoenix-rtos deleted a comment from github-actions Bot Sep 25, 2026
@phoenix-rtos phoenix-rtos deleted a comment from github-actions Bot Sep 25, 2026
@phoenix-rtos phoenix-rtos deleted a comment from github-actions Bot Sep 25, 2026
@phoenix-rtos phoenix-rtos deleted a comment from github-actions Bot Sep 25, 2026
@phoenix-rtos phoenix-rtos deleted a comment from github-actions Bot Sep 25, 2026
@phoenix-rtos phoenix-rtos deleted a comment from github-actions Bot Sep 25, 2026
@phoenix-rtos phoenix-rtos deleted a comment from github-actions Bot Sep 25, 2026
@phoenix-rtos phoenix-rtos deleted a comment from github-actions Bot Sep 25, 2026
@phoenix-rtos phoenix-rtos deleted a comment from github-actions Bot Sep 25, 2026
@phoenix-rtos phoenix-rtos deleted a comment from github-actions Bot Sep 25, 2026
@phoenix-rtos phoenix-rtos deleted a comment from github-actions Bot Sep 25, 2026
@phoenix-rtos phoenix-rtos deleted a comment from github-actions Bot Sep 25, 2026
@phoenix-rtos phoenix-rtos deleted a comment from github-actions Bot Sep 25, 2026
@phoenix-rtos phoenix-rtos deleted a comment from github-actions Bot Sep 25, 2026
@phoenix-rtos phoenix-rtos deleted a comment from github-actions Bot Sep 25, 2026
@phoenix-rtos phoenix-rtos deleted a comment from github-actions Bot Sep 25, 2026
@phoenix-rtos phoenix-rtos deleted a comment from github-actions Bot Sep 25, 2026
@phoenix-rtos phoenix-rtos deleted a comment from github-actions Bot Sep 25, 2026
@phoenix-rtos phoenix-rtos deleted a comment from github-actions Bot Sep 25, 2026
@phoenix-rtos phoenix-rtos deleted a comment from github-actions Bot Sep 25, 2026
Comment thread libm/include/complex.h Outdated
Mikołaj Matałowski added 2 commits September 25, 2026 15:43
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.

7 participants