Patchwork cortex-m3: adjusted target cflags

login
register
mail settings
Submitter Enrico Scholz
Date Feb. 7, 2011, 3:53 p.m.
Message ID <1297093986-24331-1-git-send-email-enrico.scholz@sigma-chemnitz.de>
Download mbox | patch
Permalink /patch/479/
State Accepted
Delegated to: Khem Raj
Headers show

Comments

Enrico Scholz - Feb. 7, 2011, 3:53 p.m.
Explicit '-mthumb' is required because Cortex-M3 does not support ARM
instructions and actual flags cause gcc to fail with 'error: target CPU
does not support ARM mode'.

The '-mcpu=cortex-m3' is shorter than '-march=armv7-m -mtune=cortex-m3'
and enables workarounds like '-mfix-cortex-m3-ldrd'.

Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
---
 conf/machine/include/tune-cortexm3.inc |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Mark Hatle - Feb. 7, 2011, 7:39 p.m.
On 2/7/11 1:33 PM, Khem Raj wrote:
> On Mon, Feb 7, 2011 at 7:53 AM, Enrico Scholz
> <enrico.scholz@sigma-chemnitz.de> wrote:
>> Explicit '-mthumb' is required because Cortex-M3 does not support ARM
>> instructions and actual flags cause gcc to fail with 'error: target CPU
>> does not support ARM mode'.
>>
>> The '-mcpu=cortex-m3' is shorter than '-march=armv7-m -mtune=cortex-m3'
>> and enables workarounds like '-mfix-cortex-m3-ldrd'.
> 
> Does -mcpu=cortex-m3 also cause gcc to tune for cortex-m3 ?

-mcpu=cortex-m3 is equivalent to -march=cortex-m3 -mtune=cortex-m3

So in this instance, it will have a side effect of potentially changing the
available set of instructions.. The existing command says the only available
instructions are those defined as "armv7-m", but I want to tune the instruction
scheduler for execution on "cortex-m3".

(I'm not an ARM expert, so I'm not sure what is reasonable in this case.. but
the arguments do have slightly different meanings.)

--Mark

>>
>> Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
>> ---
>>  conf/machine/include/tune-cortexm3.inc |    2 +-
>>  1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/conf/machine/include/tune-cortexm3.inc b/conf/machine/include/tune-cortexm3.inc
>> index 6da9aee..a66a33c 100644
>> --- a/conf/machine/include/tune-cortexm3.inc
>> +++ b/conf/machine/include/tune-cortexm3.inc
>> @@ -1,4 +1,4 @@
>>  # valid options for -march: `armv7', `armv7-m'
>> -TARGET_CC_ARCH = "-march=armv7-m -mtune=cortex-m3 -mfpu=vfp -mfloat-abi=softfp"
>> +TARGET_CC_ARCH = "-mthumb -mcpu=cortex-m3 -mfpu=vfp -mfloat-abi=softfp"
>>  FEED_ARCH = "armv7"
>>  BASE_PACKAGE_ARCH = "armv7"
>> --
>> 1.7.4
>>
>>
>> _______________________________________________
>> Openembedded-devel mailing list
>> Openembedded-devel@lists.openembedded.org
>> http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-devel
>>
> 
> _______________________________________________
> Openembedded-devel mailing list
> Openembedded-devel@lists.openembedded.org
> http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-devel
Khem Raj - Feb. 7, 2011, 8:19 p.m.
On Mon, Feb 7, 2011 at 11:39 AM, Mark Hatle <mark.hatle@windriver.com> wrote:
> On 2/7/11 1:33 PM, Khem Raj wrote:
>> On Mon, Feb 7, 2011 at 7:53 AM, Enrico Scholz
>> <enrico.scholz@sigma-chemnitz.de> wrote:
>>> Explicit '-mthumb' is required because Cortex-M3 does not support ARM
>>> instructions and actual flags cause gcc to fail with 'error: target CPU
>>> does not support ARM mode'.
>>>
>>> The '-mcpu=cortex-m3' is shorter than '-march=armv7-m -mtune=cortex-m3'
>>> and enables workarounds like '-mfix-cortex-m3-ldrd'.
>>
>> Does -mcpu=cortex-m3 also cause gcc to tune for cortex-m3 ?
>
> -mcpu=cortex-m3 is equivalent to -march=cortex-m3 -mtune=cortex-m3

