Skip to content

Commit aa963e9

Browse files
authored
std/math/hardware.d: Partial IeeeFlags implementation on SPARC (#10958)
There's currently no SPARC implementation of `IeeeFlags`. This patch provides the part that is shared between Phobos and GCC's `libphobos`. Besides, Solaris/SPARC uses hardware-incompatible floating-point status flags, which are included, too. The remainder of the implementation (GDC-only) can be found in PR d/123202 libphobos.phobos/std_math_hardware.d FAILs on SPARC https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123202 Together they fix: libphobos.phobos/std_math_hardware.d (test for excess errors) libphobos.phobos/std_math_hardware.d execution test Tested on GCC trunk on sparc-sun-solaris2.11 and sparc64-unknown-linux-gnu.
1 parent ffb285c commit aa963e9

1 file changed

Lines changed: 33 additions & 5 deletions

File tree

std/math/hardware.d

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ else version (RISCV_Any) version = IeeeFlagsSupport;
6060
else version (MIPS_Any) version = IeeeFlagsSupport;
6161
else version (LoongArch_Any) version = IeeeFlagsSupport;
6262
else version (ARM_Any) version = IeeeFlagsSupport;
63+
else version (SPARC_Any) version = IeeeFlagsSupport;
6364

6465
// Struct FloatingPointControl is only available if hardware FP units are available.
6566
version (D_HardFloat)
@@ -87,7 +88,7 @@ private:
8788
// The x87 FPU status register is 16 bits.
8889
// The Pentium SSE2 status register is 32 bits.
8990
// The ARM and PowerPC FPSCR is a 32-bit register.
90-
// The SPARC FSR is a 32bit register (64 bits for SPARC 7 & 8, but high bits are uninteresting).
91+
// The SPARC FSR is a 32-bit register (64 bits for SPARC V9, but high bits are uninteresting).
9192
// The RISC-V (32 & 64 bit) fcsr is 32-bit register.
9293
// THe LoongArch fcsr (fcsr0) is a 32-bit register.
9394
uint flags;
@@ -112,8 +113,21 @@ private:
112113
else version (Solaris)
113114
{
114115
// Solaris <fenv.h> uses hardware-incompatible floating-point status flags.
116+
// Use the <sys/fsr.h> AEXC (Accrued EXCeption) bit field of fsr instead.
117+
version (SPARC_Any)
118+
{
119+
enum : int
120+
{
121+
INEXACT_MASK = 0x020,
122+
UNDERFLOW_MASK = 0x080,
123+
OVERFLOW_MASK = 0x100,
124+
DIVBYZERO_MASK = 0x040,
125+
INVALID_MASK = 0x200,
126+
EXCEPTIONS_MASK = 0x3E0,
127+
}
128+
}
115129
// Use the <sys/fp.h> masks for 80387 control word or SSE/SSE2 MXCSR instead.
116-
version (X86_Any)
130+
else version (X86_Any)
117131
{
118132
enum : int
119133
{
@@ -524,9 +538,21 @@ nothrow @nogc:
524538
else version (Solaris)
525539
{
526540
// Solaris <fenv.h> uses hardware-incompatible floating-point status flags.
541+
// Use the <sys/fsr.h> RD (Rounding Direction) field of fsr instead.
542+
version (SPARC_Any)
543+
{
544+
enum : RoundingMode
545+
{
546+
roundToNearest = 0x00000000,
547+
roundDown = 0xC0000000,
548+
roundUp = 0x80000000,
549+
roundToZero = 0x40000000,
550+
roundingMask = roundToNearest | roundDown
551+
| roundUp | roundToZero,
552+
}
553+
}
527554
// Use the <sys/fp.h> rounding options in control word instead.
528-
529-
version (X86_Any)
555+
else version (X86_Any)
530556
{
531557
enum : RoundingMode
532558
{
@@ -767,6 +793,8 @@ nothrow @nogc:
767793
return true;
768794
else version (LoongArch_Any)
769795
return true;
796+
else version (SPARC_Any)
797+
return true;
770798
else version (ARM_Any)
771799
{
772800
// The hasExceptionTraps_impl function is basically pure,
@@ -850,7 +878,7 @@ private:
850878
}
851879
else version (SPARC_Any)
852880
{
853-
alias ControlState = ulong;
881+
alias ControlState = uint;
854882
}
855883
else version (IBMZ_Any)
856884
{

0 commit comments

Comments
 (0)