From 1930bd2c6eb645259fd05d0e796bdbf049735789 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Sat, 3 Jun 2023 22:49:30 +0200 Subject: [PATCH] JFConversionFixedPoint: Minor performance improvement --- jungfrau/JFConversionFixedPoint.cpp | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/jungfrau/JFConversionFixedPoint.cpp b/jungfrau/JFConversionFixedPoint.cpp index 4da70ce1..0f77194a 100644 --- a/jungfrau/JFConversionFixedPoint.cpp +++ b/jungfrau/JFConversionFixedPoint.cpp @@ -69,38 +69,35 @@ void JFConversionFixedPoint::ConvertLine(int16_t *dest, const uint16_t *source, for (int i = 0; i < RAW_MODULE_COLS; i++) { uint16_t gainbits = source[i] & 0xc000; int32_t adc = source[i] & 0x3fff; - int32_t val = 0; - - bool overflow = false; - bool wrong = false; - - if ((source[i] == 0x4000) || (source[i] == 0xffff)) wrong = true; - else if (source[i] == 0xc000) overflow = true; + int32_t val = INT32_MIN; switch (gainbits) { case 0: [[likely]] - val = jf_round((adc - pedestal_g0_aligned[i + line * RAW_MODULE_COLS]) * gain_g0_aligned[i + line * RAW_MODULE_COLS]); + val = (adc - pedestal_g0_aligned[i + line * RAW_MODULE_COLS]) * gain_g0_aligned[i + line * RAW_MODULE_COLS]; break; case 0x4000: - val = jf_round((adc - pedestal_g1_aligned[i + line * RAW_MODULE_COLS]) * gain_g1_aligned[i + line * RAW_MODULE_COLS]); + if (source[i] != 0x4000) + val = (adc - pedestal_g1_aligned[i + line * RAW_MODULE_COLS]) * gain_g1_aligned[i + line * RAW_MODULE_COLS]; break; case 0xc000: - val = jf_round((adc - pedestal_g2_aligned[i + line * RAW_MODULE_COLS]) * gain_g2_aligned[i + line * RAW_MODULE_COLS]); + if (source[i] == 0xc000) + val = INT32_MAX; + else if (source[i] != 0xffff) + val = (adc - pedestal_g2_aligned[i + line * RAW_MODULE_COLS]) * gain_g2_aligned[i + line * RAW_MODULE_COLS]; break; default: - wrong = true; break; } - if (wrong || (val <= INT16_MIN * (1L << FIXED_PRECISION))) + if (val <= INT16_MIN * (1L << FIXED_PRECISION)) [[unlikely]] dest[i] = INT16_MIN; - else if (overflow || (val >= INT16_MAX * (1L << FIXED_PRECISION))) + else if (val >= INT16_MAX * (1L << FIXED_PRECISION)) [[unlikely]] dest[i] = INT16_MAX; else - dest[i] = static_cast(val / (1L << FIXED_PRECISION)); + dest[i] = static_cast(jf_round(val)/ (1L << FIXED_PRECISION)); } }