默认情况下,当使用自定义指令时,浮点常数被编译为在硬件中实施单精度和单精度浮点运算。随着软件中实施双精度和双精度浮点运算,以下变通办法将强制编译浮点常量。
您可以使用以下任一变通方法:
选项 1 - 将 postfix "L" 添加到双精度浮点常数中,修改软件,确保常数不转换为单精度。
下表显示了示例代码和浮点自定义指令硬件的使用、精度以及实施是否在硬件或软件中。
示例代码 | FP CI 用法 | 精度 | 实现 |
b= a * 4.67 | 是的 | 单 | 硬件 |
b = a* 4.67 | 不 | 双 | 软件 |
b = a* 4.67f | 是的 | 单 | 硬件 |
b = a* 4.67f | 不 | 单 | 软件 |
b = a* 4.67L | 不要在意* (Don care*) | 双 | 软件 |
选项 2 -public.mk 中,手动移除 -mcustom-fpu-fpu 配置标志并替换为单个编译器标记,但省略 -fsingle-precision-constant 标志。
"-mcustom-fpu-config=60-1"到"-mcustom-fmuls=252 –mcustom-fadds=253 –mcustom-fsubs=254"或
"-mcustom-fpu-config=60-2"到"-mcustom-fmuls=252 –mcustom-fadds=253 –mcustom-fsubs=254 –mcustom-divs=255"
请注意,60-1 和 60-2 的区别在于 60-1 没有 –mcustom-divs 标志。
有关更多详细信息,请参阅 附录 D http://www.altera.com/literature/ug/ug_nios2_custom_instruction.pdf