]>
Commit | Line | Data |
---|---|---|
1d09f67e TL |
1 | #!/bin/python |
2 | ||
3 | # Licensed to the Apache Software Foundation (ASF) under one | |
4 | # or more contributor license agreements. See the NOTICE file | |
5 | # distributed with this work for additional information | |
6 | # regarding copyright ownership. The ASF licenses this file | |
7 | # to you under the Apache License, Version 2.0 (the | |
8 | # "License"); you may not use this file except in compliance | |
9 | # with the License. You may obtain a copy of the License at | |
10 | # | |
11 | # http://www.apache.org/licenses/LICENSE-2.0 | |
12 | # | |
13 | # Unless required by applicable law or agreed to in writing, | |
14 | # software distributed under the License is distributed on an | |
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
16 | # KIND, either express or implied. See the License for the | |
17 | # specific language governing permissions and limitations | |
18 | # under the License. | |
19 | ||
20 | # This script is modified from its original version in GitHub. Original source: | |
21 | # https://github.com/lemire/FrameOfReference/blob/146948b6058a976bc7767262ad3a2ce201486b93/scripts/turbopacking64.py | |
22 | ||
23 | # Usage: | |
24 | # python bpacking64_codegen.py > bpacking64_default.h | |
25 | ||
26 | def howmany(bit): | |
27 | """ how many values are we going to pack? """ | |
28 | return 32 | |
29 | ||
30 | ||
31 | def howmanywords(bit): | |
32 | return (howmany(bit) * bit + 63)//64 | |
33 | ||
34 | ||
35 | def howmanybytes(bit): | |
36 | return (howmany(bit) * bit + 7)//8 | |
37 | ||
38 | ||
39 | print('''// Licensed to the Apache Software Foundation (ASF) under one | |
40 | // or more contributor license agreements. See the NOTICE file | |
41 | // distributed with this work for additional information | |
42 | // regarding copyright ownership. The ASF licenses this file | |
43 | // to you under the Apache License, Version 2.0 (the | |
44 | // "License"); you may not use this file except in compliance | |
45 | // with the License. You may obtain a copy of the License at | |
46 | // | |
47 | // http://www.apache.org/licenses/LICENSE-2.0 | |
48 | // | |
49 | // Unless required by applicable law or agreed to in writing, | |
50 | // software distributed under the License is distributed on an | |
51 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
52 | // KIND, either express or implied. See the License for the | |
53 | // specific language governing permissions and limitations | |
54 | // under the License. | |
55 | ||
56 | // This file was generated by script which is modified from its original version in GitHub. | |
57 | // Original source: | |
58 | // https://github.com/lemire/FrameOfReference/blob/master/scripts/turbopacking64.py | |
59 | // The original copyright notice follows. | |
60 | ||
61 | // This code is released under the | |
62 | // Apache License Version 2.0 http://www.apache.org/licenses/. | |
63 | // (c) Daniel Lemire 2013 | |
64 | ||
65 | #pragma once | |
66 | ||
67 | #include "arrow/util/bit_util.h" | |
68 | #include "arrow/util/ubsan.h" | |
69 | ||
70 | namespace arrow { | |
71 | namespace internal { | |
72 | ''') | |
73 | ||
74 | ||
75 | print("inline const uint8_t* unpack0_64(const uint8_t* in, uint64_t* out) {") | |
76 | print(" for(int k = 0; k < {0} ; k += 1) {{".format(howmany(0))) | |
77 | print(" out[k] = 0;") | |
78 | print(" }") | |
79 | print(" return in;") | |
80 | print("}") | |
81 | ||
82 | for bit in range(1, 65): | |
83 | print("") | |
84 | print( | |
85 | "inline const uint8_t* unpack{0}_64(const uint8_t* in, uint64_t* out) {{".format(bit)) | |
86 | ||
87 | if(bit < 64): | |
88 | print(" const uint64_t mask = {0}ULL;".format((1 << bit)-1)) | |
89 | maskstr = " & mask" | |
90 | if (bit == 64): | |
91 | maskstr = "" # no need | |
92 | ||
93 | for k in range(howmanywords(bit)-1): | |
94 | print(" uint64_t w{0} = util::SafeLoadAs<uint64_t>(in);".format(k)) | |
95 | print(" w{0} = arrow::BitUtil::FromLittleEndian(w{0});".format(k)) | |
96 | print(" in += 8;".format(k)) | |
97 | k = howmanywords(bit) - 1 | |
98 | if (bit % 2 == 0): | |
99 | print(" uint64_t w{0} = util::SafeLoadAs<uint64_t>(in);".format(k)) | |
100 | print(" w{0} = arrow::BitUtil::FromLittleEndian(w{0});".format(k)) | |
101 | print(" in += 8;".format(k)) | |
102 | else: | |
103 | print(" uint64_t w{0} = util::SafeLoadAs<uint32_t>(in);".format(k)) | |
104 | print(" w{0} = arrow::BitUtil::FromLittleEndian(w{0});".format(k)) | |
105 | print(" in += 4;".format(k)) | |
106 | ||
107 | for j in range(howmany(bit)): | |
108 | firstword = j * bit // 64 | |
109 | secondword = (j * bit + bit - 1)//64 | |
110 | firstshift = (j*bit) % 64 | |
111 | firstshiftstr = " >> {0}".format(firstshift) | |
112 | if(firstshift == 0): | |
113 | firstshiftstr = "" # no need | |
114 | if(firstword == secondword): | |
115 | if(firstshift + bit == 64): | |
116 | print(" out[{0}] = w{1}{2};".format( | |
117 | j, firstword, firstshiftstr, firstshift)) | |
118 | else: | |
119 | print(" out[{0}] = (w{1}{2}){3};".format( | |
120 | j, firstword, firstshiftstr, maskstr)) | |
121 | else: | |
122 | secondshift = (64-firstshift) | |
123 | print(" out[{0}] = ((w{1}{2}) | (w{3} << {4})){5};".format( | |
124 | j, firstword, firstshiftstr, firstword+1, secondshift, maskstr)) | |
125 | print("") | |
126 | print(" return in;") | |
127 | print("}") | |
128 | ||
129 | print(''' | |
130 | } // namespace internal | |
131 | } // namespace arrow''') |