[Encoder] Add an SSE4.2 implementation of WelsGetNonZeroCount
Showing the changes to test/encoder/EncUT_EncoderMbAux.cpp (1 of 4 files). Show all
Unified · Split
| @@ -269,26 +269,43 @@ GENERATE_UT_FOR_COPY (16, 8, WelsCopy16x8NotAligned_sse2); · 268 unmodified lines | |||
| 269 | GENERATE_UT_FOR_COPY (16, 16, WelsCopy16x16NotAligned_sse2); | 269 | GENERATE_UT_FOR_COPY (16, 16, WelsCopy16x16NotAligned_sse2); |
| 270 | GENERATE_UT_FOR_COPY (16, 16, WelsCopy16x16_sse2); | 270 | GENERATE_UT_FOR_COPY (16, 16, WelsCopy16x16_sse2); |
| 271 | #endif | 271 | #endif |
| 272 | TEST (EncodeMbAuxTest, WelsGetNoneZeroCount_c) { | 272 | |
| 273 | namespace { | ||
| 274 | |||
| 275 | void TestGetNoneZeroCount (PGetNoneZeroCountFunc func) { | ||
| 273 | ENFORCE_STACK_ALIGN_1D (int16_t, pLevel, 16, 16); | 276 | ENFORCE_STACK_ALIGN_1D (int16_t, pLevel, 16, 16); |
| 274 | int32_t result = 0; | 277 | const int num_test_runs = 1000; |
| 275 | for (int i = 0; i < 16; i++) { | 278 | for (int run = 0; run < num_test_runs; run++) { |
| 276 | pLevel[i] = (rand() & 0x07) - 4; | 279 | const bool all_zero = run == 0; |
| 277 | if (pLevel[i]) result ++; | 280 | const bool all_nonzero = run == 1; |
| 281 | int result = 0; | ||
| 282 | for (int i = 0; i < 16; i++) { | ||
| 283 | const int r = rand(); | ||
| 284 | if (all_zero) | ||
| 285 | pLevel[i] = 0; | ||
| 286 | else if (all_nonzero) | ||
| 287 | pLevel[i] = r % 0xFFFF - 0x8000 ? r % 0xFFFF - 0x8000 : 0x7FFF; | ||
| 288 | else | ||
| 289 | pLevel[i] = (r >> 16 & 1) * ((r & 0xFFFF) - 0x8000); | ||
| 290 | result += pLevel[i] != 0; | ||
| 291 | } | ||
| 292 | const int32_t nnz = func (pLevel); | ||
| 293 | EXPECT_EQ (nnz, result); | ||
| 278 | } | 294 | } |
| 279 | int32_t nnz = WelsGetNoneZeroCount_c (pLevel); | 295 | } |
| 280 | EXPECT_EQ (nnz, result); | 296 | |
| 297 | } // anon ns. | ||
| 298 | |||
| 299 | TEST (EncodeMbAuxTest, WelsGetNoneZeroCount_c) { | ||
| 300 | TestGetNoneZeroCount (WelsGetNoneZeroCount_c); | ||
| 281 | } | 301 | } |
| 282 | #ifdef X86_ASM | 302 | #ifdef X86_ASM |
| 283 | TEST (EncodeMbAuxTest, WelsGetNoneZeroCount_sse2) { | 303 | TEST (EncodeMbAuxTest, WelsGetNoneZeroCount_sse2) { |
| 284 | ENFORCE_STACK_ALIGN_1D (int16_t, pLevel, 16, 16); | 304 | TestGetNoneZeroCount (WelsGetNoneZeroCount_sse2); |
| 285 | int32_t result = 0; | 305 | } |
| 286 | for (int i = 0; i < 16; i++) { | 306 | TEST (EncodeMbAuxTest, WelsGetNoneZeroCount_sse42) { |
| 287 | pLevel[i] = (rand() & 0x07) - 4; | 307 | if (WelsCPUFeatureDetect (0) & WELS_CPU_SSE42) |
| 288 | if (pLevel[i]) result ++; | 308 | TestGetNoneZeroCount (WelsGetNoneZeroCount_sse42); |
| 289 | } | ||
| 290 | int32_t nnz = WelsGetNoneZeroCount_sse2 (pLevel); | ||
| 291 | EXPECT_EQ (nnz, result); | ||
| 292 | } | 309 | } |
| 293 | #endif | 310 | #endif |
| 294 | #define WELS_ABS_LC(a) ((sign ^ (int32_t)(a)) - sign) | 311 | #define WELS_ABS_LC(a) ((sign ^ (int32_t)(a)) - sign) |