이 코드를 올바른 방식으로 최적화하려고합니다. 내가 옳다고 말하는 것은 ... 누군가가 코드를보고 최적화를 제거 할 수 있도록 이러한 최적화를 수행하는 일반적인 접근 방식이 있다고 생각합니다. 나는 첫 번째 부분 (제대로 있는지 확실하지 않습니다)를 최적화 할 수 있습니다,하지만 난SPARC 어셈블리의 루프 최적화
mov %g0, %l2
cmp %l0, %l1
bge END_LOOP
nop
LOOP:
mov %l0, %o0
call .mul
mov %l1, %o1 ! Fill delay slot with second argument
add %l2, %o0, %l2
inc %l0
cmp %l0, %l1
bl LOOP
nop
END_LOOP:
mov %l2, %o0
call .mul ! Fill delay sot with second argument
mov %l1, %o1
mov %o0, %l3
읽기 쉽 코드의
C 샘플 ...
int a = 1; // mapped to %l0
int b = 5; // mapped to %l1
int c = 0; // mapped to %l2
int d; // mapped to %l3
while(a < b) {
c += a * b;
++a;
}
d = c * b;
SPARC 어셈블리 버전 ... 두 번째 부분을 최적화하는 방법을 모릅니다.
mov %g0, %l2
cmp %l0, %l1
bge,a END_LOOP ! Annul branch to execute if branch is taken
mov %l2, %o0 ! Instruction at target
LOOP:
mov %l0, %o0
call .mul
mov %l1, %o1 ! Fill delay slot with second argument
add %l2, %o0, %l2
inc %l0
cmp %l0, %l1
bl LOOP
nop
mov %l2, %o0 ! Move the instruction to above the target
END_LOOP:
call .mul ! Fill delay sot with second argument
mov %l1, %o1
mov %o0, %l3
이러한 최적화를 수행하는 방법에 대한 도움은 매우 감사하겠습니다.
SPARC v8 이상을 대상으로하는 경우'.mul' 시스템 라이브러리 루틴을 호출하는 대신 'SMUL' 명령을 사용할 수 있습니다. – Michael
아마 내가 추가 했어야합니다. 이것은 구형 32 비트 SPARC 시스템입니다. – logbaseinfinity