Skip to content

Commit 5bd0545

Browse files
authored
Fix get/set_fpcr_aarch64 (JuliaLang#44256)
On Aarch64, the `fpcr` register is 64bit wide, although the top 32bit are currently unused and reserved for future usage. Nevertheless, we should safe and restore the full 64 bit, not just 32 bit. This also silences a compiler warning about this. Reference: <https://developer.arm.com/documentation/ddi0595/2021-06/AArch64-Registers/FPCR--Floating-point-Control-Register>
1 parent f852c88 commit 5bd0545

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/processor_arm.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,20 +1843,20 @@ extern "C" int jl_test_cpu_feature(jl_cpu_feature_t feature)
18431843

18441844
#ifdef _CPU_AARCH64_
18451845
// FPCR FZ, bit [24]
1846-
static constexpr uint32_t fpcr_fz_mask = 1 << 24;
1846+
static constexpr uint64_t fpcr_fz_mask = 1 << 24;
18471847
// FPCR FZ16, bit [19]
1848-
static constexpr uint32_t fpcr_fz16_mask = 1 << 19;
1848+
static constexpr uint64_t fpcr_fz16_mask = 1 << 19;
18491849
// FPCR DN, bit [25]
1850-
static constexpr uint32_t fpcr_dn_mask = 1 << 25;
1850+
static constexpr uint64_t fpcr_dn_mask = 1 << 25;
18511851

1852-
static inline uint32_t get_fpcr_aarch64(void)
1852+
static inline uint64_t get_fpcr_aarch64(void)
18531853
{
1854-
uint32_t fpcr;
1854+
uint64_t fpcr;
18551855
asm volatile("mrs %0, fpcr" : "=r"(fpcr));
18561856
return fpcr;
18571857
}
18581858

1859-
static inline void set_fpcr_aarch64(uint32_t fpcr)
1859+
static inline void set_fpcr_aarch64(uint64_t fpcr)
18601860
{
18611861
asm volatile("msr fpcr, %0" :: "r"(fpcr));
18621862
}
@@ -1868,8 +1868,8 @@ extern "C" JL_DLLEXPORT int32_t jl_get_zero_subnormals(void)
18681868

18691869
extern "C" JL_DLLEXPORT int32_t jl_set_zero_subnormals(int8_t isZero)
18701870
{
1871-
uint32_t fpcr = get_fpcr_aarch64();
1872-
static uint32_t mask = fpcr_fz_mask | (jl_test_cpu_feature(JL_AArch64_fullfp16) ? fpcr_fz16_mask : 0);
1871+
uint64_t fpcr = get_fpcr_aarch64();
1872+
static uint64_t mask = fpcr_fz_mask | (jl_test_cpu_feature(JL_AArch64_fullfp16) ? fpcr_fz16_mask : 0);
18731873
fpcr = isZero ? (fpcr | mask) : (fpcr & ~mask);
18741874
set_fpcr_aarch64(fpcr);
18751875
return 0;
@@ -1882,7 +1882,7 @@ extern "C" JL_DLLEXPORT int32_t jl_get_default_nans(void)
18821882

18831883
extern "C" JL_DLLEXPORT int32_t jl_set_default_nans(int8_t isDefault)
18841884
{
1885-
uint32_t fpcr = get_fpcr_aarch64();
1885+
uint64_t fpcr = get_fpcr_aarch64();
18861886
fpcr = isDefault ? (fpcr | fpcr_dn_mask) : (fpcr & ~fpcr_dn_mask);
18871887
set_fpcr_aarch64(fpcr);
18881888
return 0;

0 commit comments

Comments
 (0)