-
Notifications
You must be signed in to change notification settings - Fork 0
/
ncopy.ys
190 lines (187 loc) · 3.54 KB
/
ncopy.ys
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#/* $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
# Loop header
xorq %rax,%rax # count = 0
# xorq %rbx,%rbx # iterator var
# irmovq $0xffffffffffffffff, %rbx
# irmovq $1, %rbp
iaddq $-10,%rdx #
# andq %rdx,%rdx # len <= 0? ## len > 0
jl L2 # if so, goto Done: ## if so, goto Loop
Loop:
mrmovq (%rdi), %r8
mrmovq 0x8(%rdi), %r9
mrmovq 0x10(%rdi), %r10
mrmovq 0x18(%rdi), %r11
mrmovq 0x20(%rdi), %r12
mrmovq 0x28(%rdi), %r13
mrmovq 0x30(%rdi), %r14
mrmovq 0x38(%rdi), %rcx
mrmovq 0x40(%rdi), %rbx
mrmovq 0x48(%rdi), %rbp
andq %r8,%r8
rmmovq %r8, (%rsi)
rmmovq %r9, 8(%rsi)
rmmovq %rbx, 0x40(%rsi)
rmmovq %rbp, 0x48(%rsi)
jle L1_2
iaddq $1, %rax
L1_2:
andq %r9,%r9
jle L1_3
iaddq $1, %rax
L1_3:
andq %r10,%r10
rmmovq %r10, 0x10(%rsi)
rmmovq %r11, 0x18(%rsi)
jle L1_4
iaddq $1, %rax
L1_4:
andq %r11,%r11
jle L1_5
iaddq $1, %rax
L1_5:
andq %r12,%r12
rmmovq %r12, 0x20(%rsi)
rmmovq %r13, 0x28(%rsi)
jle L1_6
iaddq $1, %rax
L1_6:
andq %r13,%r13
jle L1_7
iaddq $1, %rax
L1_7:
andq %r14,%r14
rmmovq %r14, 0x30(%rsi)
rmmovq %rcx, 0x38(%rsi)
jle L1_8
iaddq $1, %rax
L1_8:
andq %rcx,%rcx
jle L1_9
iaddq $1, %rax
L1_9:
andq %rbx, %rbx
jle L1_10
iaddq $1, %rax
L1_10:
andq %rbp, %rbp
jle L1_11
iaddq $1, %rax
L1_11:
iaddq $0x50, %rdi
iaddq $0x50, %rsi
iaddq $-10, %rdx
jge Loop
L2:
iaddq $9, %rdx
jg Loop2
# iaddq $2, %rdx
jl L2_Done
mrmovq (%rdi),%r8
rmmovq %r8, (%rsi)
andq %r8, %r8
jle Done
iaddq $1, %rax
#addq %r9, %rdx
# jle L2_Done
L2_Done:
ret
Loop2:
mrmovq (%rdi), %r8
mrmovq 8(%rdi), %r9
# iaddq $8, %rdi
# iaddq $8, %rsi
iaddq $-2, %rdx
jg L2_0
je D3 # last 3
rmmovq %r8, (%rsi)
rmmovq %r9, 8(%rsi)
andq %r8,%r8
jle D2_1
iaddq $1, %rax
D2_1:
andq %r9, %r9
jle Done
iaddq $1, %rax
ret
D3:
mrmovq 0x10(%rdi), %r10
rmmovq %r8, (%rsi)
rmmovq %r9, 8(%rsi)
rmmovq %r10, 0x10(%rsi)
andq %r8, %r8
jle D3_1
iaddq $1, %rax
D3_1:
andq %r9, %r9
jle D3_2
iaddq $1, %rax
D3_2:
andq %r10, %r10
jle Done
iaddq $1, %rax
ret
L2_0:
rmmovq %r8, (%rsi)
rmmovq %r9, 8(%rsi)
andq %r8,%r8
jle L2_1
iaddq $1, %rax
L2_1:
andq %r9, %r9
jle L2_2
iaddq $1, %rax
L2_2:
iaddq $0x10, %rdi
iaddq $0x10, %rsi
# iaddq $-2, %rdx
jmp Loop2
# iaddq $2, %rdx
# je Done
# mrmovq (%rdi),%r8
# rmmovq %r8, (%rsi)
#andq %r8, %r8
#jle Done
#iaddq $1, %rax
# mrmovq (%rdi), %r10 # read val from src...
# rmmovq %r10, (%rsi) # ...and store it to dst
# andq %r10, %r10 # val <= 0?
# jle Npos # if so, goto Npos:
# irmovq $1, %r10
# addq %r10, %rax # count++
# iaddq $1, %rax
# Npos:
# irmovq $1, %r10
# subq %r10, %rdx # len--
# irmovq $8, %r10
# addq %r10, %rdi # src++
# addq %r10, %rsi # dst++
# iaddq $8, %rdi
# iaddq $8, %rsi
# iaddq $-1,%rdx
# andq %rdx,%rdx # len > 0?
# jg Loop # if so, goto Loop:
##################################################################
# 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 */