Hardware udiv/sdiv for integer division/modulo
Hi,
It appears that the current ARM GCC (I'm using 4.7 2013q1) does not emit udiv or sdiv instructions for division and modulo when compiling for architectures that support hardware division.
I compiled the following code with -march=armv7-m -mthumb
volatile int test;
int main() {
test = test / 1000;
return test;
}
which results in this assembly listing
int main() {
8000: b480 push {r7}
8002: af00 add r7, sp, #0
test = test / 1000;
8004: f240 4354 movw r3, #1108 ; 0x454
8008: f2c0 0301 movt r3, #1
800c: 681a ldr r2, [r3, #0]
800e: f644 53d3 movw r3, #19923 ; 0x4dd3
8012: f2c1 0362 movt r3, #4194 ; 0x1062
8016: fb83 1302 smull r1, r3, r3, r2
801a: ea4f 11a3 mov.w r1, r3, asr #6
801e: ea4f 73e2 mov.w r3, r2, asr #31
8022: 1aca subs r2, r1, r3
8024: f240 4354 movw r3, #1108 ; 0x454
8028: f2c0 0301 movt r3, #1
802c: 601a str r2, [r3, #0]
return test;
802e: f240 4354 movw r3, #1108 ; 0x454
8032: f2c0 0301 movt r3, #1
8036: 681b ldr r3, [r3, #0]
}
As you can see, the compiler is using software emulation for division, even though ARMv7-M is specified. I have also tried to compile with -mcpu=cortex-m3 -mthumb, -mcpu=cortex-m3 -mthumb, and -march=armv7-r -mthumb, to no avail.
The same problem occurs when using the % operator, as well as directly calling the library division functions (the __aeabi_sidiv called appears to be a soft implementation).
Are udiv and sdiv currently being used by GCC? If so, is there some compiler switch I'm missing to get it to emit these instructions?
Thanks for the help.
Tony Kao
Question information
- Language:
- English Edit question
- Status:
- Solved
- Assignee:
- No assignee Edit question
- Solved by:
- Joey Ye
- Solved:
- Last query:
- Last reply: