> On 8/9/2013 4:32 AM, Kyrylo Tkachov wrote: > >> Hi, > >> I wanted to understand the difference of using march vs mcpu as > argument > >> to gcc. > >> I am compiling my code for a cortex-A8 CPU, what would be better to > use: > >> > >> -mcpu=cortex-a8 or -march=armv7-a > > -mcpu=cortex-a8 will perform specific optimisations for the Cortex-A8 > such as > > instruction scheduling and will produce better performing code on that > core. > > -march=armv7-a just selects the ARMv7-a architecture which tells the > compiler > > that it can use the instructions in ARMv7-a, but it will not perform > any > > core-specific performance tuning. > > > > If you know that you'll be running your code on a Cortex-A8 you should > specify > > -mcpu=cortex-a8, it also automatically implies -march=armv7-a. > > > > For more information on the options available for ARM you can look at: > > http://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html > > > > HTH, > > Kyrill > > > >> Thanks, > >> Channa > Hi Kyrill, > Thanks for the info. > > Yes thats understood, but my concern is with respect to differences in > instructions when the code is compiled. For eg: if I use armv7-a as - > march & my cpu is cortex-a5 would it be possible that the code would > compile fine but might give undefined instruction at some point if the > compiler generated code has some instruction which is not supported on > cortex-a5? march=armv7-a will generate code that will run fine on all cores implementing ARMv7-a. Cortex-A5 is an ARMv7-a core, so with -march=armv7-a the code should not produce any undefined instruction exceptions on it. That being said, keep in mind that there is also the -mfpu option that controls the floating point/SIMD instructions that can be generated. If, for example, you compile with -mfpu=neon-vfpv4 but the core you're running on does not have a NEON unit, then you would get an exception if your code contained any NEON instructions. Note that the neither the -mcpu or -march options automatically set -mfpu, that's something that you have to set yourself. Kyrill