From: Jesse DeGuire <jesse.a.deguire@gmail.com>
To: musl@lists.openwall.com
Subject: [musl] [PATCH] Add additional __ARM_FP checks to ARM FPU math functions
Date: Wed, 20 Nov 2024 20:26:23 -0600 [thread overview]
Message-ID: <CALqyXLj9kKBm+QvVNs8_DgH-8NvdBHfdPDN4ZDSFhjCTktxHMA@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1103 bytes --]
Hi everyone!
I found that I was getting compiler errors when I try to build Musl
for an ARMv8.1M Mainline target that does not have floating-point
support but does have the M-Profile Vector Extensions (MVE). The
errors were that Musl wanted to use unsupported floating-point
instructions for fabsf() and sqrtf().
I was able to correct this by adding checks for (__ARM_FP & 4) to the
ARM "fabsf.c" and "sqrtf.c" files, which is all this tiny patch does.
The relevant options I used with Clang were "-march=armv8.1m.main+mve
-mfpu=none -mfloat-abi=hard". MVE uses the FP register file, but
treats them as 8 128-bit registers instead of 16 64-bit registers, so
presumably that's why the hard float ABI is used even when
floating-point operations are not enabled. In this case, an
integer-only subset of MVE is used.
Here is a Godbolt link that shows that you can make this happen on GCC, too.
https://www.godbolt.org/z/Mf4h489s8
I'm not sure if this is totally necessary since I suspect this would
affect only ARM M-Profile devices, but maybe it at least wouldn't hurt
to have.
Thanks,
Jesse DeGuire
[-- Attachment #2: arm_fp_check.patch --]
[-- Type: application/octet-stream, Size: 664 bytes --]
diff --git a/src/math/arm/fabsf.c b/src/math/arm/fabsf.c
index 4a217c98..790d4cfe 100644
--- a/src/math/arm/fabsf.c
+++ b/src/math/arm/fabsf.c
@@ -1,6 +1,6 @@
#include <math.h>
-#if __ARM_PCS_VFP && !BROKEN_VFP_ASM
+#if __ARM_PCS_VFP && !BROKEN_VFP_ASM && (__ARM_FP&4)
float fabsf(float x)
{
diff --git a/src/math/arm/sqrtf.c b/src/math/arm/sqrtf.c
index 32693293..51f44f8c 100644
--- a/src/math/arm/sqrtf.c
+++ b/src/math/arm/sqrtf.c
@@ -1,6 +1,6 @@
#include <math.h>
-#if (__ARM_PCS_VFP || (__VFP_FP__ && !__SOFTFP__)) && !BROKEN_VFP_ASM
+#if (__ARM_PCS_VFP || (__VFP_FP__ && !__SOFTFP__)) && !BROKEN_VFP_ASM && (__ARM_FP&4)
float sqrtf(float x)
{
reply other threads:[~2024-11-21 2:26 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CALqyXLj9kKBm+QvVNs8_DgH-8NvdBHfdPDN4ZDSFhjCTktxHMA@mail.gmail.com \
--to=jesse.a.deguire@gmail.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).