Track GCC PR http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43721
Once this bug is fixed, code size of CINT2000/252.eon/src/myrand.cc:myrand() can be reduced to some extent.
GCC FSF turnk (20100802) generates code like this,
0000000c <_Z7my_randv>:
c: b570 push {r4, r5, r6, lr}
e: 4c0d ldr r4, [pc, #52] ; (44 <_Z7my_randv+0x38>)
10: 490d ldr r1, [pc, #52] ; (48 <_Z7my_randv+0x3c>)
12: 6825 ldr r5, [r4, #0]
14: 4e0d ldr r6, [pc, #52] ; (4c <_Z7my_randv+0x40>)
16: 4628 mov r0, r5
18: f7ff fffe bl 0 <__aeabi_idiv>
1c: 4346 muls r6, r0
1e: 490a ldr r1, [pc, #40] ; (48 <_Z7my_randv+0x3c>)
20: 4628 mov r0, r5
22: f7ff fffe bl 0 <__aeabi_idivmod>
26: f244 13a7 movw r3, #16807 ; 0x41a7
2a: fb03 6601 mla r6, r3, r1, r6
2e: 2e00 cmp r6, #0
30: bfdc itt le
32: f106 4600 addle.w r6, r6, #2147483648 ; 0x80000000
36: 3e01 suble r6, #1
38: 6026 str r6, [r4, #0]
3a: 6820 ldr r0, [r4, #0]
3c: f3c0 200e ubfx r0, r0, #8, #15
40: bd70 pop {r4, r5, r6, pc}
42: bf00 nop
Once bug is fixed, code can be better,
00000006 <_Z7my_randv>:
6: b510 push {r4, lr}
8: 4c0a ldr r4, [pc, #40] ; (34 <_Z7my_randv+0x2e>)
a: 490b ldr r1, [pc, #44] ; (38 <_Z7my_randv+0x32>)
c: 6820 ldr r0, [r4, #0]
e: f7ff fffe bl 0 <__aeabi_idivmod>
12: f244 12a7 movw r2, #16807 ; 0x41a7
16: 4351 muls r1, r2
18: f46f 7231 mvn.w r2, #708 ; 0x2c4
1c: 4350 muls r0, r2
1e: eb01 0080 add.w r0, r1, r0, lsl #2
22: 2800 cmp r0, #0
24: dc02 bgt.n 2c <_Z7my_randv+0x26>
26: f06f 4100 mvn.w r1, #2147483648 ; 0x80000000
2a: 4408 add r0, r1
2c: 6020 str r0, [r4, #0]
2e: f3c0 200e ubfx r0, r0, #8, #15
32: bd10 pop {r4, pc}
Still the case with 4.5.
> arm-none- linux-gnueabi- gcc -Os -S divmod.c stack," ",%progbits
> cat divmod.s
.cpu arm10tdmi
.fpu softvfp
.eabi_attribute 20, 1
.eabi_attribute 21, 1
.eabi_attribute 23, 3
.eabi_attribute 24, 1
.eabi_attribute 25, 1
.eabi_attribute 26, 2
.eabi_attribute 30, 4
.eabi_attribute 18, 4
.file "divmod.c"
.global __aeabi_idivmod
.global __aeabi_idiv
.text
.align 2
.global divmod
.type divmod, %function
divmod:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
stmfd sp!, {r4, r5, r6, lr}
mov r6, r0
mov r5, r1
bl __aeabi_idivmod
mov r0, r6
mov r4, r1
mov r1, r5
bl __aeabi_idiv
add r0, r4, r0
ldmfd sp!, {r4, r5, r6, pc}
.size divmod, .-divmod
.ident "GCC: (GNU) 4.5.0 20100325 (experimental)"
.section .note.GNU-