Skip to content

Commit 38e34c4

Browse files
author
BuildTools
committed
Improvements to lookup table build script
1 parent e9ad8be commit 38e34c4

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

palette/build/lut.rs

+21-9
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ fn gen_into_linear_lut_u8(writer: &mut File, entries: &[LutEntryU8]) {
193193
}
194194

195195
let table_name = format!("{fn_type_uppercase}_U8_TO_F64");
196-
writeln!(writer, "pub const {table_name}: [f64; {table_size}] = [").unwrap();
196+
writeln!(writer, "const {table_name}: [f64; {table_size}] = [").unwrap();
197197
writer.write_all(&table).unwrap();
198198
writeln!(writer, "];").unwrap();
199199

@@ -222,7 +222,7 @@ fn gen_into_linear_lut_u8(writer: &mut File, entries: &[LutEntryU8]) {
222222
}
223223

224224
#[cfg(not(feature = "float_lut"))]
225-
pub fn gen_into_linear_lut_u8(_writer: &mut File, _entries: &[LutEntryU8]) {}
225+
fn gen_into_linear_lut_u8(_writer: &mut File, _entries: &[LutEntryU8]) {}
226226

227227
#[cfg(feature = "float_lut16")]
228228
fn gen_into_linear_lut_u16(writer: &mut File, entries: &[LutEntryU16]) {
@@ -250,7 +250,7 @@ fn gen_into_linear_lut_u16(writer: &mut File, entries: &[LutEntryU16]) {
250250
}
251251

252252
let table_name = format!("{fn_type_uppercase}_U16_TO_F64");
253-
writeln!(writer, "pub const {table_name}: [f64; {table_size}] = [").unwrap();
253+
writeln!(writer, "static {table_name}: [f64; {table_size}] = [").unwrap();
254254
writer.write_all(&table).unwrap();
255255
writeln!(writer, "];").unwrap();
256256

@@ -342,7 +342,7 @@ fn gen_from_linear_lut_u8(writer: &mut File, entries: &[LutEntryU8]) {
342342
}
343343

344344
let table_name = format!("TO_{fn_type_uppercase}_U8");
345-
writeln!(writer, "pub const {table_name}: [u32; {table_size}] = [").unwrap();
345+
writeln!(writer, "const {table_name}: [u32; {table_size}] = [").unwrap();
346346
writer.write_all(&table).unwrap();
347347
writeln!(writer, "\n];").unwrap();
348348

@@ -476,7 +476,7 @@ fn gen_from_linear_lut_u16(writer: &mut File, entries: &[LutEntryU16]) {
476476
}
477477

478478
let table_name = format!("TO_{fn_type_uppercase}_U16");
479-
writeln!(writer, "pub const {table_name}: [u64; {table_size}] = [").unwrap();
479+
writeln!(writer, "const {table_name}: [u64; {table_size}] = [").unwrap();
480480
writer.write_all(&table).unwrap();
481481
writeln!(writer, "\n];").unwrap();
482482

@@ -555,9 +555,21 @@ fn gen_from_linear_lut_u16(writer: &mut File, entries: &[LutEntryU16]) {
555555
\n\t\t\tunsafe {{ *{table_name}.get_unchecked(i) }}\
556556
\n\t\t}};\
557557
\n\t\tlet bias = (entry >> 32) << 17;\
558-
\n\t\tlet scale = entry & 0xffff_ffff;\
559-
\n\n\t\tlet t = (input_bits as u64 >> {man_shift}) & 0xffff;\
560-
\n\t\tlet res = (bias + scale * t) >> 32;\
558+
\n\t\tlet scale = entry & 0xffff_ffff;"
559+
).unwrap();
560+
if man_shift == 0 {
561+
writeln!(writer, "\n\t\tlet t = input_bits as u64 & 0xffff;").unwrap();
562+
} else {
563+
writeln!(
564+
writer,
565+
"\n\t\tlet t = (input_bits as u64 >> {man_shift}) & 0xffff;"
566+
)
567+
.unwrap();
568+
}
569+
writeln!(
570+
writer,
571+
"\
572+
\t\tlet res = (bias + scale * t) >> 32;\
561573
\n\t\t#[cfg(test)]\
562574
\n\t\t{{\
563575
\n\t\t\tdebug_assert!(res < 65536, \"{{}}\", res);\
@@ -573,4 +585,4 @@ fn gen_from_linear_lut_u16(writer: &mut File, entries: &[LutEntryU16]) {
573585
}
574586

575587
#[cfg(not(feature = "fast_uint_lut16"))]
576-
fn gen_from_linear_lut_u16(_writer: &mut File, entries: &[LutEntryU16]) {}
588+
fn gen_from_linear_lut_u16(_writer: &mut File, _entries: &[LutEntryU16]) {}

0 commit comments

Comments
 (0)