Q about code generation for Cortex M3

Asked by Harjit Singh

I'm using GCC ARM Embedded 4.7-2013-q1-update and have -O3 turned on.

I've selected the ARM v7M architecture and set the core type to Cortex-M3.

I have variables that are 8 bit, 16 bit and 32 bit and I was looking to see how values are converted and saw the following which seemed not quite optimal.

Here is the code snippet and associated output. I don't understand why the uxth/uxtb instructions are there. If my understanding of the instruction set is correct, the load instructions sign extend on load.

Thanks.

volatile unsigned int vuiFoo;
volatile unsigned short vuwFoo;
volatile unsigned char vucFoo;

vuiFoo = vuwFoo;
    F8BD8008 ldrh.w r8, [sp, #8]
    FA1FF288 uxth r2, r8
    9200 str r2, [sp]

vuwFoo = vuiFoo;
    9F00 ldr r7, [sp]
    B2BE uxth r6, r7
    F8AD6008 strh.w r6, [sp, #8]

vuiFoo = vucFoo;
    F89D500B ldrb.w r5, [sp, #11]

vuiFoo = vucFoo;
    9500 str r5, [sp]

vucFoo = vuiFoo;
    9C00 ldr r4, [sp]
    B2E1 uxtb r1, r4
    F88D100B strb.w r1, [sp, #11]

Question information

Language:
English Edit question
Status:
Answered
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
chengbin (can-finner) said :
#1

> Here is the code snippet and associated output. I don't understand why the uxth/uxtb
> instructions are there. If my understanding of the instruction set is correct, the load
> instructions sign extend on load.

By this, do you mean ZERO extend?

Though I am not very sure, this might be the redundant sign/zero extend problem of GCC.
If I am right, there are patches pending review that fixes the problem.
See,
http://gcc.gnu.org/ml/gcc-patches/2013-06/msg00922.html
and
http://gcc.gnu.org/ml/gcc-patches/2013-06/msg00923.html

Revision history for this message
Harjit Singh (zeetahhs) said :
#2

This seems like a possible soln. I'd have to see output code to be sure.

How does something like this get propagated to gcc and which version would it show up in?

Thanks.

Revision history for this message
Joey Ye (jinyun-ye) said :
#3

There is no guarantee when a patch can be approved. GCC ARM Embedded 4.8 can include the patch if it is in mainline no late than Oct this year.

Thanks,
Joey

Can you help with this problem?

Provide an answer of your own, or ask Harjit Singh for more information if necessary.

To post a message you must log in.