02-24-2010 07:36 AM
I'm a novice at this kind of stuff, so I'm not sure how to add in compiler flags to the make file and/or linker script. I want to add in the flags to remove unused code as talked about in this thread:
This tells the what, but not the how. So, how to add in these flags to my files if I need to shorten the length of my executable? Which Xilinx files to I need to modify, and how?
02-24-2010 11:45 AM
Are you asking about hardware (logic, VHDL code, verilog code), or software (c code running on a soft, or hard processor)?
In hardware, if the tools see that a wire, gate, or path is never used, then it is ripped out automatically (this is called logic optimization). If the tools rip out something you would like to keep, then there are 'keep' and 'save' directives you may add to your design (to prevent the optimization). For example, a ring oscillator of seven inverters connected in a loop, will be optimized to a single inverter, with input to output, and then removed as "stupid" by the tools ... so if you really want a ring oscillator, you may have to use directives, or the trick of chaining nand gates, and fooling the tools into thinking the circuit is actually doing something by bringing all the other nand inputs out to separate "enables."
In software, the c code is the c code, and if you use the gcc compiler, any optimization done by it is documented elsewhere (it is, just, yet another c compiler -- yacc, and you need to study its specifications, which have little or nothing to do with the FPGA).
Xilinx San Jose
02-25-2010 10:54 AM - edited 02-25-2010 10:57 AM
If you are not entirely comfortable with the compiler/linekr flows, this method of optimizing your code size is not recommended. But here goes:
-ffunction-sections must be added to all your source files when you compile them. -Wl,-gc-sections must be added to your final link command. The former switch tells the compiler to put every function it compiles into it's own section. The latter tells the linker to find unused sections and eliminate them from the final image. Here is a simplified way of compiling things:
mb-gcc -Os file1.c file2.c -o program.elf -ffunction-sections -Wl,-gc-sections <...rest of your compile line goes here>
You did not mention whether you use XPS or SDK. Depending on the tool, there are different ways of adding the switch.
These switches are not used widely across GCC toolchains. I wouldn't bet on the fact that it always works as you would expect. I suggest you look at more basic options for minimizing the size of your executable. Try enabling MicroBlaze features such as barrel shifter/multiplier - they lead to more efficient code. Look at the way your source files are linked and see if there are completely unused modules that are being pulled in because of a stray dependency. Lastly, try bringing down your heap and/or stack size to the minimum required levels.
02-26-2010 08:54 AM
In EDK, right click the software project in the left hand "C/C++ Projects" tab and select properties. Then select "C/C++ Build" from the left-hand side of the pop-up panel that will say "Properties for <your project>." There are tabs and spaces for both the compiler and linker to add compile/link flags as required. Once you change something on this panel, your project with auto-rebuild with these options (provided you have automatic build turned on which is the default).