-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimingFunctions.asm
253 lines (203 loc) · 5.98 KB
/
TimingFunctions.asm
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
xdef _TimeConsequtiveReads
xdef @TimeConsequtiveReads
; Arguments:
; a2 = CIA timer low addr
; a0 = read start addr
; d0 = length of read
; Returns:
; d0 - diff (cost of timer register access not accounted for)
; d1 - actual length read
TimeConsequtiveReadsRaw48x:
movem.l d2-d7/a2-a6,-(sp)
move.l a2,a1
move.l a0,-(sp) ; Save start address for later.
divu.w #48,d0 ; The resolution of each step.
swap d0 ; To not have to worry about upper bytes
clr.w d0 ; being populated with the remainder in
swap d0 ; consuming functions.
move.w d0,d1 ; Calculate jump offset for
and.w #7,d1 ; how many 48B steps
moveq #8,d2 ; in to start the initial run
sub.w d1,d2 ; of the the read loop at.
mulu.w #4,d2 ; Multiply with sizeof movem.l, how to calc that?
lea .loopStart(pc,d2.w),a2
lsr.w #3,d0 ; Calculate how many times to run the loop.
; We don't need any special handling of zero here
; as if length is zero, we will jump to the end of
; the loop.
move.b (a1),-(sp) ; Save timer before value.
jmp (a2)
.loopStart:
movem.l (a0)+,d1-d7/a2-a6
movem.l (a0)+,d1-d7/a2-a6
movem.l (a0)+,d1-d7/a2-a6
movem.l (a0)+,d1-d7/a2-a6
movem.l (a0)+,d1-d7/a2-a6
movem.l (a0)+,d1-d7/a2-a6
movem.l (a0)+,d1-d7/a2-a6
movem.l (a0)+,d1-d7/a2-a6
.loopEnd:
dbra d0,.loopStart
move.b (a1),d1 ; Get timer after value.
clr.w d0
move.b (sp)+,d0 ; Restore timer before value.
sub.b d1,d0 ; Calculate duration of test.
.end:
move.l a0,d1 ; Calculate actual read
sub.l (sp)+,d1 ; data length;
movem.l (sp)+,d2-d7/a2-a6
rts
; Arguments:
; a2 = CIA timer low addr
; a0 = read start addr
; d0 = length of test
; Returns:
; d0 - diff
; d1 - actual length read
_TimeConsequtiveReads:
@TimeConsequtiveReads:
move.l a0,d1 ; Align address upward to even
add.l #3,d1 ; longword to avoid unaligned
lsr.l #2,d1 ; move.l's which gives slowdown
lsl.l #2,d1 ; on 020+ and this would only
move.l d1,a0 ; be confusing.
; bsr.s TimeConsequtiveReadsRaw4x
cmp.l #96,d0
blt.s .lessThan96
bsr.w TimeConsequtiveReadsRaw48x
bra.s .afterTiming
.lessThan96:
cmp.l #48,d0
blt.s .lessThan48
bsr.w TimeConsequtiveReadsRaw48
bra.s .afterTiming
.lessThan48:
cmp.l #40,d0
blt.s .lessThan40
bsr.w TimeConsequtiveReadsRaw40
bra.s .afterTiming
.lessThan40:
cmp.l #32,d0
blt.s .lessThan32
bsr.w TimeConsequtiveReadsRaw32
bra.s .afterTiming
.lessThan32:
cmp.l #24,d0
blt.s .noTiming
bsr.w TimeConsequtiveReadsRaw24
bra.s .afterTiming
.noTiming:
clr.l d0
clr.l d1
.afterTiming:
tst.b d0 ; The uncompensated timing can only be zero if the test
beq.s .end ; has not been run, so return as is in that case.
move.l d1,-(sp) ; Save actual length.
move.l d0,-(sp) ; Save duration.
bsr.s CalcCyclesPerTimerRead
move.l d0,d1
move.l (sp)+,d0 ; Restore duration.
sub.b d1,d0 ; Apply cycle cost of timer register access.
move.l (sp)+,d1 ; Restore actual length;
.end:
rts
; Arguments:
; a2 = CIA timer low byte addr
; Returns:
; d0.b cycles per read
CalcCyclesPerTimerRead:
clr.l d0 ; To not have to worry about upper bytes being populated
; with garbage in consumer functions.
move.b (a2),d0 ; Save before-value of the decreasing timer register
tst.b (a2)
tst.b (a2)
tst.b (a2)
tst.b (a2)
tst.b (a2)
tst.b (a2)
tst.b (a2)
sub.b (a2),d0 ; Subtract value of last read to get number of E
; clock cycles needed for eight reads.
lsr.b #3,d0 ; Calc E clocks cycles needed per read.
rts
; Arguments:
; a2 = CIA timer low addr
; a0 = read start addr
; d0 = length of read
; Returns:
; d0 - diff (cost of timer register access not accounted for)
; d1 - actual length read
TimeConsequtiveReadsRaw48:
movem.l d2-d7/a2-a6,-(sp)
move.l a2,a1
move.l a0,-(sp) ; Save start address for later.
clr.l d0 ; To not have to worry about upper bytes being populated
; with garbage in consumer functions.
move.b (a1),d0 ; Save timer before value.
movem.l (a0)+,d1-d7/a2-a6
sub.b (a1),d0 ; Get timer after value and calculate duration of test.
.end:
move.l a0,d1 ; Calculate actual read
sub.l (sp)+,d1 ; data length;
movem.l (sp)+,d2-d7/a2-a6
rts
; Arguments:
; a2 = CIA timer low addr
; a0 = read start addr
; d0 = length of read
; Returns:
; d0 - diff (cost of timer register access not accounted for)
; d1 - actual length read
TimeConsequtiveReadsRaw40:
movem.l d2-d7/a3-a6,-(sp)
move.l a0,-(sp) ; Save start address for later.
clr.l d0 ; To not have to worry about upper bytes being populated
; with garbage in consumer functions.
move.b (a2),d0 ; Save timer before value.
movem.l (a0)+,d2-d7/a3-a6
sub.b (a2),d0 ; Get timer after value and calculate duration of test.
.end:
move.l a0,d1 ; Calculate actual read
sub.l (sp)+,d1 ; data length;
movem.l (sp)+,d2-d7/a3-a6
rts
; Arguments:
; a2 = CIA timer low addr
; a0 = read start addr
; d0 = length of read
; Returns:
; d0 - diff (cost of timer register access not accounted for)
; d1 - actual length read
TimeConsequtiveReadsRaw32:
movem.l d4-d7/a3-a6,-(sp)
move.l a0,-(sp) ; Save start address for later.
clr.l d0 ; To not have to worry about upper bytes being populated
; with garbage in consumer functions.
move.b (a2),d0 ; Save timer before value.
movem.l (a0)+,d4-d7/a3-a6
sub.b (a2),d0 ; Get timer after value and calculate duration of test.
.end:
move.l a0,d1 ; Calculate actual read
sub.l (sp)+,d1 ; data length;
movem.l (sp)+,d4-d7/a3-a6
rts
; Arguments:
; a2 = CIA timer low addr
; a0 = read start addr
; d0 = length of read
; Returns:
; d0 - diff (cost of timer register access not accounted for)
; d1 - actual length read
TimeConsequtiveReadsRaw24:
movem.l d6-d7/a3-a6,-(sp)
move.l a0,-(sp) ; Save start address for later.
clr.l d0 ; To not have to worry about upper bytes being populated
; with garbage in consumer functions.
move.b (a2),d0 ; Save timer before value.
movem.l (a0)+,d6-d7/a3-a6
sub.b (a2),d0 ; Get timer after value and calculate duration of test.
.end:
move.l a0,d1 ; Calculate actual read
sub.l (sp)+,d1 ; data length;
movem.l (sp)+,d6-d7/a3-a6
rts