Bug 108642 - ACLE function __arm_wsr missing for AArch64
Summary: ACLE function __arm_wsr missing for AArch64
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 12.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-02-02 16:57 UTC by David Spickett
Modified: 2023-02-03 16:25 UTC (History)
0 users

See Also:
Host:
Target: aarch64-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-02-02 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Spickett 2023-02-02 16:57:40 UTC
This was found by a user trying to compile llvm's libc (which is largely written in c++) using g++ 8.5.0 for AArch64. I then tried versions up to 12.2.0 and a recent trunk build.

https://godbolt.org/z/qxaYxdTcv, and I've copied the details below.

The following source:
```
#include <stdint.h>
#include <arm_acle.h>

void writeStatusWord(uint32_t fpsr) { __arm_wsr("fpsr", fpsr); }
```

When compiled with g++ gives the error:
```
<source>:4:39: error: '__arm_wsr' was not declared in this scope
    4 | void writeStatusWord(uint32_t fpsr) { __arm_wsr("fpsr", fpsr); }
      |                                       ^~~~~~~~~
```

When compiled as C, there is instead a warning and it does compile:
```
<source>:4:39: warning: implicit declaration of function '__arm_wsr' [-Wimplicit-function-declaration]
    4 | void writeStatusWord(uint32_t fpsr) { __arm_wsr("fpsr", fpsr); }
      |                                       ^~~~~~~~~
```

The expected result would be that in either mode, we can compile without errors or warnings.

This __arm_wsr function should be present after including arm_acle.h according to https://github.com/ARM-software/acle/releases/tag/r2022Q4 (acle-2022Q4.pdf
). See "11.1 Special register intrinsics".

I looked in the arm_acle.h gcc/g++ is including and see no reference to it. Which makes me wonder if it's a compiler builtin that somehow isn't present for C++.

Over in clang there is a builtin for it, that is then #defined into the __arm_wsr name in the header.
Comment 1 Andrew Pinski 2023-02-02 17:04:18 UTC
They are not implemented at all for either C or C++.

Confirmed.
Comment 2 Andrew Pinski 2023-02-02 17:06:28 UTC
Note the ACLE does not require "fpsr" to be supported either only "o0:op1:CRn:CRm:op2" format is listed there ...
Comment 3 Andrew Pinski 2023-02-02 17:07:53 UTC
GCC has a builtin already for getting fpsr already too: __builtin_aarch64_get_fpsr

Which of course is not documented ...
Comment 4 David Spickett 2023-02-02 17:09:02 UTC
Of course, I was just looking at at assembly output in compiler explorer and then locally I didn't link the object. That's why it seemed to work.

Compiling and linking I get:
$ ./bin/aarch64-none-linux-gnu-gcc /tmp/test.c -o /tmp/test.o
/tmp/test.c: In function ‘writeStatusWord’:
/tmp/test.c:4:39: warning: implicit declaration of function ‘__arm_wsr’ [-Wimplicit-function-declaration]
    4 | void writeStatusWord(uint32_t fpsr) { __arm_wsr("fpsr", fpsr); }
      |                                       ^~~~~~~~~
<...>aarch64-none-linux-gnu/bin/ld: /tmp/ccLie8Sh.o: in function `writeStatusWord':
test.c:(.text+0x18): undefined reference to `__arm_wsr'
collect2: error: ld returned 1 exit status

Which makes more sense.
Comment 5 Andrew Pinski 2023-02-02 17:10:38 UTC
(In reply to Andrew Pinski from comment #3)
> Which of course is not documented ...

They are documented but not in a decent way:
https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/AArch64-Built-in-Functions.html#AArch64-Built-in-Functions
Comment 6 David Spickett 2023-02-03 16:25:34 UTC
Thanks for the link, we'll try to use those when we detect g++.