-
Notifications
You must be signed in to change notification settings - Fork 4
/
pointer_arithmetics.fj
38 lines (33 loc) · 1.23 KB
/
pointer_arithmetics.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
// ---------- Ptr ++/--/+=/-=
ns hex {
// Time Complexity: 9@+14
// Space Complexity: w(0.375@ + 3.25) + 5@+55 (for log(w) in 16,32,64,128)
// ptr[:w/4] += 2w
// @requires hex.add.init (or hex.init)
def ptr_inc ptr {
hex.add_constant w/4, ptr, dw
}
// Time Complexity: 9@+23
// Space Complexity: w(0.375@ + 3.25) + 5@+67 (for log(w) in 16,32,64,128)
// ptr[:w/4] -= 2w
// @requires hex.sub.init (or hex.init)
def ptr_dec ptr {
hex.sub_constant w/4, ptr, dw
}
// Time Complexity: 13@+26
// Space Complexity: w(0.375@ + 3.25) + 7.5@+94
// ptr[:w/4] += value * 2w (advance ptr by value)
// @requires hex.add.init (or hex.init)
// @note: The complexity is calculated with n_const=2, and for log(w) in 16,32,64,128.
def ptr_add ptr, value {
hex.add_constant w/4, ptr, value * dw
}
// Time Complexity: 13@+35
// Space Complexity: w(0.375@ + 3.25) + 7.5@+106
// ptr[:w/4] -= value * 2w (retreat ptr by value)
// @requires hex.add.init (or hex.init)
// @note: The complexity is calculated with n_const=2, and for log(w) in 16,32,64,128.
def ptr_sub ptr, value {
hex.sub_constant w/4, ptr, value * dw
}
}