Skip to content

RISCV: Backport some upstream changes #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion std/complex.d
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ Complex!(CommonType!(T, U)) fromPolar(T, U)(const T modulus, const U argument)
import std.math.operations : isClose;
import std.math.algebraic : sqrt;
import std.math.constants : PI_4;
auto z = fromPolar(core.math.sqrt(2.0), PI_4);
auto z = fromPolar(core.math.sqrt(2.0L), PI_4);
assert(isClose(z.re, 1.0L));
assert(isClose(z.im, 1.0L));
}
Expand Down
6 changes: 3 additions & 3 deletions std/math/algebraic.d
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,9 @@ if (isFloatingPoint!T)
[ 1.0L, 4.0L, 8.0L, 9.0L ],
[ 4.0L, 4.0L, 7.0L, 9.0L ],
[ 12.0L, 16.0L, 21.0L, 29.0L ],
[ 1e+8L, 1.0L, 1e-8L, 1e+8L ],
[ 1.0L, 1e+8L, 1e-8L, 1e+8L ],
[ 1e-8L, 1.0L, 1e+8L, 1e+8L ],
[ 1e+8L, 1.0L, 1e-8L, 1e+8L+5e-9L ],
[ 1.0L, 1e+8L, 1e-8L, 1e+8L+5e-9L ],
[ 1e-8L, 1.0L, 1e+8L, 1e+8L+5e-9L ],
[ 1e-2L, 1e-4L, 1e-4L, 0.010000999950004999375L ],
[ 2147483647.0L, 2147483647.0L, 2147483647.0L, 3719550785.027307813987L ]
];
Expand Down
52 changes: 26 additions & 26 deletions std/math/hardware.d
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ private:
}
else return sw & EXCEPTIONS_MASK;
}
else version (RISCV_Any)
{
mixin(`
uint result = void;
asm pure nothrow @nogc
{
"frflags %0" : "=r" (result);
}
return result;
`);
}
else version (LDC)
{
version (PPC_Any)
Expand Down Expand Up @@ -188,17 +199,6 @@ private:
{
assert(false, "Not yet supported.");
}
else version (RISCV_Any)
{
mixin(`
uint result = void;
asm pure nothrow @nogc
{
"frflags %0" : "=r" (result);
}
return result;
`);
}
else
assert(0, "Not yet supported");
}
Expand Down Expand Up @@ -648,9 +648,9 @@ nothrow @nogc:
enum : ExceptionMask
{
inexactException = 0x01,
divByZeroException = 0x02,
underflowException = 0x04,
overflowException = 0x08,
divByZeroException = 0x08,
underflowException = 0x02,
overflowException = 0x04,
invalidException = 0x10,
severeExceptions = overflowException | divByZeroException
| invalidException,
Expand Down Expand Up @@ -905,7 +905,18 @@ private:
// Read from the control register
package(std.math) static ControlState getControlState() @trusted pure
{
version (LDC)
version (RISCV_Any)
{
mixin(`
Copy link
Member

Choose a reason for hiding this comment

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

why is a mixin used here?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for your review. I'm not so sure why the previous implementation uses mixin. All I've done is moving this RISCV_Any condition above the LDC condition. It was first committed in dlang@3d84369.

Copy link
Member

Choose a reason for hiding this comment

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

IIRC, that was a problem of the dscanner linter not supporting GDC-style inline asm...

Copy link
Member

Choose a reason for hiding this comment

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

ah ok. Well it's OK. Refactoring is usually better done separately :)

ControlState cont;
asm pure nothrow @nogc
{
"frcsr %0" : "=r" (cont);
}
return cont;
`);
}
else version (LDC)
{
ControlState cont;

Expand Down Expand Up @@ -980,17 +991,6 @@ private:
}
return cont;
}
else version (RISCV_Any)
{
mixin(`
ControlState cont;
asm pure nothrow @nogc
{
"frcsr %0" : "=r" (cont);
}
return cont;
`);
}
else
assert(0, "Not yet supported");
}
Expand Down
46 changes: 23 additions & 23 deletions std/math/trigonometry.d
Original file line number Diff line number Diff line change
Expand Up @@ -485,20 +485,20 @@ private T tanImpl(T)(T x) @safe pure nothrow @nogc
static immutable T[2][] vals =
[
// angle, tan
[ .5, .54630248984],
[ 1, 1.5574077247],
[ 1.5, 14.101419947],
[ 2, -2.1850398633],
[ 2.5,-.74702229724],
[ 3, -.14254654307],
[ 3.5, .37458564016],
[ 4, 1.1578212823],
[ 4.5, 4.6373320546],
[ 5, -3.3805150062],
[ 5.5,-.99558405221],
[ 6, -.29100619138],
[ 6.5, .22027720035],
[ 10, .64836082746],
[ .5, .546302489843790513255L],
[ 1, 1.55740772465490223050L],
[ 1.5, 14.1014199471717193876L],
[ 2, -2.18503986326151899164L],
[ 2.5,-.747022297238660279355L],
[ 3, -.142546543074277805295L],
[ 3.5, .374585640158594666330L],
[ 4, 1.15782128234957758313L],
[ 4.5, 4.63733205455118446831L],
[ 5, -3.38051500624658563698L],
[ 5.5,-.995584052213885017701L],
[ 6, -.291006191384749157053L],
[ 6.5, .220277200345896811825L],
[ 10, .648360827459086671259L],

// special angles
[ PI_4, 1],
Expand Down Expand Up @@ -875,11 +875,11 @@ private T atanImpl(T)(T x) @safe pure nothrow @nogc
static immutable T[2][] vals =
[
// x, atan(x)
[ 0.25, 0.24497866313 ],
[ 0.5, 0.46364760900 ],
[ 1, PI_4 ],
[ 1.5, 0.98279372325 ],
[ 10, 1.47112767430 ],
[ 0.25, 0.244978663126864154172L ],
[ 0.5, 0.463647609000806116214L ],
[ 1, PI_4 ],
[ 1.5, 0.982793723247329067985L ],
[ 10, 1.471127674303734591852L ],
];

foreach (ref val; vals)
Expand Down Expand Up @@ -1093,10 +1093,10 @@ private T atan2Impl(T)(T y, T x) @safe pure nothrow @nogc
[ 3.0, -3.0, 3 * PI_4 ],
[ -4.0, -4.0, -3 * PI_4 ],

[ 0.75, 0.25, 1.249045772398 ],
[ -0.5, 0.375, -0.927295218002 ],
[ 0.5, -0.125, 1.815774989922 ],
[ -0.75, -0.5, -2.158798930342 ],
[ 0.75, 0.25, 1.2490457723982544258299L ],
[ -0.5, 0.375, -0.9272952180016122324285L ],
[ 0.5, -0.125, 1.8157749899217607734034L ],
[ -0.75, -0.5, -2.1587989303424641704769L ],
];

foreach (ref val; vals)
Expand Down
44 changes: 38 additions & 6 deletions std/numeric.d
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ public enum CustomFloatFlags
none = 0
}

private enum isIEEEQuadruple = floatTraits!real.realFormat == RealFormat.ieeeQuadruple;

private template CustomFloatParams(uint bits)
{
enum CustomFloatFlags flags = CustomFloatFlags.ieee
^ ((bits == 80) ? CustomFloatFlags.storeNormalized : CustomFloatFlags.none);
^ ((bits == 80 && !isIEEEQuadruple) ? CustomFloatFlags.storeNormalized : CustomFloatFlags.none);
static if (bits == 8) alias CustomFloatParams = CustomFloatParams!( 4, 3, flags);
static if (bits == 16) alias CustomFloatParams = CustomFloatParams!(10, 5, flags);
static if (bits == 32) alias CustomFloatParams = CustomFloatParams!(23, 8, flags);
Expand Down Expand Up @@ -367,11 +369,36 @@ private:
public:
static if (precision == 64) // CustomFloat!80 support hack
{
ulong significand;
enum ulong significand_max = ulong.max;
mixin(bitfields!(
T_exp , "exponent", exponentWidth,
bool , "sign" , flags & flags.signed ));
static if (isIEEEQuadruple)
{
// Only use highest 64 significand bits from 112 explicitly stored
align (1):
enum ulong significand_max = ulong.max;
version (LittleEndian)
{
private ubyte[6] _padding; // 48-bit of padding
ulong significand;
mixin(bitfields!(
T_exp , "exponent", exponentWidth,
bool , "sign" , flags & flags.signed ));
}
else
{
mixin(bitfields!(
T_exp , "exponent", exponentWidth,
bool , "sign" , flags & flags.signed ));
ulong significand;
private ubyte[6] _padding; // 48-bit of padding
}
}
else
{
ulong significand;
enum ulong significand_max = ulong.max;
mixin(bitfields!(
T_exp , "exponent", exponentWidth,
bool , "sign" , flags & flags.signed ));
}
}
else
{
Expand Down Expand Up @@ -631,23 +658,28 @@ public:
auto x = F(0.125);
assert(x.get!float == 0.125F);
assert(x.get!double == 0.125);
assert(x.get!real == 0.125L);

x -= 0.0625;
assert(x.get!float == 0.0625F);
assert(x.get!double == 0.0625);
assert(x.get!real == 0.0625L);

x *= 2;
assert(x.get!float == 0.125F);
assert(x.get!double == 0.125);
assert(x.get!real == 0.125L);

x /= 4;
assert(x.get!float == 0.03125);
assert(x.get!double == 0.03125);
assert(x.get!real == 0.03125L);

x = 0.5;
x ^^= 4;
assert(x.get!float == 1 / 16.0F);
assert(x.get!double == 1 / 16.0);
assert(x.get!real == 1 / 16.0L);
}
}

Expand Down