Implement opt Q for fixed-point precision, and q literals (e.g. 12.34q8) (#958)

Fixes #957

Co-authored-by: ISSOtm <eldredhabert0@gmail.com>
This commit is contained in:
Rangi
2022-09-04 18:47:32 -04:00
committed by GitHub
parent 889302a9e2
commit 98a6dffbca
20 changed files with 253 additions and 56 deletions

View File

@@ -12,3 +12,11 @@ fl = 6.283185
fr = MUL(20.0, 0.32)
println "32% of 20 = {f:fr} (~{.2f:fr}) (~~{.0f:fr})"
q8 = 1.25q8
q16 = 1.25Q16
q24 = 1.25q.24
println "Q8 ${x:q8} Q16 ${x:q16} Q24 ${x:q24}"
qerr = 1.25q32
println qerr

View File

@@ -0,0 +1,3 @@
error: fixed-point-precision.asm(21):
Fixed-point constant precision must be between 1 and 31
error: Assembly aborted (1 error)!

View File

@@ -4,3 +4,5 @@
`16.12`: 16.119995 -> $00101eb8
`6.283185`: 6.283188 -> $0006487f
32% of 20 = 6.40015 (~6.40) (~~6)
Q8 $140 Q16 $14000 Q24 $1400000
$14000

18
test/asm/opt-Q.asm Normal file
View File

@@ -0,0 +1,18 @@
MACRO test
PUSHO
OPT Q\1
print STRFMT("Q%4s", "\1")
def n = 1.14159
println STRFMT(" -> %032b", n)
POPO
ENDM
for x, 1, 32
if x < 16
test .{d:x}
else
test {d:x}
endc
endr
test .0 ; error
test 32 ; error

7
test/asm/opt-Q.err Normal file
View File

@@ -0,0 +1,7 @@
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):
Argument for option 'Q' must be between 1 and 31
error: opt-Q.asm(18) -> opt-Q.asm::test(3):
Argument for option 'Q' must be between 1 and 31
error: Assembly aborted (2 errors)!

33
test/asm/opt-Q.out Normal file
View File

@@ -0,0 +1,33 @@
Q .1 -> 00000000000000000000000000000010
Q .2 -> 00000000000000000000000000000101
Q .3 -> 00000000000000000000000000001001
Q .4 -> 00000000000000000000000000010010
Q .5 -> 00000000000000000000000000100101
Q .6 -> 00000000000000000000000001001001
Q .7 -> 00000000000000000000000010010010
Q .8 -> 00000000000000000000000100100100
Q .9 -> 00000000000000000000001001001000
Q .10 -> 00000000000000000000010010010001
Q .11 -> 00000000000000000000100100100010
Q .12 -> 00000000000000000001001001000100
Q .13 -> 00000000000000000010010010001000
Q .14 -> 00000000000000000100100100010000
Q .15 -> 00000000000000001001001000100000
Q 16 -> 00000000000000010010010000111111
Q 17 -> 00000000000000100100100001111110
Q 18 -> 00000000000001001001000011111101
Q 19 -> 00000000000010010010000111111010
Q 20 -> 00000000000100100100001111110100
Q 21 -> 00000000001001001000011111101000
Q 22 -> 00000000010010010000111111010000
Q 23 -> 00000000100100100001111110011111
Q 24 -> 00000001001001000011111100111110
Q 25 -> 00000010010010000111111001111100
Q 26 -> 00000100100100001111110011111000
Q 27 -> 00001001001000011111100111110000
Q 28 -> 00010010010000111111001111100000
Q 29 -> 00100100100001111110011111000000
Q 30 -> 01001001000011111100111110000001
Q 31 -> 10010010000111111001111100000010
Q .0 -> 00000000000000010010010000111111
Q 32 -> 00000000000000010010010000111111

View File

@@ -3,11 +3,13 @@ SECTION "test", ROM0
opt !h, !L ; already the default, but tests parsing "!"
pusho
opt p42, h, L, Wno-div
opt p42, Q.4, h, L, Wno-div
ds 1
ld [$ff88], a
halt
println $8000_0000 / -1
def n = 3.14
println "{x:n} = {f:n}"
popo
opt H, l
@@ -16,3 +18,5 @@ popo
ld [$ff88], a
halt
println $8000_0000 / -1
def n = 3.14
println "{x:n} = {f:n}"

View File

@@ -1,2 +1,2 @@
warning: opt.asm(18): [-Wdiv]
warning: opt.asm(20): [-Wdiv]
Division of -2147483648 by -1 yields -2147483648

View File

@@ -1,2 +1,4 @@
$80000000
32 = 3.12500
$80000000
323d7 = 3.14000