bfloat16 wip
This commit is contained in:
parent
9b63c1eb6c
commit
9ab32991ed
75
bfloat16.tal
75
bfloat16.tal
|
@ -152,18 +152,6 @@
|
||||||
%EXPONENT { #10 SFT2 POP }
|
%EXPONENT { #10 SFT2 POP }
|
||||||
%MANTISSA { NIP #7f AND }
|
%MANTISSA { NIP #7f AND }
|
||||||
|
|
||||||
( returns sign: #00 or #01 )
|
|
||||||
@sign ( x* -> sgn^ )
|
|
||||||
SIGN JMP2r
|
|
||||||
|
|
||||||
( returns exp: #00 to #ff )
|
|
||||||
@exponent ( x* -> exp^ )
|
|
||||||
EXPONENT JMP2r
|
|
||||||
|
|
||||||
( returns mta: #00 to #7f )
|
|
||||||
@mantissa ( x* -> mta^ )
|
|
||||||
MANTISSA JMP2r
|
|
||||||
|
|
||||||
( returns full mta: #00 to #ff )
|
( returns full mta: #00 to #ff )
|
||||||
( normal numbers will be >= #80 )
|
( normal numbers will be >= #80 )
|
||||||
( subnormal numbers will be < #80 )
|
( subnormal numbers will be < #80 )
|
||||||
|
@ -175,11 +163,14 @@
|
||||||
@negate-bf16 ( x* -> z* )
|
@negate-bf16 ( x* -> z* )
|
||||||
#8000 EOR2 JMP2r
|
#8000 EOR2 JMP2r
|
||||||
|
|
||||||
|
@abs-bf16 ( x* -> z* )
|
||||||
|
#7fff AND2 JMP2r
|
||||||
|
|
||||||
@is-zero ( x* -> bool^ )
|
@is-zero ( x* -> bool^ )
|
||||||
#7fff AND2 #0000 EQU2
|
#7fff AND2 #0000 EQU2 JMP2r
|
||||||
|
|
||||||
@non-zero ( x* -> bool^ )
|
@non-zero ( x* -> bool^ )
|
||||||
#7fff AND2 #0000 NEQ2
|
#7fff AND2 #0000 NEQ2 JMP2r
|
||||||
|
|
||||||
( Shift mantissa m right by n bits, with rounding )
|
( Shift mantissa m right by n bits, with rounding )
|
||||||
( )
|
( )
|
||||||
|
@ -262,19 +253,19 @@
|
||||||
@ne-bf16 ( x* y* -> bool^ )
|
@ne-bf16 ( x* y* -> bool^ )
|
||||||
;eq-bf16 JSR2 #00 EQU JMP2r
|
;eq-bf16 JSR2 #00 EQU JMP2r
|
||||||
|
|
||||||
( rules for sentinels (in order): )
|
( rules for sentinels (in order): )
|
||||||
( 1. x < x is false )
|
( 1. x < x is false )
|
||||||
( 2a. nan < x is false )
|
( 2a. nan < x is false )
|
||||||
( 2b. x < nan is false )
|
( 2b. x < nan is false )
|
||||||
( 3a. x < +inf is true )
|
( 3a. x < +inf is true )
|
||||||
( 3b. +inf < x is false )
|
( 3b. +inf < x is false )
|
||||||
( 4a. -inf < x is true )
|
( 4a. -inf < x is true )
|
||||||
( 4b. x < -inf is false )
|
( 4b. x < -inf is false )
|
||||||
( 5. -0 < +0 is false )
|
( 5. -0 < +0 is false )
|
||||||
( 6. -x < +x (or 0) )
|
( 6. -x < +x (or 0) )
|
||||||
( 7. 0 < +x )
|
( 7. 0 < +x )
|
||||||
( 8. x*2^p < y*2^q if p < q )
|
( 8. x*2^p < y*2^q if p < q )
|
||||||
( 9. x*2^p < y*2^p if x < y )
|
( 9. x*2^p < y*2^p if x < y )
|
||||||
@lt-bf16 ( x* y* -> bool^ )
|
@lt-bf16 ( x* y* -> bool^ )
|
||||||
,&y STR2 ,&x STR2
|
,&y STR2 ,&x STR2
|
||||||
,&y LDR2 ;non-nan JSR2 ( is y not nan? )
|
,&y LDR2 ;non-nan JSR2 ( is y not nan? )
|
||||||
|
@ -285,16 +276,26 @@
|
||||||
,&x ;non-zero JSR2 ( is x non-zero? )
|
,&x ;non-zero JSR2 ( is x non-zero? )
|
||||||
ORA ,¬-zero JCN #00 JMP2r ( false if x and y are zero )
|
ORA ,¬-zero JCN #00 JMP2r ( false if x and y are zero )
|
||||||
¬-zero
|
¬-zero
|
||||||
,&x LDR2 ;sign JSR2 ( sign of x )
|
,&x LDR2 SIGN ( sign of x )
|
||||||
,&y LDR2 ;sign JSR2 ( sign of y )
|
,&y LDR2 SIGN ( sign of y )
|
||||||
EQUk ,&same-sign JCN GTH JMP2r ( return unless signs are eq )
|
EQUk ,&same-sign JCN GTH JMP2r ( return unless signs are eq )
|
||||||
[ &x $2 &y $2 ]
|
[ &x $2 &y $2 ]
|
||||||
&same-sign POP
|
&same-sign
|
||||||
,&x LDR2 ;exponent JSR2 ( exponent of x )
|
POP ,&is-negative JCN
|
||||||
,&y LDR2 ;exponent JSR2 ( exponent of y )
|
,&x LDR2 ,&y LDR2 LTH2 JMP2r ( for positives, use integer x < y )
|
||||||
EQUk ,&exp-eq JCN LTH JMP2r ( return ex < ey unless exps are eq )
|
&is-negative
|
||||||
&exp-eq POP
|
,&x LDR2 ,&y LDR2 GTH2 JMP2r ( for negatives, use integer x > y )
|
||||||
,&x LDR2 ;mantissa JSR2 ( mantissa of x )
|
|
||||||
,&y LDR2 ;exponent JSR2 ( mantissa of y )
|
|
||||||
LTH JMP2r ( mx < my )
|
|
||||||
|
|
||||||
|
( see lt-bf16; (x < y) = (y < x) )
|
||||||
|
@gt-bf16 ( x* y* -> bool^ )
|
||||||
|
SWP2 ;lt-bf16 JMP2
|
||||||
|
|
||||||
|
( special cases: )
|
||||||
|
( 1. x + y = y + x )
|
||||||
|
( 2. nan + x = nan )
|
||||||
|
( 3. 0 + x = x )
|
||||||
|
( 4. inf + (-inf) = nan )
|
||||||
|
( 5. inf + x = inf )
|
||||||
|
( 6. -inf + x = -inf )
|
||||||
|
@add-bf16 ( x* y* -> z* )
|
||||||
|
JMP2r
|
||||||
|
|
Loading…
Reference in New Issue