⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fastfloat16_.asm

📁 ADI BF 16位定点DSP的快速浮点仿真的汇编代码
💻 ASM
字号:
.section program;

/****************************************************************************************
fastfloat16 fract16_to_ff16(fract16);
------------------
Input parameters:

R0.L = fract16

Output parameters:

R0.L = ff16.exp
R0.H = ff16.frac
------------------
****************************************************************************************/
_fract16_to_ff16:
.global _fract16_to_ff16;
	r1.l = signbits r0.l; 			// get the number of sign bits
	r2 = -r1 (v);	
	r2.h = ashift r0.l by r1.l; 	// normalize the mantissa	
	r0 = r2;
	  
	rts; 
_fract16_to_ff16.end:

/****************************************************************************************
fract16 ff16_to_fract16(fastfloat16);
------------------
Input parameters:

R0.L = ff16.exp
R0.H = ff16.frac

Output parameters:

R0.L = fract16
------------------
****************************************************************************************/
_ff16_to_fract16:
.global _ff16_to_fract16;
	r0.h = ashift r0.h by r0.l;		// shift the binary point
	r0 >>= 16;
	
	rts; 
_ff16_to_fract16.end:


/*

The add, sub, mult and div functions all use the following parameter conventions

------------------
Input parameters:

R0.L = x.exp
R0.H = x.frac

R1.L = y.exp
R1.H = y.frac

Output parameters:

R0.L = z.exp
R0.H = z.frac
------------------
*/

/****************************************************************************************
fastfloat16 add_ff16(fastfloat16, fastfloat16);
****************************************************************************************/
_add_ff16:
.global _add_ff16;

	r2.l = r0.l - r1.l (ns);		// is Ex > Ey?
	cc = an;						// negative result?
	r2.l = r2.l << 11 (s);			// guarantee shift range [-16,15]
	r2.l = r2.l >>> 11;	
	if !cc jump _add_ff16_1;		// no, shift y
	r0.h = ashift r0.h by r2.l;		// yes, shift x
	jump _add_ff16_2;

_add_ff16_1:
	r2 = -r2 (v);
	r1.h = ashift r1.h by r2.l;		// shift y
	a0 = 0;
	a0.l = r0.l;					// you can't do r1.h = r2.h
	r1.l = a0 (iu);					// so use a0.x as an intermediate storage place
_add_ff16_2:
	r2.l = r0.h + r1.h (ns);		// add fractional parts
	cc = v;							// was there an overflow?
	if cc jump _add_ff16_3;

	// normalize
	r0.l = signbits r2.l;			// get the number of sign bits
	r0.h = ashift r2.l by r0.l;		// normalize the mantissa
	r0.l = r1.l - r0.l (ns);		// adjust the exponent

	rts;

// overflow condition for mantissa addition
_add_ff16_3:
	r0.h = r0.h >>> 1;				// shift the mantissas down
	r1.h = r1.h >>> 1;
	r0.h = r0.h + r1.h (ns);		// add fractional parts

	r2.l = 1;
	r0.l = r1.l + r2.l (ns);		// adjust the exponent

	rts;

_add_ff16.end:

/****************************************************************************************
fastfloat16 sub_ff16(fastfloat16, fastfloat16);
****************************************************************************************/
.global _sub_ff16;
_sub_ff16:

	r2.l = r0.l - r1.l (ns);		// is Ex > Ey?
	cc = an;						// negative result?
	r2.l = r2.l << 11 (s);			// guarantee shift range [-16,15]
	r2.l = r2.l >>> 11;	
	if !cc jump _sub_ff16_1;		// no, shift y
	r0.h = ashift r0.h by r2.l;		// yes, shift x
	jump _sub_ff16_2;

_sub_ff16_1:
	r2 = -r2 (v);
	r1.h = ashift r1.h by r2.l;		// shift y
	a0 = 0;
	a0.l = r0.l;					// you can't do r1.h = r2.h
	r1.l = a0 (iu);					// so use a0.x as an intermediate storage place
_sub_ff16_2:
	r2.l = r0.h - r1.h (ns);		// subtract fractions
	cc = v;							// was there an overflow?
	if cc jump _sub_ff16_3;
	
	// normalize
	r0.l = signbits r2.l;			// get the number of sign bits
	r0.h = ashift r2.l by r0.l;		// normalize the mantissa
	r0.l = r1.l - r0.l (ns);		// adjust the exponent

	rts;

// overflow condition for mantissa subtraction
_sub_ff16_3:
	r0.h = r0.h >>> 1;				// shift the mantissas down
	r1.h = r1.h >>> 1;
	r0.h = r0.h - r1.h (ns);		// subtract fractions
	
	r2.l = 1;
	r0.l = r1.l + r2.l (ns);		// adjust the exponent
	
	rts;		

_sub_ff16.end:

/****************************************************************************************
fastfloat16 void mult_ff16(fastfloat16, fastfloat16);
****************************************************************************************/
.global _mult_ff16;
_mult_ff16:

	r3.l = r0.l + r1.l (ns);
	a0 = r0.h * r1.h;
	
	r2.l = signbits a0;				// get the number of sign bits
	a0 = ashift a0 by r2.l;			// normalize the mantissa
	r0 = a0;
	r0.l = r3.l - r2.l (ns);		// adjust the exponent
	
	rts;			
	
_mult_ff16.end:

/****************************************************************************************
fastfloat16 div_ff16(fastfloat16, fastfloat16);
****************************************************************************************/
.global _div_ff16;
_div_ff16:

	// NOTE: fastfloat16 division may or may not be implemented
	rts;	
_div_ff16.end:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -