Allow fixed-point constants to have unsigned range (#1084)

For example with Q.4, $F0 is 15.0, which no longer warns
This commit is contained in:
Rangi
2022-10-01 17:32:34 -04:00
committed by GitHub
parent a1107fc5cf
commit 106ad30e5a
5 changed files with 30 additions and 3 deletions

View File

@@ -1179,7 +1179,7 @@ static uint32_t readFractionalPart(uint32_t integer)
precision = fixPrecision; precision = fixPrecision;
} }
if (integer >= ((uint32_t)1 << (precision - 1))) if (integer >= ((uint64_t)1 << precision))
warning(WARNING_LARGE_CONSTANT, "Magnitude of fixed-point constant is too large\n"); warning(WARNING_LARGE_CONSTANT, "Magnitude of fixed-point constant is too large\n");
// Cast to unsigned avoids undefined overflow behavior // Cast to unsigned avoids undefined overflow behavior

View File

@@ -0,0 +1,13 @@
OPT Q.4
println 1.0
println -1.0
println 0.0625
println -0.0625
println 7.25
println -7.25
println 12.25
println -12.25
println 15.9375
println -15.9375
println 20.0
println -20.0

View File

@@ -0,0 +1,4 @@
warning: fixed-point-magnitude.asm(12): [-Wlarge-constant]
Magnitude of fixed-point constant is too large
warning: fixed-point-magnitude.asm(13): [-Wlarge-constant]
Magnitude of fixed-point constant is too large

View File

@@ -0,0 +1,12 @@
$10
$FFFFFFF0
$1
$FFFFFFFF
$74
$FFFFFF8C
$C4
$FFFFFF3C
$FF
$FFFFFF01
$140
$FFFFFEC0

View File

@@ -1,5 +1,3 @@
warning: opt-Q.asm(10) -> opt-Q.asm::REPT~1(12) -> opt-Q.asm::test(5): [-Wlarge-constant]
Magnitude of fixed-point constant is too large
error: opt-Q.asm(17) -> opt-Q.asm::test(3): error: opt-Q.asm(17) -> opt-Q.asm::test(3):
Argument for option 'Q' must be between 1 and 31 Argument for option 'Q' must be between 1 and 31
error: opt-Q.asm(18) -> opt-Q.asm::test(3): error: opt-Q.asm(18) -> opt-Q.asm::test(3):