From 394381397878d598f4ed5066e9ba3d4919041cf2 Mon Sep 17 00:00:00 2001 From: Eric Schneider Date: Thu, 28 Dec 2023 00:32:34 -0500 Subject: [PATCH] Macro-ize D_shift arrays --- adder-codec-core/Cargo.toml | 1 + adder-codec-core/src/lib.rs | 409 ++---------------------------------- 2 files changed, 18 insertions(+), 392 deletions(-) diff --git a/adder-codec-core/Cargo.toml b/adder-codec-core/Cargo.toml index c6349015..541a4222 100644 --- a/adder-codec-core/Cargo.toml +++ b/adder-codec-core/Cargo.toml @@ -38,6 +38,7 @@ rustdct = "0.7.1" serde = { version = "1.0.140", features = ["derive"] } serde_bytes = "0.11.6" serde_json = "1.0" +seq-macro = "0.3.5" thiserror = "1.0.38" transpose = "0.2.2" ndarray = "0.15.6" diff --git a/adder-codec-core/src/lib.rs b/adder-codec-core/src/lib.rs index 5fe044bb..aea74288 100644 --- a/adder-codec-core/src/lib.rs +++ b/adder-codec-core/src/lib.rs @@ -214,399 +214,24 @@ pub enum PixelMultiMode { /// Precision for maximum intensity representable with allowed [`D`] values pub type UDshift = u128; +use seq_macro::seq; + +macro_rules! make_d_shift_array { + ($name:ident, $type:ty) => { + seq!(N in 0..=127 { + pub const $name: [$type; 128] = [ + #( + (1_u128 << N) as $type, + )* + ]; + }); + }; +} + /// Array for computing the intensity to integrate for a given [`D`] value -pub const D_SHIFT: [UDshift; 128] = [ - 1 << 0, - 1 << 1, - 1 << 2, - 1 << 3, - 1 << 4, - 1 << 5, - 1 << 6, - 1 << 7, - 1 << 8, - 1 << 9, - 1 << 10, - 1 << 11, - 1 << 12, - 1 << 13, - 1 << 14, - 1 << 15, - 1 << 16, - 1 << 17, - 1 << 18, - 1 << 19, - 1 << 20, - 1 << 21, - 1 << 22, - 1 << 23, - 1 << 24, - 1 << 25, - 1 << 26, - 1 << 27, - 1 << 28, - 1 << 29, - 1 << 30, - 1 << 31, - 1 << 32, - 1 << 33, - 1 << 34, - 1 << 35, - 1 << 36, - 1 << 37, - 1 << 38, - 1 << 39, - 1 << 40, - 1 << 41, - 1 << 42, - 1 << 43, - 1 << 44, - 1 << 45, - 1 << 46, - 1 << 47, - 1 << 48, - 1 << 49, - 1 << 50, - 1 << 51, - 1 << 52, - 1 << 53, - 1 << 54, - 1 << 55, - 1 << 56, - 1 << 57, - 1 << 58, - 1 << 59, - 1 << 60, - 1 << 61, - 1 << 62, - 1 << 63, - 1 << 64, - 1 << 65, - 1 << 66, - 1 << 67, - 1 << 68, - 1 << 69, - 1 << 70, - 1 << 71, - 1 << 72, - 1 << 73, - 1 << 74, - 1 << 75, - 1 << 76, - 1 << 77, - 1 << 78, - 1 << 79, - 1 << 80, - 1 << 81, - 1 << 82, - 1 << 83, - 1 << 84, - 1 << 85, - 1 << 86, - 1 << 87, - 1 << 88, - 1 << 89, - 1 << 90, - 1 << 91, - 1 << 92, - 1 << 93, - 1 << 94, - 1 << 95, - 1 << 96, - 1 << 97, - 1 << 98, - 1 << 99, - 1 << 100, - 1 << 101, - 1 << 102, - 1 << 103, - 1 << 104, - 1 << 105, - 1 << 106, - 1 << 107, - 1 << 108, - 1 << 109, - 1 << 110, - 1 << 111, - 1 << 112, - 1 << 113, - 1 << 114, - 1 << 115, - 1 << 116, - 1 << 117, - 1 << 118, - 1 << 119, - 1 << 120, - 1 << 121, - 1 << 122, - 1 << 123, - 1 << 124, - 1 << 125, - 1 << 126, - 1 << 127, -]; - -pub const D_SHIFT_F64: [f64; 128] = [ - (1_u128 << 0) as f64, - (1_u128 << 1) as f64, - (1_u128 << 2) as f64, - (1_u128 << 3) as f64, - (1_u128 << 4) as f64, - (1_u128 << 5) as f64, - (1_u128 << 6) as f64, - (1_u128 << 7) as f64, - (1_u128 << 8) as f64, - (1_u128 << 9) as f64, - (1_u128 << 10) as f64, - (1_u128 << 11) as f64, - (1_u128 << 12) as f64, - (1_u128 << 13) as f64, - (1_u128 << 14) as f64, - (1_u128 << 15) as f64, - (1_u128 << 16) as f64, - (1_u128 << 17) as f64, - (1_u128 << 18) as f64, - (1_u128 << 19) as f64, - (1_u128 << 20) as f64, - (1_u128 << 21) as f64, - (1_u128 << 22) as f64, - (1_u128 << 23) as f64, - (1_u128 << 24) as f64, - (1_u128 << 25) as f64, - (1_u128 << 26) as f64, - (1_u128 << 27) as f64, - (1_u128 << 28) as f64, - (1_u128 << 29) as f64, - (1_u128 << 30) as f64, - (1_u128 << 31) as f64, - (1_u128 << 32) as f64, - (1_u128 << 33) as f64, - (1_u128 << 34) as f64, - (1_u128 << 35) as f64, - (1_u128 << 36) as f64, - (1_u128 << 37) as f64, - (1_u128 << 38) as f64, - (1_u128 << 39) as f64, - (1_u128 << 40) as f64, - (1_u128 << 41) as f64, - (1_u128 << 42) as f64, - (1_u128 << 43) as f64, - (1_u128 << 44) as f64, - (1_u128 << 45) as f64, - (1_u128 << 46) as f64, - (1_u128 << 47) as f64, - (1_u128 << 48) as f64, - (1_u128 << 49) as f64, - (1_u128 << 50) as f64, - (1_u128 << 51) as f64, - (1_u128 << 52) as f64, - (1_u128 << 53) as f64, - (1_u128 << 54) as f64, - (1_u128 << 55) as f64, - (1_u128 << 56) as f64, - (1_u128 << 57) as f64, - (1_u128 << 58) as f64, - (1_u128 << 59) as f64, - (1_u128 << 60) as f64, - (1_u128 << 61) as f64, - (1_u128 << 62) as f64, - (1_u128 << 63) as f64, - (1_u128 << 64) as f64, - (1_u128 << 65) as f64, - (1_u128 << 66) as f64, - (1_u128 << 67) as f64, - (1_u128 << 68) as f64, - (1_u128 << 69) as f64, - (1_u128 << 70) as f64, - (1_u128 << 71) as f64, - (1_u128 << 72) as f64, - (1_u128 << 73) as f64, - (1_u128 << 74) as f64, - (1_u128 << 75) as f64, - (1_u128 << 76) as f64, - (1_u128 << 77) as f64, - (1_u128 << 78) as f64, - (1_u128 << 79) as f64, - (1_u128 << 80) as f64, - (1_u128 << 81) as f64, - (1_u128 << 82) as f64, - (1_u128 << 83) as f64, - (1_u128 << 84) as f64, - (1_u128 << 85) as f64, - (1_u128 << 86) as f64, - (1_u128 << 87) as f64, - (1_u128 << 88) as f64, - (1_u128 << 89) as f64, - (1_u128 << 90) as f64, - (1_u128 << 91) as f64, - (1_u128 << 92) as f64, - (1_u128 << 93) as f64, - (1_u128 << 94) as f64, - (1_u128 << 95) as f64, - (1_u128 << 96) as f64, - (1_u128 << 97) as f64, - (1_u128 << 98) as f64, - (1_u128 << 99) as f64, - (1_u128 << 100) as f64, - (1_u128 << 101) as f64, - (1_u128 << 102) as f64, - (1_u128 << 103) as f64, - (1_u128 << 104) as f64, - (1_u128 << 105) as f64, - (1_u128 << 106) as f64, - (1_u128 << 107) as f64, - (1_u128 << 108) as f64, - (1_u128 << 109) as f64, - (1_u128 << 110) as f64, - (1_u128 << 111) as f64, - (1_u128 << 112) as f64, - (1_u128 << 113) as f64, - (1_u128 << 114) as f64, - (1_u128 << 115) as f64, - (1_u128 << 116) as f64, - (1_u128 << 117) as f64, - (1_u128 << 118) as f64, - (1_u128 << 119) as f64, - (1_u128 << 120) as f64, - (1_u128 << 121) as f64, - (1_u128 << 122) as f64, - (1_u128 << 123) as f64, - (1_u128 << 124) as f64, - (1_u128 << 125) as f64, - (1_u128 << 126) as f64, - (1_u128 << 127) as f64, -]; - -pub const D_SHIFT_F32: [f32; 128] = [ - (1_u128 << 0) as f32, - (1_u128 << 1) as f32, - (1_u128 << 2) as f32, - (1_u128 << 3) as f32, - (1_u128 << 4) as f32, - (1_u128 << 5) as f32, - (1_u128 << 6) as f32, - (1_u128 << 7) as f32, - (1_u128 << 8) as f32, - (1_u128 << 9) as f32, - (1_u128 << 10) as f32, - (1_u128 << 11) as f32, - (1_u128 << 12) as f32, - (1_u128 << 13) as f32, - (1_u128 << 14) as f32, - (1_u128 << 15) as f32, - (1_u128 << 16) as f32, - (1_u128 << 17) as f32, - (1_u128 << 18) as f32, - (1_u128 << 19) as f32, - (1_u128 << 20) as f32, - (1_u128 << 21) as f32, - (1_u128 << 22) as f32, - (1_u128 << 23) as f32, - (1_u128 << 24) as f32, - (1_u128 << 25) as f32, - (1_u128 << 26) as f32, - (1_u128 << 27) as f32, - (1_u128 << 28) as f32, - (1_u128 << 29) as f32, - (1_u128 << 30) as f32, - (1_u128 << 31) as f32, - (1_u128 << 32) as f32, - (1_u128 << 33) as f32, - (1_u128 << 34) as f32, - (1_u128 << 35) as f32, - (1_u128 << 36) as f32, - (1_u128 << 37) as f32, - (1_u128 << 38) as f32, - (1_u128 << 39) as f32, - (1_u128 << 40) as f32, - (1_u128 << 41) as f32, - (1_u128 << 42) as f32, - (1_u128 << 43) as f32, - (1_u128 << 44) as f32, - (1_u128 << 45) as f32, - (1_u128 << 46) as f32, - (1_u128 << 47) as f32, - (1_u128 << 48) as f32, - (1_u128 << 49) as f32, - (1_u128 << 50) as f32, - (1_u128 << 51) as f32, - (1_u128 << 52) as f32, - (1_u128 << 53) as f32, - (1_u128 << 54) as f32, - (1_u128 << 55) as f32, - (1_u128 << 56) as f32, - (1_u128 << 57) as f32, - (1_u128 << 58) as f32, - (1_u128 << 59) as f32, - (1_u128 << 60) as f32, - (1_u128 << 61) as f32, - (1_u128 << 62) as f32, - (1_u128 << 63) as f32, - (1_u128 << 64) as f32, - (1_u128 << 65) as f32, - (1_u128 << 66) as f32, - (1_u128 << 67) as f32, - (1_u128 << 68) as f32, - (1_u128 << 69) as f32, - (1_u128 << 70) as f32, - (1_u128 << 71) as f32, - (1_u128 << 72) as f32, - (1_u128 << 73) as f32, - (1_u128 << 74) as f32, - (1_u128 << 75) as f32, - (1_u128 << 76) as f32, - (1_u128 << 77) as f32, - (1_u128 << 78) as f32, - (1_u128 << 79) as f32, - (1_u128 << 80) as f32, - (1_u128 << 81) as f32, - (1_u128 << 82) as f32, - (1_u128 << 83) as f32, - (1_u128 << 84) as f32, - (1_u128 << 85) as f32, - (1_u128 << 86) as f32, - (1_u128 << 87) as f32, - (1_u128 << 88) as f32, - (1_u128 << 89) as f32, - (1_u128 << 90) as f32, - (1_u128 << 91) as f32, - (1_u128 << 92) as f32, - (1_u128 << 93) as f32, - (1_u128 << 94) as f32, - (1_u128 << 95) as f32, - (1_u128 << 96) as f32, - (1_u128 << 97) as f32, - (1_u128 << 98) as f32, - (1_u128 << 99) as f32, - (1_u128 << 100) as f32, - (1_u128 << 101) as f32, - (1_u128 << 102) as f32, - (1_u128 << 103) as f32, - (1_u128 << 104) as f32, - (1_u128 << 105) as f32, - (1_u128 << 106) as f32, - (1_u128 << 107) as f32, - (1_u128 << 108) as f32, - (1_u128 << 109) as f32, - (1_u128 << 110) as f32, - (1_u128 << 111) as f32, - (1_u128 << 112) as f32, - (1_u128 << 113) as f32, - (1_u128 << 114) as f32, - (1_u128 << 115) as f32, - (1_u128 << 116) as f32, - (1_u128 << 117) as f32, - (1_u128 << 118) as f32, - (1_u128 << 119) as f32, - (1_u128 << 120) as f32, - (1_u128 << 121) as f32, - (1_u128 << 122) as f32, - (1_u128 << 123) as f32, - (1_u128 << 124) as f32, - (1_u128 << 125) as f32, - (1_u128 << 126) as f32, - (1_u128 << 127) as f32, -]; +make_d_shift_array!(D_SHIFT, UDshift); +make_d_shift_array!(D_SHIFT_F64, f64); +make_d_shift_array!(D_SHIFT_F32, f32); /// The maximum intensity representation for input data. Currently 255 for 8-bit framed input. pub const MAX_INTENSITY: f32 = 255.0; // TODO: make variable, dependent on input bit depth