@######################################################### @ @ Scott R. Armstrong @ UIUC CS433 Spring 2007 @ ASM Performance Improvement Project @ Due by May 8, 2007 @ @######################################################### .file "primes.c" .section .rodata .text .align 2 .global main .type main, %function main: @ args = 0, pretend = 0, frame = 28 @ frame_needed = 1, uses_anonymous_args = 0 mov ip, sp stmfd sp!, {fp, ip, lr, pc} sub fp, ip, #4 sub sp, sp, #28 @@ set up z (limit of numbers to check for prime-ness) mov r3, #99328 @ compiler split z into 99328+672 add r3, r3, #672 @ uses shifted values to fit IMM field @ or load a different IMM into r6 @ assigned here to replace I/O for @ the purposes of this project mov r6, r3 @ move value into z mov r5, #10 @ y, initialized to 10 @ to demonstrate loop unrolling .L1: @@ y-loop-start cmp r5, r6 bgt .L1_END @@ Start of unrolled-loops section @@ n+1 loop add r5, r5, #1 @ n + 1 mov r7, #1 @@ prime, initialized to true mov r4, #2 @@ x, initialized to 2 .L2_n1: @@ x-loop-start mov r2, r5, asr #1 @@ y/2 (y DIV 2, no need for fractions) cmp r4, r2 @@ Compare r2 (y/2) with x bgt .L2_END_n1 @ DIV/MOD function - based on ARM Developer Suite 1.1 Divide Function @ used here instead of linking a MOD function mov r9, r4 mov r10, r5 @ r10 will contain any remainder .L_DIV_n1: mov r2, r9 cmp r2, r10, lsr #1 .L_DIV_1_n1: movls r2, r2, lsl #1@ cmp r2, r10, lsr #1 bls .L_DIV_1_n1 mov r0, #0 @ Initialize quotient .L_DIV_2_n1: cmp r10, r2 subcs r10, r10, r2 adc r0, r0, r0 mov r2, r2, lsr #1 cmp r2, r9 bhs .L_DIV_2_n1 @ End DIV/MOD function cmp r10, #0 @ if no remainder moveq r7, #0 @ set prime to false cmp r7, #1 addeq r4, r4, #1 @ if prime, increment x beq .L2_n1 @ ...and branch to L2 (repeat) .L2_END_n1: cmp r7, #1 moveq r8, r5 @ store last prime number in r8 @@ n+3 loop add r5, r5, #2 @ n + 3 mov r7, #1 @@ prime, initialized to true mov r4, #2 @@ x, initialized to 2 .L2_n3: @@ x-loop-start mov r2, r5, asr #1 @@ y/2 (y DIV 2, no need for fractions) cmp r4, r2 @@ Compare r2 (y/2) with x bgt .L2_END_n3 @ DIV/MOD function - based on ARM Developer Suite 1.1 Divide Function @ used here instead of linking a MOD function mov r9, r4 mov r10, r5 @ r10 will contain any remainder .L_DIV_n3: mov r2, r9 cmp r2, r10, lsr #1 .L_DIV_1_n3: movls r2, r2, lsl #1@ cmp r2, r10, lsr #1 bls .L_DIV_1_n3 mov r0, #0 @ Initialize quotient .L_DIV_2_n3: cmp r10, r2 subcs r10, r10, r2 adc r0, r0, r0 mov r2, r2, lsr #1 cmp r2, r9 bhs .L_DIV_2_n3 @ End DIV/MOD function cmp r10, #0 @ if no remainder moveq r7, #0 @ set prime to false cmp r7, #1 addeq r4, r4, #1 @ if prime, increment x beq .L2_n3 @ ...and branch to L2 (repeat) .L2_END_n3: cmp r7, #1 moveq r8, r5 @ store last prime number in r8 @@ n+7 loop add r5, r5, #4 @ n + 7 mov r7, #1 @@ prime, initialized to true mov r4, #2 @@ x, initialized to 2 .L2_n7: @@ x-loop-start mov r2, r5, asr #1 @@ y/2 (y DIV 2, no need for fractions) cmp r4, r2 @@ Compare r2 (y/2) with x bgt .L2_END_n7 @ DIV/MOD function - based on ARM Developer Suite 1.1 Divide Function @ used here instead of linking a MOD function mov r9, r4 mov r10, r5 @ r10 will contain any remainder .L_DIV_n7: mov r2, r9 cmp r2, r10, lsr #1 .L_DIV_1_n7: movls r2, r2, lsl #1@ cmp r2, r10, lsr #1 bls .L_DIV_1_n7 mov r0, #0 @ Initialize quotient .L_DIV_2_n7: cmp r10, r2 subcs r10, r10, r2 adc r0, r0, r0 mov r2, r2, lsr #1 cmp r2, r9 bhs .L_DIV_2_n7 @ End DIV/MOD function cmp r10, #0 @ if no remainder moveq r7, #0 @ set prime to false cmp r7, #1 addeq r4, r4, #1 @ if prime, increment x beq .L2_n7 @ ...and branch to L2 (repeat) .L2_END_n7: cmp r7, #1 moveq r8, r5 @ store last prime number in r8 @@ n+9 loop add r5, r5, #2 @ n + 9 mov r7, #1 @@ prime, initialized to true mov r4, #2 @@ x, initialized to 2 .L2_n9: @@ x-loop-start mov r2, r5, asr #1 @@ y/2 (y DIV 2, no need for fractions) cmp r4, r2 @@ Compare r2 (y/2) with x bgt .L2_END_n9 @ DIV/MOD function - based on ARM Developer Suite 1.1 Divide Function @ used here instead of linking a MOD function mov r9, r4 mov r10, r5 @ r10 will contain any remainder .L_DIV_n9: mov r2, r9 cmp r2, r10, lsr #1 .L_DIV_1_n9: movls r2, r2, lsl #1@ cmp r2, r10, lsr #1 bls .L_DIV_1_n9 mov r0, #0 @ Initialize quotient .L_DIV_2_n9: cmp r10, r2 subcs r10, r10, r2 adc r0, r0, r0 mov r2, r2, lsr #1 cmp r2, r9 bhs .L_DIV_2_n9 @ End DIV/MOD function cmp r10, #0 @ if no remainder moveq r7, #0 @ set prime to false cmp r7, #1 addeq r4, r4, #1 @ if prime, increment x beq .L2_n9 @ ...and branch to L2 (repeat) .L2_END_n9: cmp r7, #1 moveq r8, r5 @ store last prime number in r8 @@ End of unrolled-loops section add r5, r5, #1 @ add 1 to y, r5 adds total 10 b .L1 .L1_END: @mov r3, #0 @mov r0, r3 sub sp, fp, #12 ldmfd sp, {fp, sp, pc} .align 2 .size main, .-main .ident "GCC: (GNU) 4.1.0" .end