maciek_urbanski
Member
- Joined
- Oct 3, 2008
- Messages
- 161
In my analysis of SGX architecture I'm working primarily with ARM assembly. This is my first contact with ARM architecture, so I learn it on-the-fly, but I'm loving every minute of it. It's instruction set is a pure elegance.
The only fly in the ointment is quality of code produced by Code Sourcery G++.
I found some fairy obvious sub-optimialities, most involving ARM predicated execution or (lack of) variable limit analysis.
example 1:
CODE
1: CMP R0, #constant
2: LDRNE R3, [R1,#4]
3: MOVNE R3, R3,LSR#20
4: ANDNE R0, R3, #1
5: LDREQ R3, [R1,#4]
6: MOVEQ R3, R3,LSR#23
7: ANDEQ R0, R3, #1
Loading [R1,#4] to R3 occurs in not-equal and in equal case. The same goes for boolean 'and'.
Optimized version would look like this:
CODE
1: CMP R0, #constant
2: LDR R3, [R1,#4]
3: MOVNE R3, R3,LSR#20
6: MOVEQ R3, R3,LSR#23
7: AND R0, R3, #1
Seems GCC is handling ARM conditional instructions rather poorly (from performance standpoint).
example 2:
CODE
1: BL some_function_returning_bool_in_R0
2: CMP R0, #0
3: ADDEQ R0, R0, #1
4: LDRNE R3, [R4]
5: MOVNE R0, #1
6: ORRNE R3, R3, #0x80
7: STRNE R3, [R4]
Line 5 is not necessary. after 1. R0 can be either 0 or 1. After 3 it can be only 1.
Optimized version would look like this:
CODE
1: BL some_function_returning_bool_in_R0
2: CMP R0, #0
3: ADDEQ R0, R0, #1
4: LDRNE R3, [R4]
6: ORRNE R3, R3, #0x80
7: STRNE R3, [R4]
There's a lot of code like this produced by Code Sourcery G++ (those are not by any means isolated occurrences).
Boy, I wonder how fast it will be when Code Sourcery will fix those pesky little flaws. B)
Damn, I made mistake in subtopic. :angry:
MOD: please change subtopic to '...is not very high...'
The only fly in the ointment is quality of code produced by Code Sourcery G++.
I found some fairy obvious sub-optimialities, most involving ARM predicated execution or (lack of) variable limit analysis.
example 1:
CODE
1: CMP R0, #constant
2: LDRNE R3, [R1,#4]
3: MOVNE R3, R3,LSR#20
4: ANDNE R0, R3, #1
5: LDREQ R3, [R1,#4]
6: MOVEQ R3, R3,LSR#23
7: ANDEQ R0, R3, #1
Loading [R1,#4] to R3 occurs in not-equal and in equal case. The same goes for boolean 'and'.
Optimized version would look like this:
CODE
1: CMP R0, #constant
2: LDR R3, [R1,#4]
3: MOVNE R3, R3,LSR#20
6: MOVEQ R3, R3,LSR#23
7: AND R0, R3, #1
Seems GCC is handling ARM conditional instructions rather poorly (from performance standpoint).
example 2:
CODE
1: BL some_function_returning_bool_in_R0
2: CMP R0, #0
3: ADDEQ R0, R0, #1
4: LDRNE R3, [R4]
5: MOVNE R0, #1
6: ORRNE R3, R3, #0x80
7: STRNE R3, [R4]
Line 5 is not necessary. after 1. R0 can be either 0 or 1. After 3 it can be only 1.
Optimized version would look like this:
CODE
1: BL some_function_returning_bool_in_R0
2: CMP R0, #0
3: ADDEQ R0, R0, #1
4: LDRNE R3, [R4]
6: ORRNE R3, R3, #0x80
7: STRNE R3, [R4]
There's a lot of code like this produced by Code Sourcery G++ (those are not by any means isolated occurrences).
Boy, I wonder how fast it will be when Code Sourcery will fix those pesky little flaws. B)
Damn, I made mistake in subtopic. :angry:
MOD: please change subtopic to '...is not very high...'