Skip to content

Commit f31cd6f

Browse files
committed
Address reviewer comments
1 parent ad687e1 commit f31cd6f

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

cpp/src/arrow/util/bpacking_scalar_codegen.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# https://github.com/lemire/FrameOfReference/blob/146948b6058a976bc7767262ad3a2ce201486b93/scripts/turbopacking64.py
2222

2323
# Usage:
24-
# python bpacking64_codegen.py > bpacking64_default_internal.h
24+
# python bpacking_scalar_codegen.py > bpacking_scalar_generated_internal.h
2525

2626

2727
import dataclasses
@@ -44,15 +44,6 @@
4444
// KIND, either express or implied. See the License for the
4545
// specific language governing permissions and limitations
4646
// under the License.
47-
48-
// This file was generated by script which is modified from its original version in GitHub.
49-
// Original source:
50-
// https://github.com/lemire/FrameOfReference/blob/master/scripts/turbopacking64.py
51-
// The original copyright notice follows.
52-
53-
// This code is released under the
54-
// Apache License Version 2.0 http://www.apache.org/licenses/.
55-
// (c) Daniel Lemire 2013
5647
"""
5748

5849
HEADER = """
@@ -90,6 +81,7 @@ def out_bit_width(self) -> int:
9081
return 8
9182
elif self.out_type.startswith("uint"):
9283
return int(self.out_type.removeprefix("uint").removesuffix("_t"))
84+
raise NotImplementedError(f"Unsupported type {self.out_type}")
9385

9486
@property
9587
def out_byte_width(self) -> int:
@@ -111,17 +103,21 @@ def print_struct_declaration(self):
111103
print(f"struct {self.struct_name};")
112104

113105
@property
114-
def howmany(self) -> int:
115-
"""How many values are we going to pack?"""
106+
def total_in_values(self) -> int:
107+
"""How many values are we going to unpack?"""
116108
if self.smart_halve:
117109
return self.out_bit_width // 2
118110
return self.out_bit_width
119111

120-
def howmanywords(self, bit: int) -> int:
121-
return (self.howmany * bit + self.out_bit_width - 1) // self.out_bit_width
112+
def total_out_values(self, bit: int) -> int:
113+
return (
114+
self.total_in_values * bit + self.out_bit_width - 1
115+
) // self.out_bit_width
122116

123-
def howmanybytes(self, bit: int) -> int:
124-
return (self.howmany * bit + self.out_byte_width - 1) // self.out_byte_width
117+
def total_out_bytes(self, bit: int) -> int:
118+
return (
119+
self.total_in_values * bit + self.out_byte_width - 1
120+
) // self.out_byte_width
125121

126122
def print_unpack_k(self, bit: int) -> None:
127123
print(
@@ -135,13 +131,13 @@ def print_unpack_k(self, bit: int) -> None:
135131
print()
136132
maskstr = " & mask"
137133

138-
for k in range(self.howmanywords(bit) - 1):
134+
for k in range(self.total_out_values(bit) - 1):
139135
print(
140136
f" const auto w{k} = LoadInt<{self.out_type}>("
141137
f"in + {k} * {self.out_byte_width});"
142138
)
143139

144-
k = self.howmanywords(bit) - 1
140+
k = self.total_out_values(bit) - 1
145141
use_smart_halving = self.smart_halve and bit % 2 == 1
146142
if use_smart_halving:
147143
print(
@@ -154,7 +150,7 @@ def print_unpack_k(self, bit: int) -> None:
154150
f"in + {k} * {self.out_byte_width});"
155151
)
156152

157-
for j in range(self.howmany):
153+
for j in range(self.total_in_values):
158154
firstword = j * bit // self.out_bit_width
159155
secondword = (j * bit + bit - 1) // self.out_bit_width
160156
firstshift = (j * bit) % self.out_bit_width
@@ -176,18 +172,20 @@ def print_unpack_k(self, bit: int) -> None:
176172

177173
if use_smart_halving:
178174
print(
179-
f" return in + ({self.howmanywords(bit) - 1} * {self.out_byte_width}"
175+
f" return in + ({self.total_out_values(bit) - 1} * {self.out_byte_width}"
180176
f" + {self.out_byte_width // 2});"
181177
)
182178
else:
183-
print(f" return in + ({self.howmanywords(bit)} * {self.out_byte_width});")
179+
print(
180+
f" return in + ({self.total_out_values(bit)} * {self.out_byte_width});"
181+
)
184182
print(" }")
185183

186184
def print_struct_k(self, bit: int) -> None:
187185
print("template<>")
188186
print(f"struct {self.struct_specialization(bit)} {{")
189187
print()
190-
print(f" static constexpr int kValuesUnpacked = {self.howmany};")
188+
print(f" static constexpr int kValuesUnpacked = {self.total_in_values};")
191189
print()
192190
self.print_unpack_k(bit)
193191
print("};")

0 commit comments

Comments
 (0)