📄 fastfloat32_.asm
字号:
#include <asm_sprt.h>
.section program;
// NOTE: The "link" instruction was needed to get [FP+20] to point to the right argument
#define FF32_PROLOGUE() link 0; r3 = [fp+20]; [--sp]=r4; [--sp]=r5
#define FF32_EPILOGUE() r5=[sp++]; r4=[sp++]; unlink
/****************************************************************************************
fastfloat32 fract32_to_ff32(fract32);
------------------
Input parameters:
R0 = fract32
Output parameters:
R0.L = ff32.exp
R1 = ff32.frac
------------------
****************************************************************************************/
_fract32_to_ff32:
.global _fract32_to_ff32;
r1.l = signbits r0; // get the number of sign bits
r2 = -r1 (v);
r1 = ashift r0 by r1.l; // normalize the mantissa
r0 = r2;
rts;
_fract32_to_ff32.end:
/****************************************************************************************
fract32 ff32_to_fract32(fastfloat32);
------------------
Input parameters:
R0.L = ff32.exp
R1 = ff32.frac
Output parameters:
R0 = fract32
------------------
****************************************************************************************/
_ff32_to_fract32:
.global _ff32_to_fract32;
r0 = ashift r1 by r0.l; // shift the binary point
rts;
_ff32_to_fract32.end:
/*
The add, sub, mult and div functions all use the following parameter conventions
------------------
Input parameters:
R0.L = x.exp
R1 = x.frac
R2.L = y.exp
R3 = [FP+20] = y.frac
Output parameters:
R0.L = z.exp
R1 = z.frac
------------------
*/
/****************************************************************************************
fastfloat32 add_ff32(fastfloat32, fastfloat32);
****************************************************************************************/
.global _add_ff32;
_add_ff32:
FF32_PROLOGUE();
r4.l = r0.l - r2.l (ns); // is Ex > Ey?
cc = an; // negative result?
r4.l = r4.l << 10 (s); // guarantee shift range [-32,31]
r4.l = r4.l >>> 10;
if !cc jump _add_ff32_1; // no, shift Fy
r1 = ashift r1 by r4.l; // yes, shift Fx
jump _add_ff32_2;
_add_ff32_1:
r4 = -r4 (v);
r3 = ashift r3 by r4.l; // shift Fy
r2 = r0;
_add_ff32_2:
r4 = r1 + r3 (ns); // add fractional parts
cc = v; // was there an overflow?
if cc jump _add_ff32_3;
// normalize
r0.l = signbits r4; // get the number of sign bits
r1 = ashift r4 by r0.l; // normalize the mantissa
r0.l = r2.l - r0.l (ns); // adjust the exponent
FF32_EPILOGUE();
rts;
// overflow condition for mantissa addition
_add_ff32_3:
r1 = r1 >>> 1;
r3 = r3 >>> 1;
r1 = r1 + r3 (ns); // add fractional parts
r4.l = 1;
r0.l = r2.l + r4.l (ns); // adjust the exponent
FF32_EPILOGUE();
rts;
_add_ff32.end:
/****************************************************************************************
fastfloat32 sub_ff32(fastfloat32, fastfloat32);
****************************************************************************************/
.global _sub_ff32;
_sub_ff32:
FF32_PROLOGUE();
r4.l = r0.l - r2.l (ns); // is Ex > Ey?
cc = an; // negative result?
r4.l = r4.l << 10 (s); // guarantee shift range [-32,31]
r4.l = r4.l >>> 10;
if !cc jump _sub_ff32_1; // no, shift Fy
r1 = ashift r1 by r4.l; // yes, shift Fx
jump _sub_ff32_2;
_sub_ff32_1:
r4 = -r4 (v);
r3 = ashift r3 by r4.l; // shift Fy
r2 = r0;
_sub_ff32_2:
r4 = r1 - r3 (ns); // subtract fractions
cc = v; // was there an overflow?
if cc jump _sub_ff32_3;
// normalize
r0.l = signbits r4; // get the number of sign bits
r1 = ashift r4 by r0.l; // normalize the mantissa
r0.l = r2.l - r0.l (ns); // adjust the exponent
FF32_EPILOGUE();
rts;
// overflow condition for mantissa subtraction
_sub_ff32_3:
r1 = r1 >>> 1;
r3 = r3 >>> 1;
r1 = r1 - r3 (ns); // subtract fractions
r4.l = 1;
r0.l = r2.l + r4.l (ns); // adjust the exponent
FF32_EPILOGUE();
rts;
_sub_ff32.end:
/****************************************************************************************
fastfloat32 void mult_ff32(fastfloat32, fastfloat32);
****************************************************************************************/
.global _mult_ff32;
_mult_ff32:
FF32_PROLOGUE();
r0.l = r0.l + r2.l (ns); // add the exponents
// perform 32-bit fractional multiplication
a1 = a0 = 0;
r5 = 0;
r5.l = (a0 = r1.l * r3.l) (fu);
a1 = r5;
r2 = (a0 = r1.h * r3.h), a1 += r1.h * r3.l (m);
r5 = (a1 += r3.h * r1.l) (m);
r5 = r5 >>> 15;
r1 = r2 + r5;
// normalize
r4.l = signbits r1; // get the number of sign bits
r1 = ashift r1 by r4.l; // normalize the mantissa
r0.l = r0.l - r4.l (ns); // adjust the exponent
FF32_EPILOGUE();
rts;
_mult_ff32.end:
/****************************************************************************************
fastfloat32 div_ff32(fastfloat32, fastfloat32);
****************************************************************************************/
.global _div_ff32;
_div_ff32:
// NOTE: fastfloat32 division may or may not be implemented
rts;
_div_ff32.end:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -