-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathgenbinary.py
More file actions
executable file
·30 lines (27 loc) · 853 Bytes
/
genbinary.py
File metadata and controls
executable file
·30 lines (27 loc) · 853 Bytes
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
#!/usr/bin/python
def gen (lower, upper, eq):
assert lower <= upper;
if lower == upper:
if eq:
print "if (key != KEY (%d)) goto failure;" % lower
print "RETURN (%d);" % lower
else:
middle = (lower + upper) / 2
print "if (key <= KEY (%d)) {" % middle
gen (lower, middle, eq)
print "} else {"
gen (middle + 1, upper, eq)
print "}"
for n in range (129):
print "static int GEN_NAME (binary_static_unrolled, %d) (const int *arr, int n, int key) {" % n
gen (0, n, False)
print "assert (0);"
print "return -1;"
print "}"
for n in range (129):
print "static int GEN_NAME (binary_static_unrolled_eq, %d) (const int *arr, int n, int key) {" % n
gen (0, n, True)
print "failure:"
print "assert (0);"
print "return -1;"
print "}"