CSAPP-sol/arch/sim/pipe/ncopy.ys

169 lines
2.9 KiB
Plaintext

#/* $begin ncopy-ys */
##################################################################
# ncopy.ys - Copy a src block of len words to dst.
# Return the number of positive words (>0) contained in src.
#
# Include your name and ID here.
#
# Describe how and why you modified the baseline code.
#
##################################################################
# Do not modify this portion
# Function prologue.
# %rdi = src, %rsi = dst, %rdx = len
ncopy:
##################################################################
# You can modify this portion
xorq %rax, %rax
iaddq $-9, %rdx
jle Remaining
Loop:
mrmovq (%rdi), %r10
rmmovq %r10, (%rsi)
andq %r10, %r10
jle F1
iaddq $1, %rax
F1:
mrmovq 8(%rdi), %r10
rmmovq %r10, 8(%rsi)
andq %r10, %r10
jle F2
iaddq $1, %rax
F2:
mrmovq 16(%rdi), %r10
rmmovq %r10, 16(%rsi)
andq %r10, %r10
jle F3
iaddq $1, %rax
F3:
mrmovq 24(%rdi), %r10
rmmovq %r10, 24(%rsi)
andq %r10, %r10
jle F4
iaddq $1, %rax
F4:
mrmovq 32(%rdi), %r10
rmmovq %r10, 32(%rsi)
andq %r10, %r10
jle F5
iaddq $1, %rax
F5:
mrmovq 40(%rdi), %r10
rmmovq %r10, 40(%rsi)
andq %r10, %r10
jle F6
iaddq $1, %rax
F6:
mrmovq 48(%rdi), %r10
rmmovq %r10, 48(%rsi)
andq %r10, %r10
jle F7
iaddq $1, %rax
F7:
mrmovq 56(%rdi), %r10
rmmovq %r10, 56(%rsi)
andq %r10, %r10
jle F8
iaddq $1, %rax
F8:
mrmovq 64(%rdi), %r10
rmmovq %r10, 64(%rsi)
andq %r10, %r10
jle F9
iaddq $1, %rax
F9:
mrmovq 72(%rdi), %r10
rmmovq %r10, 72(%rsi)
andq %r10, %r10
jle F10
iaddq $1, %rax
F10:
iaddq $80, %rdi
iaddq $80, %rsi
iaddq $-10, %rdx
jg Loop
Remaining:
iaddq $8, %rdx
jl Done
je J1
iaddq $-2, %rdx
jl J2
je J3
iaddq $-2, %rdx
jl J4
je J5
iaddq $-2, %rdx
jl J6
je J7
iaddq $-1, %rdx
je J8
J9:
mrmovq 64(%rdi), %r10
rmmovq %r10, 64(%rsi)
andq %r10, %r10
jle J8
iaddq $1, %rax
J8:
mrmovq 56(%rdi), %r10
rmmovq %r10, 56(%rsi)
andq %r10, %r10
jle J7
iaddq $1, %rax
J7:
mrmovq 48(%rdi), %r10
rmmovq %r10, 48(%rsi)
andq %r10, %r10
jle J6
iaddq $1, %rax
J6:
mrmovq 40(%rdi), %r10
rmmovq %r10, 40(%rsi)
andq %r10, %r10
jle J5
iaddq $1, %rax
J5:
mrmovq 32(%rdi), %r10
rmmovq %r10, 32(%rsi)
andq %r10, %r10
jle J4
iaddq $1, %rax
J4:
mrmovq 24(%rdi), %r10
rmmovq %r10, 24(%rsi)
andq %r10, %r10
jle J3
iaddq $1, %rax
J3:
mrmovq 16(%rdi), %r10
rmmovq %r10, 16(%rsi)
andq %r10, %r10
jle J2
iaddq $1, %rax
J2:
mrmovq 8(%rdi), %r10
rmmovq %r10, 8(%rsi)
andq %r10, %r10
jle J1
iaddq $1, %rax
J1:
mrmovq (%rdi), %r10
rmmovq %r10, (%rsi)
andq %r10, %r10
jle Done
iaddq $1, %rax
##################################################################
# Do not modify the following section of code
# Function epilogue.
Done:
ret
##################################################################
# Keep the following label at the end of your function
End:
#/* $end ncopy-ys */