@@ -67,6 +67,61 @@ namespace Simd
6767 hiCount += hiCountStride;
6868 }
6969 }
70+
71+ SIMD_INLINE svuint8_t AdjustLo (const svbool_t & mask, const svuint8_t & count, const svuint8_t & value,
72+ const svuint8_t & threshold, const svuint8_t & _1)
73+ {
74+ svuint8_t dec = svand_u8_z (svcmpgt_u8 (mask, count, threshold), _1, _1);
75+ svuint8_t inc = svand_u8_z (svcmplt_u8 (mask, count, threshold), _1, _1);
76+ return svqsub_u8 (svqadd_u8 (value, inc), dec);
77+ }
78+
79+ SIMD_INLINE svuint8_t AdjustHi (const svbool_t & mask, const svuint8_t & count, const svuint8_t & value,
80+ const svuint8_t & threshold, const svuint8_t & _1)
81+ {
82+ svuint8_t inc = svand_u8_z (svcmpgt_u8 (mask, count, threshold), _1, _1);
83+ svuint8_t dec = svand_u8_z (svcmplt_u8 (mask, count, threshold), _1, _1);
84+ return svqsub_u8 (svqadd_u8 (value, inc), dec);
85+ }
86+
87+ SIMD_INLINE void BackgroundAdjustRange (uint8_t * loCount, uint8_t * loValue, uint8_t * hiCount, uint8_t * hiValue,
88+ const svuint8_t & threshold, const svuint8_t & _1, const svuint8_t & _0, const svbool_t & mask)
89+ {
90+ svuint8_t _loCount = svld1_u8 (mask, loCount);
91+ svuint8_t _loValue = svld1_u8 (mask, loValue);
92+ svuint8_t _hiCount = svld1_u8 (mask, hiCount);
93+ svuint8_t _hiValue = svld1_u8 (mask, hiValue);
94+
95+ svst1_u8 (mask, loValue, AdjustLo (mask, _loCount, _loValue, threshold, _1));
96+ svst1_u8 (mask, hiValue, AdjustHi (mask, _hiCount, _hiValue, threshold, _1));
97+ svst1_u8 (mask, loCount, _0);
98+ svst1_u8 (mask, hiCount, _0);
99+ }
100+
101+ void BackgroundAdjustRange (uint8_t * loCount, size_t loCountStride, size_t width, size_t height,
102+ uint8_t * loValue, size_t loValueStride, uint8_t * hiCount, size_t hiCountStride,
103+ uint8_t * hiValue, size_t hiValueStride, uint8_t threshold)
104+ {
105+ size_t A = svlen (svuint8_t ());
106+ size_t widthA = AlignLo (width, A);
107+ const svbool_t body = svptrue_b8 ();
108+ const svbool_t tail = svwhilelt_b8 (widthA, width);
109+ svuint8_t _threshold = svdup_n_u8 (threshold);
110+ svuint8_t _1 = svdup_n_u8 (1 );
111+ svuint8_t _0 = svdup_n_u8 (0 );
112+ for (size_t row = 0 ; row < height; ++row)
113+ {
114+ size_t col = 0 ;
115+ for (; col < widthA; col += A)
116+ BackgroundAdjustRange (loCount + col, loValue + col, hiCount + col, hiValue + col, _threshold, _1, _0, body);
117+ if (widthA < width)
118+ BackgroundAdjustRange (loCount + col, loValue + col, hiCount + col, hiValue + col, _threshold, _1, _0, tail);
119+ loValue += loValueStride;
120+ hiValue += hiValueStride;
121+ loCount += loCountStride;
122+ hiCount += hiCountStride;
123+ }
124+ }
70125 }
71126#endif
72127}
0 commit comments