1 | # -*- coding: utf-8 -*- |
---|
2 | # |
---|
3 | # parabix2_compilable.py |
---|
4 | # |
---|
5 | # Parallel XML Parsing with Bitstream Addition |
---|
6 | # |
---|
7 | # - Complete prototype for all bitstream computations in Parabix2 |
---|
8 | # - Optimized for compilation |
---|
9 | # - Separate compilation |
---|
10 | |
---|
11 | # Robert D. Cameron |
---|
12 | # July 29, 2010 |
---|
13 | # |
---|
14 | |
---|
15 | #import bitutil |
---|
16 | |
---|
17 | class Basis_bits(): |
---|
18 | bit_0 = 0 |
---|
19 | bit_1 = 0 |
---|
20 | bit_2 = 0 |
---|
21 | bit_3 = 0 |
---|
22 | bit_4 = 0 |
---|
23 | bit_5 = 0 |
---|
24 | bit_6 = 0 |
---|
25 | bit_7 = 0 |
---|
26 | |
---|
27 | class Dictionary (): |
---|
28 | Words = 0 |
---|
29 | Word_starts = 0 |
---|
30 | Word_ends = 0 |
---|
31 | Word_ends_1_to_2 = 0 |
---|
32 | Word_ends_3_to_4 = 0 |
---|
33 | Word_ends_5_to_6 = 0 |
---|
34 | Word_ends_7_to_8 = 0 |
---|
35 | Word_ends_9_to_10 = 0 |
---|
36 | Word_ends_11_to_12 = 0 |
---|
37 | Word_ends_13_to_14 = 0 |
---|
38 | Word_ends_15_to_16 = 0 |
---|
39 | Word_remaining_ends = 0 |
---|
40 | |
---|
41 | class Hash_data(): |
---|
42 | Hash_value = 0 |
---|
43 | |
---|
44 | def Classify_bytes(basis_bits, dictionary): |
---|
45 | temp1 = (basis_bits.bit_6 & basis_bits.bit_7) |
---|
46 | temp2 = (basis_bits.bit_5 | temp1) |
---|
47 | temp3 = (basis_bits.bit_4 & temp2) |
---|
48 | temp4 = (~temp3) |
---|
49 | temp5 = (basis_bits.bit_4 | basis_bits.bit_5) |
---|
50 | temp6 = (basis_bits.bit_6 | basis_bits.bit_7) |
---|
51 | temp7 = (temp5 | temp6) |
---|
52 | temp8 = ((basis_bits.bit_3 & temp4)|(~(basis_bits.bit_3) & temp7)) |
---|
53 | temp9 = (basis_bits.bit_1 &~ basis_bits.bit_0) |
---|
54 | dictionary.Words = (temp8 & temp9) |
---|
55 | |
---|
56 | temp = pablo.Advance(dictionary.Words) ^ dictionary.Words |
---|
57 | dictionary.Word_starts = temp & dictionary.Words |
---|
58 | dictionary.Word_ends = temp & ~dictionary.Words |
---|
59 | |
---|
60 | def Form_Length_Group_Bitstreams(dictionary): |
---|
61 | |
---|
62 | starts = dictionary.Word_starts |
---|
63 | ends = dictionary.Word_ends |
---|
64 | |
---|
65 | temp = ends | pablo.Advance(ends) |
---|
66 | |
---|
67 | # Group symbols of length 1 and 2 |
---|
68 | start_2 = pablo.Advance(pablo.Advance(starts)) |
---|
69 | dictionary.Word_ends_1_to_2 = start_2 & temp |
---|
70 | |
---|
71 | # Group symbols of length 3 and 4 |
---|
72 | start_4 = pablo.Advance(pablo.Advance(start_2 & ~temp)) |
---|
73 | dictionary.Word_ends_3_to_4 = start_4 & temp |
---|
74 | |
---|
75 | # Group symbols of length 5 and 6 |
---|
76 | start_6 = pablo.Advance(pablo.Advance(start_4 & ~temp)) |
---|
77 | dictionary.Word_ends_5_to_6 = start_6 & temp |
---|
78 | |
---|
79 | # Group symbols of length 7 and 8 |
---|
80 | start_8 = pablo.Advance(pablo.Advance(start_6 & ~temp)) |
---|
81 | dictionary.Word_ends_7_to_8 = start_8 & temp |
---|
82 | |
---|
83 | # Group symbols of length 9 and 10 |
---|
84 | start_10 = pablo.Advance(pablo.Advance(start_8 & ~temp)) |
---|
85 | dictionary.Word_ends_9_to_10 = start_10 & temp |
---|
86 | |
---|
87 | # Group symbols of length 11 and 12 |
---|
88 | start_12 = pablo.Advance(pablo.Advance(start_10 & ~temp)) |
---|
89 | dictionary.Word_ends_11_to_12 = start_12 & temp |
---|
90 | |
---|
91 | # Group symbols of length 13 and 14 |
---|
92 | start_14 = pablo.Advance(pablo.Advance(start_12 & ~temp)) |
---|
93 | dictionary.Word_ends_13_to_14 = start_14 & temp |
---|
94 | |
---|
95 | # Group symbols of length 15 and 16 |
---|
96 | start_16 = pablo.Advance(pablo.Advance(start_14 & ~temp)) |
---|
97 | dictionary.Word_ends_15_to_16 = start_16 & temp |
---|
98 | |
---|
99 | # Group symbols of length 17 and longer |
---|
100 | dictionary.Word_remaining_ends = start_16 & ~dictionary.Word_ends_15_to_16 |
---|
101 | |
---|
102 | def Compute_Hash_Value_Bitstream(hash_data, basis_bits): |
---|
103 | hash_data.Hash_value = basis_bits.bit_2 ^ basis_bits.bit_4 ^ basis_bits.bit_6 |
---|
104 | #hash_data.Hash_value = basis_bits.bit_3 ^ basis_bits.bit_5 ^ basis_bits.bit_7 |
---|
105 | |
---|
106 | def Main(basis_bits, dictionary, hash_data): |
---|
107 | Classify_bytes(basis_bits, dictionary) |
---|
108 | |
---|
109 | # These methods are needed to do Paralel Bitstream Based Length Sorting |
---|
110 | Form_Length_Group_Bitstreams(dictionary) |
---|
111 | Compute_Hash_Value_Bitstream(hash_data, basis_bits); |
---|
112 | |
---|