From b51c8b91d2952869a780665b480db886f6907792 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Fri, 9 Jun 2023 15:55:48 +0200 Subject: [PATCH] JFConversionFixedPoint: More SIMD improvement (but Intel only!) --- jungfrau/JFConversionFixedPoint.cpp | 68 +++++++++++++---------------- 1 file changed, 30 insertions(+), 38 deletions(-) diff --git a/jungfrau/JFConversionFixedPoint.cpp b/jungfrau/JFConversionFixedPoint.cpp index 50b7067e..09b3d7b3 100644 --- a/jungfrau/JFConversionFixedPoint.cpp +++ b/jungfrau/JFConversionFixedPoint.cpp @@ -51,7 +51,9 @@ void JFConversionFixedPoint::Setup(const JFModuleGainCalibration &gain_calibrati inline int32_t jf_round(int32_t in) { const int32_t half = (1L << (FIXED_PRECISION-1)); - if (in > 0) + if (in > INT16_MAX * (1L << FIXED_PRECISION)) + return INT16_MAX * (1L << FIXED_PRECISION); + else if (in > 0) return in + half; else return in - half; @@ -65,44 +67,34 @@ void JFConversionFixedPoint::ConvertModule(int16_t *dest, const uint16_t *source auto pedestal_g1_aligned = std::assume_aligned<64>(pedestal_g1); auto pedestal_g2_aligned = std::assume_aligned<64>(pedestal_g2); - - for (int line = 0; line < RAW_MODULE_LINES; line++) { - for (int col = 0; col < RAW_MODULE_COLS; col++) { - int i = col + line * RAW_MODULE_COLS; - int32_t adc = source[i] & 0x3fff; - int32_t val = (adc - pedestal_g0_aligned[i]) * gain_g0_aligned[i]; - dest[i] = static_cast(jf_round(val) / (1L << FIXED_PRECISION)); - } - - for (int col = 0; col < RAW_MODULE_COLS; col++) { - int i = col + line * RAW_MODULE_COLS; - uint16_t gainbits = source[i] & 0xc000; - int32_t adc = source[i] & 0x3fff; - - int32_t val = (adc - pedestal_g1_aligned[i]) * gain_g1_aligned[i]; - if (gainbits == 0x4000) - dest[i] = static_cast(jf_round(val) / (1L << FIXED_PRECISION)); - } - - for (int col = 0; col < RAW_MODULE_COLS; col++) { - int i = col + line * RAW_MODULE_COLS; - uint16_t gainbits = source[i] & 0xc000; - int32_t adc = source[i] & 0x3fff; - - int32_t val = (adc - pedestal_g2_aligned[i]) * gain_g2_aligned[i]; - - if (gainbits == 0xc000) - dest[i] = static_cast(jf_round(val) / (1L << FIXED_PRECISION)); - } - #pragma ivdep - for (int col = 0; col < RAW_MODULE_COLS; col++) { - int i = col + line * RAW_MODULE_COLS; - if (source[i] == 0xc000) - dest[i] = INT16_MAX; - if (source[i] == 0xffff) - dest[i] = INT16_MIN; - } + for (int64_t i = 0; i < RAW_MODULE_SIZE; i++) { + int32_t adc = source[i] & 0x3fff; + uint16_t gainbits = source[i] & 0xc000; + + int32_t val = (adc - pedestal_g0_aligned[i]) * gain_g0_aligned[i]; + int32_t val_g1 = (adc - pedestal_g1_aligned[i]) * gain_g1_aligned[i]; + int32_t val_g2 = (adc - pedestal_g2_aligned[i]) * gain_g2_aligned[i]; + + dest[i] = static_cast(jf_round(val) / (1L << FIXED_PRECISION)); + + if (gainbits == 0x4000) + dest[i] = static_cast(jf_round(val_g1) / (1L << FIXED_PRECISION)); + + if (gainbits == 0xc000) + dest[i] = static_cast(jf_round(val_g2) / (1L << FIXED_PRECISION)); + + if (source[i] == 0x4000) + dest[i] = INT16_MIN; + + if (source[i] == 0x8000) + dest[i] = INT16_MIN; + + if (source[i] == 0xc000) + dest[i] = INT16_MAX; + + if (source[i] == 0xffff) + dest[i] = INT16_MIN; } }