-
Notifications
You must be signed in to change notification settings - Fork 4
/
logics.fj
128 lines (110 loc) · 2.75 KB
/
logics.fj
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
// ---------- Logical Macros
ns bit {
// Complexity: @-1
// dst ^= src
// dst,src are bits.
def xor dst, src {
.exact_xor dst + dbit, src
}
// Complexity: n(@-1)
// dst[:n] ^= src[:n]
// dst,src are bit[:n].
def xor n, dst, src {
rep(n, i) .xor dst+dw*i, src+dw*i
}
// Complexity: @-1
// note: pad 2 is needed, but pad 8 is used for wflips-padding optimization and for smaller wflips.
// dst(bit_address) ^= src
// dst,src are bits.
def exact_xor dst, src @ base_jump_label, cleanup {
wflip src+w, base_jump_label, src
pad 8
base_jump_label:
;cleanup
dst;
cleanup:
wflip src+w, base_jump_label
}
// Complexity: @
// note: pad 2 is needed, but pad 8 is used for wflips-padding optimization and for smaller wflips.
// dst1(bit_address) ^= src
// dst2(bit_address) ^= src
// dst1,dst2,src are bits.
def double_exact_xor dst1, dst2, src @ base_jump_label, cleanup {
wflip src+w, base_jump_label, src
pad 8
base_jump_label:
;cleanup
dst1;
dst2;
cleanup:
wflip src+w, base_jump_label
}
// Complexity: n@
// address(bit_address) ^= src
// var ^= src
// var,src are bit[:n], address is an address.
def address_and_variable_xor n, address, var, src {
rep(n, i) .double_exact_xor address+i, var+dbit+i*dw, src+i*dw
}
// Complexity: @
// dst ^= src
// src = 0
// dst,src are bits.
def xor_zero dst, src {
.double_exact_xor dst+dbit, src+dbit, src
}
// Complexity: n@
// dst[:n] ^= src[:n]
// src[:n] = 0
// dst,src are bit[:n].
def xor_zero n, dst, src {
rep(n, i) .xor_zero dst+dw*i, src+dw*i
}
// Complexity: 2@+2
// dst |= src
// dst,src are bits.
def or dst, src @ end {
.if0 src, end
.one dst
end:
}
// Complexity: n(2@+2)
// dst[:n] |= src[:n]
// dst,src are bit[:n].
def or n, dst, src {
rep(n, i) .or dst+dw*i, src+dw*i
}
// Complexity: 2@+2
// dst &= src
// dst,src are bits.
def and dst, src @ end {
.if1 src, end
.zero dst
end:
}
// Complexity: n(2@+2)
// dst[:n] &= src[:n]
// dst,src are bit[:n].
def and n, dst, src {
rep(n, i) .and dst+dw*i, src+dw*i
}
// Complexity: 1
// dst ^= 1
// dst is a bit.
def not dst {
dst + dbit;
}
// Complexity: n
// dst[:n] ^= (1<<n)-1
// dst is bit[:n]
def not n, dst {
rep(n, i) .not dst+dw*i
}
// Complexity: 1
// dst(bit_address) ^= 1
// dst is an address.
def exact_not dst {
dst;
}
}