bfloat16 wip

This commit is contained in:
~d6 2022-01-17 22:52:44 -05:00
parent 9b63c1eb6c
commit 9ab32991ed
1 changed files with 39 additions and 38 deletions

View File

@ -152,18 +152,6 @@
%EXPONENT { #10 SFT2 POP }
%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 )
( normal numbers will be >= #80 )
( subnormal numbers will be < #80 )
@ -175,11 +163,14 @@
@negate-bf16 ( x* -> z* )
#8000 EOR2 JMP2r
@abs-bf16 ( x* -> z* )
#7fff AND2 JMP2r
@is-zero ( x* -> bool^ )
#7fff AND2 #0000 EQU2
#7fff AND2 #0000 EQU2 JMP2r
@non-zero ( x* -> bool^ )
#7fff AND2 #0000 NEQ2
#7fff AND2 #0000 NEQ2 JMP2r
( Shift mantissa m right by n bits, with rounding )
( )
@ -285,16 +276,26 @@
,&x ;non-zero JSR2 ( is x non-zero? )
ORA ,&not-zero JCN #00 JMP2r ( false if x and y are zero )
&not-zero
,&x LDR2 ;sign JSR2 ( sign of x )
,&y LDR2 ;sign JSR2 ( sign of y )
,&x LDR2 SIGN ( sign of x )
,&y LDR2 SIGN ( sign of y )
EQUk ,&same-sign JCN GTH JMP2r ( return unless signs are eq )
[ &x $2 &y $2 ]
&same-sign POP
,&x LDR2 ;exponent JSR2 ( exponent of x )
,&y LDR2 ;exponent JSR2 ( exponent of y )
EQUk ,&exp-eq JCN LTH JMP2r ( return ex < ey unless exps are eq )
&exp-eq POP
,&x LDR2 ;mantissa JSR2 ( mantissa of x )
,&y LDR2 ;exponent JSR2 ( mantissa of y )
LTH JMP2r ( mx < my )
&same-sign
POP ,&is-negative JCN
,&x LDR2 ,&y LDR2 LTH2 JMP2r ( for positives, use integer x < y )
&is-negative
,&x LDR2 ,&y LDR2 GTH2 JMP2r ( for negatives, use integer x > y )
( 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