is -march=cortex-m3 valid even ? my question was if we select armv7-m
using -march
then gcc knows stuff like oh this arch has a hardware div instruction
but now if we
use -mcpu will it still do it.
Mark Hatle - Feb. 7, 2011, 8:42 p.m.
On 2/7/11 2:19 PM, Khem Raj wrote:
> On Mon, Feb 7, 2011 at 11:39 AM, Mark Hatle <mark.hatle@windriver.com> wrote:
>> On 2/7/11 1:33 PM, Khem Raj wrote:
>>> On Mon, Feb 7, 2011 at 7:53 AM, Enrico Scholz
>>> <enrico.scholz@sigma-chemnitz.de> wrote:
>>>> Explicit '-mthumb' is required because Cortex-M3 does not support ARM
>>>> instructions and actual flags cause gcc to fail with 'error: target CPU
>>>> does not support ARM mode'.
>>>>
>>>> The '-mcpu=cortex-m3' is shorter than '-march=armv7-m -mtune=cortex-m3'
>>>> and enables workarounds like '-mfix-cortex-m3-ldrd'.
>>>
>>> Does -mcpu=cortex-m3 also cause gcc to tune for cortex-m3 ?
>>
>> -mcpu=cortex-m3 is equivalent to -march=cortex-m3 -mtune=cortex-m3
> 
> is -march=cortex-m3 valid even ? my question was if we select armv7-m
> using -march
> then gcc knows stuff like oh this arch has a hardware div instruction
> but now if we
> use -mcpu will it still do it.

You would have to look in the source and see if -mcpu=cortex-m3 is an "alias"
for anything or simply uses the default logic of cpu == march && mtune..

(FYI, last time I looked at how this worked was a year or so ago.. so if the way
GCC processes options has changed, then I'm wrong..  but it's worth looking at..
 I was scolded many times by GCC developers that -mcpu= is not the same as
specifically setting the arch and tune.)

Usually you use march & mtune when you are trying to make a set of binaries that
is capable of running on multiple cores in the same family.  I see it used the
most of IA and Power systems myself.

--Mark
Enrico Scholz - Feb. 7, 2011, 8:59 p.m.
Khem Raj <raj.khem@gmail.com> writes:

>> The '-mcpu=cortex-m3' is shorter than '-march=armv7-m -mtune=cortex-m3'
>> and enables workarounds like '-mfix-cortex-m3-ldrd'.
>
> Does -mcpu=cortex-m3 also cause gcc to tune for cortex-m3 ?

Yes; logic in gcc/config/arm/arm.c is:

|    if (i == ARM_OPT_SET_CPU || i == ARM_OPT_SET_TUNE)
|      arm_tune = (enum processor_type) (sel - ptr->processors);
|
|    if (i == ARM_OPT_SET_ARCH)
|      target_arch_cpu = sel->core;
|
|    if (i == ARM_OPT_SET_CPU)
|      selected_cpu = (enum processor_type) (sel - ptr->processors);

'-mcpu' causes the highest optimization level (both for the used instruction
set (--> '-march') and the "soft" optimizations (--> '-mcpu')).



Enrico
Enrico Scholz - Feb. 7, 2011, 10:27 p.m.
Khem Raj <raj.khem@gmail.com> writes:

> Can you check what does gcc emits in an assembly file when using
> -mcpu=cortex-m3 in your case. If it emits sdiv instruction or not
>
> int foo (long a, long b)
> {
>         return a/b;
> }

$ arm-linux-uclibceabi-gcc -mthumb -mcpu=cortex-m3 -mfpu=vfp -mfloat-abi=softfp -O1 -c x.c
$ arm-linux-uclibceabi-objdump -d x.o
00000000 <foo>:
   0:   fb90 f0f1       sdiv    r0, r0, r1
   4:   4770            bx      lr
   6:   bf00            nop



Enrico

Patch

diff --git a/conf/machine/include/tune-cortexm3.inc b/conf/machine/include/tune-cortexm3.inc
index 6da9aee..a66a33c 100644
--- a/conf/machine/include/tune-cortexm3.inc
+++ b/conf/machine/include/tune-cortexm3.inc
@@ -1,4 +1,4 @@ 
 # valid options for -march: `armv7', `armv7-m'
-TARGET_CC_ARCH = "-march=armv7-m -mtune=cortex-m3 -mfpu=vfp -mfloat-abi=softfp"
+TARGET_CC_ARCH = "-mthumb -mcpu=cortex-m3 -mfpu=vfp -mfloat-abi=softfp"
 FEED_ARCH = "armv7"
 BASE_PACKAGE_ARCH = "armv7"