Improving codegen for ARM Cortex-M

Mike Franklin slavo5150 at yahoo.com
Fri Jul 20 12:49:59 UTC 2018


Actually the assembly output from objdump isn't quite accurate.  
Here's the generated assembly from the compiler.

LDC
---
ldc2 -conf= -disable-simplify-libcalls -c -Os  
-mtriple=thumb-none-eabi -float-abi=hard -mcpu=cortex-m4 
-Isource/runtime -boundscheck=off

_D5board3lcd8fillRectFiikktZv:
	.fnstart
	.save	{r4, r5, r6, r7, r8, r9, lr}
	push.w	{r4, r5, r6, r7, r8, r9, lr}
	add.w	lr, r3, r1
	cmp	lr, r3
	it	lt
	poplt.w	{r4, r5, r6, r7, r8, r9, pc}
	ldr.w	r12, [sp, #28]
	rsb	r5, r3, r3, lsl #4
	movw	r8, :lower16:_D5board4ltdc11frameBufferG76800t
	and	r1, r2, #3
	sub.w	r9, r2, #1
	movt	r8, :upper16:_D5board4ltdc11frameBufferG76800t
	subs	r4, r2, r1
	add.w	r5, r12, r5, lsl #4
	add.w	r5, r8, r5, lsl #1
	adds	r7, r5, #4
.LBB1_1:
	cbz	r2, .LBB1_8
	movs	r5, #0
	cmp.w	r9, #3
	blo	.LBB1_5
	mov	r6, r7
.LBB1_4:
	adds	r5, #4
	strh	r0, [r6, #-2]
	strh	r0, [r6, #-4]
	strh	r0, [r6]
	strh	r0, [r6, #2]
	adds	r6, #8
	cmp	r4, r5
	bne	.LBB1_4
.LBB1_5:
	cbz	r1, .LBB1_8
	rsb	r6, r3, r3, lsl #4
	cmp	r1, #1
	add.w	r6, r12, r6, lsl #4
	add	r5, r6
	strh.w	r0, [r8, r5, lsl #1]
	beq	.LBB1_8
	add.w	r5, r8, r5, lsl #1
	cmp	r1, #2
	strh	r0, [r5, #2]
	it	ne
	strhne	r0, [r5, #4]
.LBB1_8:
	adds	r3, #1
	add.w	r7, r7, #480
	cmp	r3, lr
	ble	.LBB1_1
	pop.w	{r4, r5, r6, r7, r8, r9, pc}

GDC
---
arm-none-eabi-gdc -c -O2 -nophoboslib -nostdinc -nodefaultlibs 
-nostdlib -mthumb -mcpu=cortex-m4 -mtune=cortex-m4 
-mfloat-abi=hard -Isource/runtime -fno-bounds-check 
-ffunction-sections -fdata-sections -fno-weak

_D5board3lcd8fillRectFiikktZv:
	.fnstart
.LFB4:
	@ args = 4, pretend = 0, frame = 0
	@ frame_needed = 0, uses_anonymous_args = 0
	@ link register save eliminated.
	push	{r4, r5, r6}
	add	r3, r3, r1
	cmp	r1, r3
	ldrh	r5, [sp, #12]
	bgt	.L47
	rsb	r4, r1, r1, lsl #4
	add	r0, r0, r4, lsl #4
	ldr	r4, .L58
	add	r0, r0, r2
	rsb	r6, r2, r2, lsl #31
	add	r4, r4, r0, lsl #1
	lsls	r6, r6, #1
.L51:
	cbz	r2, .L49
	adds	r0, r4, r6
.L50:
	strh	r5, [r0], #2	@ movhi
	cmp	r0, r4
	bne	.L50
.L49:
	adds	r1, r1, #1
	cmp	r3, r1
	add	r4, r4, #480
	bge	.L51
.L47:
	pop	{r4, r5, r6}
	bx	lr

Mike


More information about the D.gnu mailing list