-
Notifications
You must be signed in to change notification settings - Fork 0
/
term_actions.inc
530 lines (416 loc) · 14.7 KB
/
term_actions.inc
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
CHILDNULL = FALSE
macro action_not sidefrom*, sideto*, lenfrom*, lento* {
save r12,r13,r14,r15,rsi,rdi
mov sequent, arg1
mov el_index, arg2
malloc sizeof.SEQUENT
mov new_seq, rax
mov child1, new_seq
mov child2, NULL
if CHILDNULL
mov [new_seq+SEQUENT.child1], NULL
mov [new_seq+SEQUENT.child2], NULL
end if
;===sideto===
mov r15, lento
inc r15 ;r15 = incremented lento
shl r15, 3 ;*8
malloc r15 ;alloc 8*(lento+1)
;copy old to new
mov rsi, sideto ;rsi = old sideto
mov rdi, rax ;rdi = new sideto
mov rcx, lento ;rcx = lento
rep movsq
;add elem sidefrom[el_index].t1
mov r11, sidefrom ;sidefrom ptr
mov r11, [r11+el_index*8] ;elem ptr
mov r11, [r11+TERM.t1] ;elem.t1 (=TERM ptr)
sub r15, 8
mov [rax+r15], r11 ;new sideto[(old)lento*8] = elem.t1
;update sideto
mov [new_seq+SEQUENT.#sideto], rax
;update lento
mov r11, lento
inc r11
mov [new_seq+SEQUENT.#lento], r11
;===sidefrom===
dec_lenfrom equ r15
mov dec_lenfrom, lenfrom
dec dec_lenfrom
mov r11, dec_lenfrom
shl r11, 3
malloc r11 ;alloc 8*(lenfrom-1)
mov rsi, sidefrom ;rsi = old sidefrom
mov rdi, rax ;rdi = new sidefrom
mov rcx, el_index ;rcx = el_index
rep movsq
add rsi, 8 ;skip elem
mov rcx, dec_lenfrom ;rcx = lenfrom-1
sub rcx, el_index ;rcx = lenfrom-1 - elem_index
rep movsq
;update sidefrom
mov [new_seq+SEQUENT.#sidefrom], rax
;update lenfrom
mov r11, lenfrom
dec r11
mov [new_seq+SEQUENT.#lenfrom], r11
rest
ret
}
macro action_chop side1*, side2*, len1*, len2* {
save r12,r13,r14,r15,rsi,rdi
mov sequent, arg1
mov el_index, arg2
malloc sizeof.SEQUENT
mov new_seq, rax
mov child1, new_seq
mov child2, NULL
if CHILDNULL
mov [new_seq+SEQUENT.child1], NULL
mov [new_seq+SEQUENT.child2], NULL
end if
;===side1===
inc_len1 equ r15
mov inc_len1, len1
inc inc_len1
mov r11, inc_len1
shl r11, 3
malloc r11 ;alloc 8*(len1 + 1)
mov rsi, side1 ;rsi = old side1
mov rdi, rax ;rdi = new side1
mov rcx, el_index ;rcx = el_index
rep movsq
add rsi, 8 ;skip elem
mov rcx, len1
dec rcx ;rcx = len1 - 1
sub rcx, el_index ;rcx = len1 - 1 - elem_index
rep movsq
;add elems
mov rsi, side1 ;side1 ptr
mov rsi, [rsi+el_index*8] ;elem ptr
add rsi, TERM.t1 ;elem.t1 (=TERM ptr)
movsq ;add to new side1: elem.t1
movsq ;add to new side1: elem.t2
mov [new_seq+SEQUENT.#side1], rax ;update side1
mov [new_seq+SEQUENT.#len1], inc_len1 ;update len1
;===side2===
mov rax, len2
shl rax, 3
malloc rax ;alloc 8*len2
mov rsi, side2 ;rsi = old side2
mov rdi, rax ;rdi = new side2
mov rcx, len2 ;rcx = len2
rep movsq
mov [new_seq+SEQUENT.#side2], rax ;update side2
mov rax, len2
mov [new_seq+SEQUENT.#len2], rax ;update len2
rest
ret
}
;side1 contains element to be chopped and will receive the chopped terms (excl. t1 if t1_at2)
macro action_chop_split side1*, side2*, len1*, len2*, t1_at2=FALSE {
seq1 equ r14
seq2 equ rbx
save r12,r13,r14,r15,rbx,rsi,rdi
mov sequent, arg1
mov el_index, arg2
macro create_seq@action_chop_split n_seq* \{
malloc sizeof.SEQUENT
mov seq\#n_seq, rax
mov child\#n_seq, rax
if CHILDNULL
mov [rax+SEQUENT.child1], NULL
mov [rax+SEQUENT.child2], NULL
end if
\}
rept 2 % \{create_seq@action_chop_split %\}
purge create_seq@action_chop_split
;===side1===
if ~t1_at2
mov r15, len1
shl r15, 3
end if
macro side1@action_chop_split n_child* \{
if t1_at2
mov r15, len1
if n_child=1
dec r15
end if
shl r15, 3
end if
malloc r15 ;alloc 8*(len1 [-1])
mov rsi, side1 ;rsi = old side1
mov rdi, rax ;rdi = new side1
mov rcx, el_index ;rcx = el_index
rep movsq
add rsi, 8 ;skip elem
mov rcx, len1
dec rcx ;rcx = len1 - 1
sub rcx, el_index ;rcx = len1 - 1 - elem_index
rep movsq
if ~(t1_at2 & n_child=1)
;add elem.tX
mov rsi, side1 ;side1 ptr
mov rsi, [rsi+el_index*8] ;elem ptr
add rsi, TERM.t\#n_child ;elem.tX (=TERM ptr)
movsq ;add to new side1: elem.tX
end if
mov [seq\#n_child+SEQUENT.#side1], rax ;update side1
mov rax, len1
if t1_at2 & n_child=1
dec rax
end if
mov [seq\#n_child+SEQUENT.#len1], rax ;set len1
\}
rept 2 % \{side1@action_chop_split %\}
purge side1@action_chop_split
;===side2===
if ~t1_at2
mov r15, len2
shl r15, 3
end if
macro side2@action_chop_split n_child* \{
if t1_at2
mov r15, len2
if n_child=1
inc r15
end if
shl r15, 3
end if
malloc r15 ;alloc 8*(len2 [+1])
mov rsi, side2 ;rsi = old side2
mov rdi, rax ;rdi = new side2
mov rcx, len2 ;rcx = len2
rep movsq
if t1_at2 & n_child=1
;add elem.t1
mov rsi, side1 ;side1 ptr
mov rsi, [rsi+el_index*8] ;elem ptr
add rsi, TERM.t1 ;elem.t1 (=TERM ptr)
movsq ;add to new side2: elem.t1
end if
mov [seq\#n_child+SEQUENT.#side2], rax ;update side2
mov rax, len2
if t1_at2 & n_child=1
inc rax
end if
mov [seq\#n_child+SEQUENT.#len2], rax ;set len2
\}
rept 2 % \{side2@action_chop_split %\}
purge side2@action_chop_split
rest
ret
restore seq1,seq2
}
;side1 contains element to be chopped
macro action_imp_eqv_r side1*, side2*, len1*, len2*, split* {
seq1 equ r14
seq2 equ rbx
save r12,r13,r14,r15,rbx,rsi,rdi
mov sequent, arg1
mov el_index, arg2
macro create_seq@action_imp_eqv_r n_seq* \{
malloc sizeof.SEQUENT
mov seq\#n_seq, rax
mov child\#n_seq, rax
if CHILDNULL
mov [rax+SEQUENT.child1], NULL
mov [rax+SEQUENT.child2], NULL
end if
\}
create_seq@action_imp_eqv_r 1
if split
create_seq@action_imp_eqv_r 2
else
mov child2, NULL
end if
purge create_seq@action_imp_eqv_r
;===side1===
mov r15, len1
shl r15, 3
macro side1@action_imp_eqv_r n_child*, tx* \{
malloc r15 ;alloc 8*len1
mov rsi, side1 ;rsi = old side1
mov rdi, rax ;rdi = new side1
mov rcx, el_index ;rcx = el_index
rep movsq
add rsi, 8 ;skip elem
mov rcx, len1
dec rcx ;rcx = len1 - 1
sub rcx, el_index ;rcx = len1 - 1 - elem_index
rep movsq
;add elem.tX
mov rsi, side1 ;side1 ptr
mov rsi, [rsi+el_index*8] ;elem ptr
add rsi, TERM.t\#tx ;elem.tX (=TERM ptr)
movsq ;add to new side1: elem.tX
mov [seq\#n_child+SEQUENT.#side1], rax ;update side1
mov rax, len1
mov [seq\#n_child+SEQUENT.#len1], rax ;set len1
\}
;child1 gets t2, child2 gets t1
side1@action_imp_eqv_r 1, 2
if split
side1@action_imp_eqv_r 2, 1
end if
purge side1@action_imp_eqv_r
;===side2===
mov r15, len2
inc r15
shl r15, 3
macro side2@action_imp_eqv_r n_child* \{
malloc r15 ;alloc 8*(len2 + 1)
mov rsi, side2 ;rsi = old side2
mov rdi, rax ;rdi = new side2
mov rcx, len2 ;rcx = len2
rep movsq
;add elem.tX
mov rsi, side1 ;side1 ptr
mov rsi, [rsi+el_index*8] ;elem ptr
add rsi, TERM.t\#n_child ;elem.tX (=TERM ptr)
movsq ;add to new side2: elem.tX
mov [seq\#n_child+SEQUENT.#side2], rax ;update side2
mov rax, len2
inc rax
mov [seq\#n_child+SEQUENT.#len2], rax ;set len2
\}
side2@action_imp_eqv_r 1
if split
side2@action_imp_eqv_r 2
end if
purge side2@action_imp_eqv_r
rest
ret
restore seq1,seq2
}
;side1 contains element to be chopped
macro action_eqv_l side1*, side2*, len1*, len2* {
seq1 equ r14
seq2 equ rbx
save r12,r13,r14,r15,rbx,rsi,rdi
mov sequent, arg1
mov el_index, arg2
macro create_seq@action_eqv_l n_seq* \{
malloc sizeof.SEQUENT
mov seq\#n_seq, rax
mov child\#n_seq, rax
if CHILDNULL
mov [rax+SEQUENT.child1], NULL
mov [rax+SEQUENT.child2], NULL
end if
\}
rept 2 % \{create_seq@action_eqv_l %\}
purge create_seq@action_eqv_l
;===side1===
mov r15, len1
inc r15
shl r15, 3
macro side1@action_eqv_l n_child* \{
if n_child=2
sub r15, 2*8
end if
malloc r15 ;alloc 8*(len1 + 1)
mov rsi, side1 ;rsi = old side1
mov rdi, rax ;rdi = new side1
mov rcx, el_index ;rcx = el_index
rep movsq
add rsi, 8 ;skip elem
mov rcx, len1
dec rcx ;rcx = len1 - 1
sub rcx, el_index ;rcx = len1 - 1 - elem_index
rep movsq
if n_child=1
;add elems
mov rsi, side1 ;side1 ptr
mov rsi, [rsi+el_index*8] ;elem ptr
add rsi, TERM.t1 ;elem.t1 (=TERM ptr)
movsq ;add to new side1: elem.t1
movsq ;add to new side1: elem.t2
end if
mov [seq\#n_child+SEQUENT.#side1], rax ;update side1
mov rax, len1
if n_child=1
inc rax
else
dec rax
end if
mov [seq\#n_child+SEQUENT.#len1], rax ;set len1
\}
rept 2 % \{side1@action_eqv_l %\}
purge side1@action_eqv_l
;===side2===
mov r15, len2
shl r15, 3
macro side2@action_eqv_l n_child* \{
if n_child=2
add r15, 2*8
end if
malloc r15 ;alloc 8*len2
mov rsi, side2 ;rsi = old side2
mov rdi, rax ;rdi = new side2
mov rcx, len2 ;rcx = len2
rep movsq
if n_child=2
;add elems
mov rsi, side1 ;side1 ptr
mov rsi, [rsi+el_index*8] ;elem ptr
add rsi, TERM.t1 ;elem.t1 (=TERM ptr)
movsq ;add to new side2: elem.t1
movsq ;add to new side2: elem.t2
end if
mov [seq\#n_child+SEQUENT.#side2], rax ;update side2
mov rax, len2
if n_child=2
add rax, 2
end if
mov [seq\#n_child+SEQUENT.#len2], rax ;set len2
\}
rept 2 % {side2@action_eqv_l %\}
purge side2@action_eqv_l
rest
ret
restore seq1,seq2
}
sequent equ r12
el_index equ r13
new_seq equ r14
tside equ [sequent+SEQUENT.tside]
fside equ [sequent+SEQUENT.fside]
tlen equ [sequent+SEQUENT.tlen]
flen equ [sequent+SEQUENT.flen]
child1 equ [sequent+SEQUENT.child1]
child2 equ [sequent+SEQUENT.child2]
t_actions:
;sequent, el_index
fbound
.not: action_not tside, fside, tlen, flen
;sequent, el_index
fbound
.and: action_chop tside, fside, tlen, flen
;sequent, el_index
fbound
.or: action_chop_split tside, fside, tlen, flen
;sequent, el_index
fbound
.imp: action_chop_split tside, fside, tlen, flen, TRUE
;sequent, el_index
fbound
.eqv: action_eqv_l tside, fside, tlen, flen
f_actions:
;sequent, el_index
fbound
.not: action_not fside, tside, flen, tlen
;sequent, el_index
fbound
.and: action_chop_split fside, tside, flen, tlen
;sequent, el_index
fbound
.or: action_chop fside, tside, flen, tlen
;sequent, el_index
fbound
.imp: action_imp_eqv_r fside, tside, flen, tlen, FALSE
;sequent, el_index
fbound
.eqv: action_imp_eqv_r fside, tside, flen, tlen, TRUE
restore sequent,el_index, new_seq, tside,fside,tlen,flen,child1,child2
purge action_not,action_chop,action_chop_split,action_imp_eqv_r