From 5b11a6f842865e13005ebfd7c4cff38c8670f852 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Fri, 9 Jun 2023 18:17:14 +0200 Subject: [PATCH] Revert "JFConversionFixedPoint: More SIMD improvement (but Intel only!)" This reverts commit b51c8b91d2952869a780665b480db886f6907792. --- jungfrau/JFConversionFixedPoint.cpp | 68 ++++++++++++++++------------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/jungfrau/JFConversionFixedPoint.cpp b/jungfrau/JFConversionFixedPoint.cpp index 09b3d7b3..50b7067e 100644 --- a/jungfrau/JFConversionFixedPoint.cpp +++ b/jungfrau/JFConversionFixedPoint.cpp @@ -51,9 +51,7 @@ 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 > INT16_MAX * (1L << FIXED_PRECISION)) - return INT16_MAX * (1L << FIXED_PRECISION); - else if (in > 0) + if (in > 0) return in + half; else return in - half; @@ -67,34 +65,44 @@ 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 (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; + 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; + } } }