关于Xilinx FPGA的技术经验
Nov
24
[FPU种类]
MicroBlaze FPU - MB内置,单精度,加减乘除开方比较转换
V4 PPC APU_FPU - PPC APU接口,单精度,加减乘除开方比较转换
V5 PPC APU_FPU_VIRTEX5 - PPC APU接口,单/双精度,加减乘除开方移位绝对值比较转换
[问题]
1. 怎样使用FPU
- 在硬件加入了FPU之后,EDK会给Compiler添加一些用于FPU的开关。这些开关不用用户手动添加,但是如果发现工具没有自动添加,用户也可以手动指定
一些可能用到的开关有:
-mno-xl-soft-mul
-mxl-multiply-high
-mhard-float
-mxl-float-sqrt
-mxl-float-convert
参考AR31770
2. C语言的标准函数库都是为双精度小数写的,用了sqrt()函数还是没有用到FPU
- 如果要使用单精度的FPU,需要使用单精度的函数
- sqrtf()函数就是sqrt()的单精度版,fabsf()是fabs()的单精度版,但是不是标准C
- #include
参考apu_fpu_virtex5 datasheet --> Runtime library functions
3. 怎么检查编译出来的结果有没有使用FPU?
- mb-objdump -S executable.elf > dump
- 在dump文件中查找相应的指令,比如fsqrt。其他指令参考datasheet
4. 为什么我看到dump中使用了fsqrt但是也包含了的软件函数,整个函数大概有7K长?
- 当输入了硬件FPU不能处理的输入数据,比如负数之后,软件的sqrtf函数会继续运算和报错。
- 如果确定所有的输入都是合法的,可以用-ffast-math开关把这些代码去掉
5. 如果是加减乘除,需要用特别的函数吗?
- 对于加减乘除来说不需要使用特殊的函数,应该是由于这些符号都是可重入的。
- 注意给的参数一定要使用单精度的,如果是常数比如定义 a = 16.0f; b = a/4.1f; 或 b = a/(float)4.1;
[Reference]
Xilinx Answer Records
CR478364
MicroBlaze FPU - MB内置,单精度,加减乘除开方比较转换
V4 PPC APU_FPU - PPC APU接口,单精度,加减乘除开方比较转换
V5 PPC APU_FPU_VIRTEX5 - PPC APU接口,单/双精度,加减乘除开方移位绝对值比较转换
[问题]
1. 怎样使用FPU
- 在硬件加入了FPU之后,EDK会给Compiler添加一些用于FPU的开关。这些开关不用用户手动添加,但是如果发现工具没有自动添加,用户也可以手动指定
一些可能用到的开关有:
-mno-xl-soft-mul
-mxl-multiply-high
-mhard-float
-mxl-float-sqrt
-mxl-float-convert
参考AR31770
2. C语言的标准函数库都是为双精度小数写的,用了sqrt()函数还是没有用到FPU
- 如果要使用单精度的FPU,需要使用单精度的函数
- sqrtf()函数就是sqrt()的单精度版,fabsf()是fabs()的单精度版,但是不是标准C
- #include
参考apu_fpu_virtex5 datasheet --> Runtime library functions
3. 怎么检查编译出来的结果有没有使用FPU?
- mb-objdump -S executable.elf > dump
- 在dump文件中查找相应的指令,比如fsqrt。其他指令参考datasheet
4. 为什么我看到dump中使用了fsqrt但是也包含了
- 当输入了硬件FPU不能处理的输入数据,比如负数之后,软件的sqrtf函数会继续运算和报错。
- 如果确定所有的输入都是合法的,可以用-ffast-math开关把这些代码去掉
5. 如果是加减乘除,需要用特别的函数吗?
- 对于加减乘除来说不需要使用特殊的函数,应该是由于这些符号都是可重入的。
- 注意给的参数一定要使用单精度的,如果是常数比如定义 a = 16.0f; b = a/4.1f; 或 b = a/(float)4.1;
[Reference]
Xilinx Answer Records
CR478364
Nov
11
[问题] 当一个大程序中,有一些函数从来没有被调用过,用GCC编译仍然会把他们保留在最终的输出elf中。怎样去除这些没有被调用过的函数呢?
[Question] Sometimes some functions are never used in one program, but gcc will retain them in the produced elf file even with -O2 option. How to remove these dead code?
[GCC Doc]
[解决]
XPS --> Software --> Software Platform Settings --> Software Platform --> extra_compiler_flags = -g -ffunction-sections -fdata-sections
Project --> Right Click --> Set Compiler Settings --> Paths and options --> Other compiler options to append --> -ffunction-sections -fdata-sections -Wl,--gc-sections
[注意]
如果是一个有interrupt的系统,用了以上方法会导致interrupt vector和interrupt handler也被remove掉。
暂时没有解决办法。
[Ref]
http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gnat_ugn_u...
[Question] Sometimes some functions are never used in one program, but gcc will retain them in the produced elf file even with -O2 option. How to remove these dead code?
[GCC Doc]
引用
In order to do this, it has to work with objects compiled with the following options: -ffunction-sections -fdata-sections. These options are usable with C and Ada files. They will place respectively each function or data in a separate section in the resulting object file.
Once the objects and static libraries are created with these options, the linker can perform the dead code elimination. You can do this by setting the -Wl,--gc-sections option to gcc command or in the -largs section of gnatmake. This will perform a garbage collection of code and data never referenced.
Once the objects and static libraries are created with these options, the linker can perform the dead code elimination. You can do this by setting the -Wl,--gc-sections option to gcc command or in the -largs section of gnatmake. This will perform a garbage collection of code and data never referenced.
[解决]
XPS --> Software --> Software Platform Settings --> Software Platform --> extra_compiler_flags = -g -ffunction-sections -fdata-sections
Project --> Right Click --> Set Compiler Settings --> Paths and options --> Other compiler options to append --> -ffunction-sections -fdata-sections -Wl,--gc-sections
[注意]
如果是一个有interrupt的系统,用了以上方法会导致interrupt vector和interrupt handler也被remove掉。
暂时没有解决办法。
[Ref]
http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gnat_ugn_u...
Oct
20
设计中经常由于大小端问题等等需要把一个Bus里所有比特的位置倒置一下,使原来bit0, bit1...bitN的顺序改为bitN, bitN-1, bit0.
以下是从xps_spi_2.00.b中截取的一段代码,用于解决这个问题。
spi_module.vhd , Line 541
以下是从xps_spi_2.00.b中截取的一段代码,用于解决这个问题。
spi_module.vhd , Line 541
if (LSB_first = '1') then
for i in 0 to C_NUM_TRANSFER_BITS-1 loop
Receive_Data(i) <= Shift_Reg(C_NUM_TRANSFER_BITS-1-i);
end loop;
else
Receive_Data <= Shift_Reg;
end if;
for i in 0 to C_NUM_TRANSFER_BITS-1 loop
Receive_Data(i) <= Shift_Reg(C_NUM_TRANSFER_BITS-1-i);
end loop;
else
Receive_Data <= Shift_Reg;
end if;
Oct
9
问题:在EDK中为某个Project设置的Optimize Level都只针对这个Project下的C,而Library都默认以-O2编译。这对调试的情况有一些不便。怎样设置让LibGen以-O0编译库?
解决:Platform Settings --> Software Platform --> Microblaze_0 --> extra compiler flags = -g -O0 ".
解决:Platform Settings --> Software Platform --> Microblaze_0 --> extra compiler flags = -g -O0 ".
Oct
8
http://www.escet.urjc.es/~phuerta/SMP_project.htm
引用
The system can be used as an example of how to build SMP systems on
FPGA and how to write applications for it.
In the software side, a modified version of xilkernel I have developed
is used to write multi-threaded applications that run on the SMP
system.
FPGA and how to write applications for it.
In the software side, a modified version of xilkernel I have developed
is used to write multi-threaded applications that run on the SMP
system.






