浮点运算单元的实现——浮点指令内联汇编(一)
团队编号:CICC1230
团队名称:少吃米饭多吃肉
代码实现
在硬件实现FPU后,可通过内联汇编的方式,指定浮点指令对其进行测试,以下罗列出相关测试代码。
//fmadds_test
__STATIC_FORCEINLINE float fmadds_test(float a,float b,float c)
{
float zero = 0;
asm volatile (
"fmadd.s %0, %1, %2, %3\n\t"
:"=f"(zero)
:"f"(a),"f"(b),"f"(c)
);
return zero;
}
//fmsubs_test
__STATIC_FORCEINLINE float fmsubs_test(float a,float b,float c)
{
float zero = 0;
asm volatile (
"fmsub.s %0, %1, %2, %3\n\t"
:"=f"(zero)
:"f"(a),"f"(b),"f"(c)
);
return zero;
}
//fnmadds_test
__STATIC_FORCEINLINE float fnmadds_test(float a,float b,float c)
{
float zero = 0;
asm volatile (
"fnmadd.s %0, %1, %2, %3\n\t"
:"=f"(zero)
:"f"(a),"f"(b),"f"(c)
);
return zero;
}
//fnmsubs_test
__STATIC_FORCEINLINE float fnmsubs_test(float a,float b,float c)
{
float zero = 0;
asm volatile (
"fnmsub.s %0, %1, %2, %3\n\t"
:"=f"(zero)
:"f"(a),"f"(b),"f"(c)
);
return zero;
}
//fadds_test
__STATIC_FORCEINLINE float fadds_test(float a,float b)
{
float zero = 0;
asm volatile (
"fadd.s %0, %1, %2\n\t"
:"=f"(zero)
:"f"(a),"f"(b)
);
return zero;
}
//fsubs_test
__STATIC_FORCEINLINE float fsubs_test(float a,float b)
{
float zero = 0;
asm volatile (
"fsub.s %0, %1, %2\n\t"
:"=f"(zero)
:"f"(a),"f"(b)
);
return zero;
}
//fmuls_test
__STATIC_FORCEINLINE float fmuls_test(float a,float b)
{
float zero = 0;
asm volatile (
"fmul.s %0, %1, %2\n\t"
:"=f"(zero)
:"f"(a),"f"(b)
);
return zero;
}
//fdivs_test
__STATIC_FORCEINLINE float fdivs_test(float a,float b)
{
float zero = 0;
asm volatile (
"fdiv.s %0, %1, %2\n\t"
:"=f"(zero)
:"f"(a),"f"(b)
);
return zero;
}
//fsqrts_test
__STATIC_FORCEINLINE float fsqrts_test(float a)
{
float zero = 0;
asm volatile (
"fsqrt.s %0, %1\n\t"
:"=f"(zero)
:"f"(a)
);
return zero;
}
//fmins_test
__STATIC_FORCEINLINE float fmins_test(float a,float b)
{
float zero = 0;
asm volatile (
"fmin.s %0, %1, %2\n\t"
:"=f"(zero)
:"f"(a),"f"(b)
);
return zero;
}
//fmaxs_test
__STATIC_FORCEINLINE float fmaxs_test(float a,float b)
{
float zero = 0;
asm volatile (
"fmax.s %0, %1, %2\n\t"
:"=f"(zero)
:"f"(a),"f"(b)
);
return zero;
}