Showing the changes to test/encoder/EncUT_EncoderMbAux.cpp (1 of 2 files). Show all
Unified · Split
| @@ -0,0 +1,494 @@ | |||
| 1 | #include<gtest/gtest.h> | ||
| 2 | #include<stdlib.h> | ||
| 3 | #include<time.h> | ||
| 4 | #include "ls_defines.h" | ||
| 5 | #include "encode_mb_aux.h" | ||
| 6 | #include "wels_common_basis.h" | ||
| 7 | |||
| 8 | using namespace WelsSVCEnc; | ||
| 9 | |||
| 10 | #define ALLOC_MEMORY(type, name, num) type* name = (type*)cMemoryAlign.WelsMalloc(num*sizeof(type), #name); | ||
| 11 | #define FREE_MEMORY(name) cMemoryAlign.WelsFree(name, #name); | ||
| 12 | TEST(EncodeMbAuxTest, TestScan_4x4_ac_c) { | ||
| 13 | CMemoryAlign cMemoryAlign(0); | ||
| 14 | ALLOC_MEMORY(int16_t, iLevel, 16); | ||
| 15 | ALLOC_MEMORY(int16_t, iDctA, 16); | ||
| 16 | ALLOC_MEMORY(int16_t, iDctB, 16); | ||
| 17 | srand((unsigned int)time(NULL)); | ||
| 18 | for(int i=0;i<16;i++) { | ||
| 19 | iDctA[i]=rand()%256+1; | ||
| 20 | iDctB[i]=iDctA[i]; | ||
| 21 | } | ||
| 22 | WelsScan4x4Ac_c( iLevel, iDctA ); | ||
| 23 | EXPECT_EQ(iLevel[0],iDctB[1]); | ||
| 24 | EXPECT_EQ(iLevel[1],iDctB[4]); | ||
| 25 | EXPECT_EQ(iLevel[2],iDctB[8]); | ||
| 26 | EXPECT_EQ(iLevel[3],iDctB[5]); | ||
| 27 | EXPECT_EQ(iLevel[4],iDctB[2]); | ||
| 28 | EXPECT_EQ(iLevel[5],iDctB[3]); | ||
| 29 | EXPECT_EQ(iLevel[6],iDctB[6]); | ||
| 30 | EXPECT_EQ(iLevel[7],iDctB[9]); | ||
| 31 | EXPECT_EQ(iLevel[8],iDctB[12]); | ||
| 32 | EXPECT_EQ(iLevel[9],iDctB[13]); | ||
| 33 | EXPECT_EQ(iLevel[10],iDctB[10]); | ||
| 34 | EXPECT_EQ(iLevel[11],iDctB[7]); | ||
| 35 | EXPECT_EQ(iLevel[12],iDctB[11]); | ||
| 36 | EXPECT_EQ(iLevel[13],iDctB[14]); | ||
| 37 | EXPECT_EQ(iLevel[14],iDctB[15]); | ||
| 38 | EXPECT_EQ(iLevel[15],0); | ||
| 39 | FREE_MEMORY(iLevel); | ||
| 40 | FREE_MEMORY(iDctA); | ||
| 41 | FREE_MEMORY(iDctB); | ||
| 42 | } | ||
| 43 | |||
| 44 | #ifdef X86_ASM | ||
| 45 | TEST(EncodeMbAuxTest, TestScan_4x4_ac_sse2) { | ||
| 46 | CMemoryAlign cMemoryAlign(0); | ||
| 47 | ALLOC_MEMORY(int16_t, iLevelA, 16); | ||
| 48 | ALLOC_MEMORY(int16_t, iLevelB, 16); | ||
| 49 | ALLOC_MEMORY(int16_t, iDct, 16); | ||
| 50 | srand((unsigned int)time(NULL)); | ||
| 51 | for(int i=0;i<16;i++) { | ||
| 52 | iDct[i]=rand()%256+1; | ||
| 53 | } | ||
| 54 | WelsScan4x4Ac_c( iLevelA, iDct ); | ||
| 55 | WelsScan4x4Ac_sse2( iLevelB, iDct ); | ||
| 56 | for(int j=0; j<16;j++) | ||
| 57 | EXPECT_EQ(iLevelA[j], iLevelB[j]); | ||
| 58 | FREE_MEMORY(iLevelA); | ||
| 59 | FREE_MEMORY(iLevelB); | ||
| 60 | FREE_MEMORY(iDct); | ||
| 61 | } | ||
| 62 | TEST(EncodeMbAuxTest, WelsScan4x4DcAc_sse2) { | ||
| 63 | CMemoryAlign cMemoryAlign(0); | ||
| 64 | ALLOC_MEMORY(int16_t, iLevelA, 32); | ||
| 65 | ALLOC_MEMORY(int16_t, iLevelB, 32); | ||
| 66 | ALLOC_MEMORY(int16_t, iDct, 32); | ||
| 67 | srand((unsigned int)time(NULL)); | ||
| 68 | for(int i = 0; i < 32; i++) | ||
| 69 | iDct[i] = (rand() & 32767) - 16384; | ||
| 70 | WelsScan4x4DcAc_sse2(iLevelA, iDct); | ||
| 71 | WelsScan4x4DcAc_c(iLevelB, iDct); | ||
| 72 | for(int i = 0; i < 16; i++) | ||
| 73 | EXPECT_EQ(iLevelA[i], iLevelB[i]); | ||
| 74 | FREE_MEMORY(iLevelA); | ||
| 75 | FREE_MEMORY(iLevelB); | ||
| 76 | FREE_MEMORY(iDct); | ||
| 77 | } | ||
| 78 | #endif | ||
| 79 | TEST(EncodeMbAuxTest, TestScan_4x4_dcc) { | ||
| 80 | CMemoryAlign cMemoryAlign(0); | ||
| 81 | ALLOC_MEMORY(int16_t, iLevel, 16); | ||
| 82 | ALLOC_MEMORY(int16_t, iDctA, 16); | ||
| 83 | ALLOC_MEMORY(int16_t, iDctB, 16); | ||
| 84 | srand((unsigned int)time(NULL)); | ||
| 85 | for(int i=0;i<16;i++) | ||
| 86 | iDctA[i] = iDctB[i] = rand()%256+1; | ||
| 87 | WelsScan4x4Dc( iLevel, iDctA ); | ||
| 88 | EXPECT_EQ(iLevel[0],iDctB[0]); | ||
| 89 | EXPECT_EQ(iLevel[1],iDctB[1]); | ||
| 90 | EXPECT_EQ(iLevel[2],iDctB[4]); | ||
| 91 | EXPECT_EQ(iLevel[3],iDctB[8]); | ||
| 92 | EXPECT_EQ(iLevel[4],iDctB[5]); | ||
| 93 | EXPECT_EQ(iLevel[5],iDctB[2]); | ||
| 94 | EXPECT_EQ(iLevel[6],iDctB[3]); | ||
| 95 | EXPECT_EQ(iLevel[7],iDctB[6]); | ||
| 96 | EXPECT_EQ(iLevel[8],iDctB[9]); | ||
| 97 | EXPECT_EQ(iLevel[9],iDctB[12]); | ||
| 98 | EXPECT_EQ(iLevel[10],iDctB[13]); | ||
| 99 | EXPECT_EQ(iLevel[11],iDctB[10]); | ||
| 100 | EXPECT_EQ(iLevel[12],iDctB[7]); | ||
| 101 | EXPECT_EQ(iLevel[13],iDctB[11]); | ||
| 102 | EXPECT_EQ(iLevel[14],iDctB[14]); | ||
| 103 | EXPECT_EQ(iLevel[15],iDctB[15]); | ||
| 104 | FREE_MEMORY(iLevel); | ||
| 105 | FREE_MEMORY(iDctA); | ||
| 106 | FREE_MEMORY(iDctB); | ||
| 107 | } | ||
| 108 | static inline void PixelSubWH( int16_t *iDiff, int iSize, uint8_t *pPix1, int iStride1, uint8_t *pPix2, int iStride2 ) { | ||
| 109 | int y, x; | ||
| 110 | for( y = 0; y < iSize; y++ ) { | ||
| 111 | for( x = 0; x < iSize; x++ ) | ||
| 112 | iDiff[x + y*iSize] = pPix1[x] - pPix2[x]; | ||
| 113 | pPix1 += iStride1; | ||
| 114 | pPix2 += iStride2; | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | #define FENC_STRIDE 16 | ||
| 119 | #define FDEC_STRIDE 32 | ||
| 120 | static void Sub4x4DctAnchor( int16_t iDct[4][4], uint8_t *pPix1, uint8_t *pPix2 ) { | ||
| 121 | int16_t iDiff[4][4]; | ||
| 122 | int16_t tmp[4][4]; | ||
| 123 | int i; | ||
| 124 | PixelSubWH( (int16_t*)iDiff, 4, pPix1, FENC_STRIDE, pPix2, FDEC_STRIDE ); | ||
| 125 | for( i = 0; i < 4; i++ ) { | ||
| 126 | const int a03 = iDiff[i][0] + iDiff[i][3]; | ||
| 127 | const int a12 = iDiff[i][1] + iDiff[i][2]; | ||
| 128 | const int s03 = iDiff[i][0] - iDiff[i][3]; | ||
| 129 | const int s12 = iDiff[i][1] - iDiff[i][2]; | ||
| 130 | tmp[0][i] = a03 + a12; | ||
| 131 | tmp[1][i] = 2*s03 + s12; | ||
| 132 | tmp[2][i] = a03 - a12; | ||
| 133 | tmp[3][i] = s03 - 2*s12; | ||
| 134 | } | ||
| 135 | for( i = 0; i < 4; i++ ) { | ||
| 136 | const int a03 = tmp[i][0] + tmp[i][3]; | ||
| 137 | const int a12 = tmp[i][1] + tmp[i][2]; | ||
| 138 | const int s03 = tmp[i][0] - tmp[i][3]; | ||
| 139 | const int s12 = tmp[i][1] - tmp[i][2]; | ||
| 140 | iDct[i][0] = a03 + a12; | ||
| 141 | iDct[i][1] = 2*s03 + s12; | ||
| 142 | iDct[i][2] = a03 - a12; | ||
| 143 | iDct[i][3] = s03 - 2*s12; | ||
| 144 | } | ||
| 145 | } | ||
| 146 | |||
| 147 | static void Sub8x8DctAnchor( int16_t iDct[4][4][4], uint8_t *pPix1, uint8_t *pPix2 ) { | ||
| 148 | Sub4x4DctAnchor( iDct[0], &pPix1[0], &pPix2[0] ); | ||
| 149 | Sub4x4DctAnchor( iDct[1], &pPix1[4], &pPix2[4] ); | ||
| 150 | Sub4x4DctAnchor( iDct[2], &pPix1[4*FENC_STRIDE+0], &pPix2[4*FDEC_STRIDE+0] ); | ||
| 151 | Sub4x4DctAnchor( iDct[3], &pPix1[4*FENC_STRIDE+4], &pPix2[4*FDEC_STRIDE+4] ); | ||
| 152 | } | ||
| 153 | TEST(EncodeMbAuxTest, WelsDctT4_c) { | ||
| 154 | int16_t iDctRef[4][4]; | ||
| 155 | uint8_t uiPix1[16*FENC_STRIDE], uiPix2[16*FDEC_STRIDE]; | ||
| 156 | int16_t iDct[16]; | ||
| 157 | srand((unsigned int)time(NULL)); | ||
| 158 | for(int i = 0; i < 4; i++) | ||
| 159 | for(int j = 0; j < 4; j++) | ||
| 160 | uiPix1[i*FENC_STRIDE+j] = uiPix2[i*FDEC_STRIDE+j] = rand() & 255; | ||
| 161 | Sub4x4DctAnchor(iDctRef, uiPix1, uiPix2); | ||
| 162 | WelsDctT4_c(iDct, uiPix1, FENC_STRIDE, uiPix2, FDEC_STRIDE); | ||
| 163 | for(int i = 0; i < 4; i++) | ||
| 164 | for(int j = 0; j < 4; j++) | ||
| 165 | EXPECT_EQ(iDctRef[j][i], iDct[i*4+j]); | ||
| 166 | } | ||
| 167 | TEST(EncodeMbAuxTest, WelsDctFourT4_c) { | ||
| 168 | int16_t iDctRef[4][4][4]; uint8_t uiPix1[16*FENC_STRIDE], uiPix2[16*FDEC_STRIDE]; | ||
| 169 | int16_t iDct[16*4]; | ||
| 170 | srand((unsigned int)time(NULL)); | ||
| 171 | for(int i = 0; i < 8; i++) | ||
| 172 | for(int j = 0; j < 8; j++) | ||
| 173 | uiPix1[i*FENC_STRIDE+j] = uiPix2[i*FDEC_STRIDE+j] = rand() & 255; | ||
| 174 | Sub8x8DctAnchor(iDctRef, uiPix1, uiPix2); | ||
| 175 | WelsDctFourT4_c(iDct, uiPix1, FENC_STRIDE, uiPix2, FDEC_STRIDE); | ||
| 176 | for(int k = 0; k < 4; k++) | ||
| 177 | for(int i = 0; i < 4; i++) | ||
| 178 | for(int j = 0; j < 4; j++) | ||
| 179 | EXPECT_EQ(iDctRef[k][j][i], iDct[k*16+i*4+j]); | ||
| 180 | } | ||
| 181 | |||
| 182 | #ifdef X86_ASM | ||
| 183 | TEST(EncodeMbAuxTest, WelsDctT4_mmx) { | ||
| 184 | int16_t iDctC[16], iDctM[16]; | ||
| 185 | uint8_t uiPix1[16*FENC_STRIDE], uiPix2[16*FDEC_STRIDE]; | ||
| 186 | srand((unsigned int)time(NULL)); | ||
| 187 | for(int i = 0; i < 4; i++) | ||
| 188 | for(int j = 0; j < 4; j++) | ||
| 189 | uiPix1[i*FENC_STRIDE+j] = uiPix2[i*FDEC_STRIDE+j] = rand() & 255; | ||
| 190 | WelsDctT4_c(iDctC, uiPix1, FENC_STRIDE, uiPix2, FDEC_STRIDE); | ||
| 191 | WelsDctT4_mmx(iDctM, uiPix1, FENC_STRIDE, uiPix2, FDEC_STRIDE); | ||
| 192 | for(int i = 0; i < 16; i++) | ||
| 193 | EXPECT_EQ(iDctC[i], iDctM[i]); | ||
| 194 | } | ||
| 195 | |||
| 196 | TEST(EncodeMbAuxTest, WelsDctFourT4_sse2) { | ||
| 197 | CMemoryAlign cMemoryAlign(0); | ||
| 198 | ALLOC_MEMORY(uint8_t, uiPix1, 16*FENC_STRIDE); | ||
| 199 | ALLOC_MEMORY(uint8_t, uiPix2, 16*FDEC_STRIDE); | ||
| 200 | ALLOC_MEMORY(int16_t, iDctC, 16*4); | ||
| 201 | ALLOC_MEMORY(int16_t, iDctS, 16*4); | ||
| 202 | srand((unsigned int)time(NULL)); | ||
| 203 | for(int i = 0; i < 8; i++) | ||
| 204 | for(int j = 0; j < 8; j++) | ||
| 205 | uiPix1[i*FENC_STRIDE+j] = uiPix2[i*FDEC_STRIDE+j] = rand() & 255; | ||
| 206 | WelsDctFourT4_c(iDctC, uiPix1, FENC_STRIDE, uiPix2, FDEC_STRIDE); | ||
| 207 | WelsDctFourT4_sse2(iDctS, uiPix1, FENC_STRIDE, uiPix2, FDEC_STRIDE); | ||
| 208 | for(int i = 0; i < 64; i++) | ||
| 209 | EXPECT_EQ(iDctC[i], iDctS[i]); | ||
| 210 | FREE_MEMORY(uiPix1); | ||
| 211 | FREE_MEMORY(uiPix2); | ||
| 212 | FREE_MEMORY(iDctC); | ||
| 213 | FREE_MEMORY(iDctS); | ||
| 214 | } | ||
| 215 | |||
| 216 | TEST(EncodeMbAuxTest, WelsCalculateSingleCtr4x4_sse2) { | ||
| 217 | CMemoryAlign cMemoryAlign(0); | ||
| 218 | ALLOC_MEMORY(int16_t, iDctC, 16); | ||
| 219 | ALLOC_MEMORY(int16_t, iDctS, 16); | ||
| 220 | srand((unsigned int)time(NULL)); | ||
| 221 | for(int i = 0; i < 16; i++) | ||
| 222 | iDctC[i] = iDctS[i] = (rand() & 65535 ) - 32768; | ||
| 223 | WelsCalculateSingleCtr4x4_c(iDctC); | ||
| 224 | WelsCalculateSingleCtr4x4_sse2(iDctS); | ||
| 225 | for(int i = 0; i < 16; i++) | ||
| 226 | EXPECT_EQ(iDctC[i], iDctS[i]); | ||
| 227 | FREE_MEMORY(iDctC); | ||
| 228 | FREE_MEMORY(iDctS); | ||
| 229 | } | ||
| 230 | #endif | ||
| 231 | |||
| 232 | void copy(uint8_t *pDst, int32_t iDStride, uint8_t *pSrc, int32_t iSStride, int32_t iWidth, int32_t iHeight) { | ||
| 233 | for(int i = 0; i < iHeight; i++) | ||
| 234 | memcpy(pDst+i*iDStride, pSrc+i*iSStride, iWidth); | ||
| 235 | } | ||
| 236 | |||
| 237 | #define GENERATE_UT_FOR_COPY(width, height, function) \ | ||
| 238 | TEST(EncodeMbAuxTest, function) { \ | ||
| 239 | const int iSStride = 64; \ | ||
| 240 | const int iDStride = 64; \ | ||
| 241 | uint8_t _ref_src[64*64], _ref_dst[64*64], _dst[64*64]; \ | ||
| 242 | uint8_t *ref_src = (uint8_t*)((((unsigned long)(_ref_src + 15)) >> 4) << 4); \ | ||
| 243 | uint8_t *ref_dst = (uint8_t*)((((unsigned long)(_ref_dst + 15)) >> 4) << 4); \ | ||
| 244 | uint8_t *dst = (uint8_t*)((((unsigned long)(_dst + 15)) >> 4) << 4); \ | ||
| 245 | srand((unsigned int)time(NULL)); \ | ||
| 246 | for(int i = 0; i < height; i++) \ | ||
| 247 | for(int j = 0; j < width; j++) \ | ||
| 248 | ref_src[i*iSStride+j] = rand() & 255; \ | ||
| 249 | function(dst, iDStride, ref_src, iSStride); \ | ||
| 250 | copy(ref_dst, iDStride, ref_src, iSStride, width, height); \ | ||
| 251 | for(int i = 0; i < height; i++) \ | ||
| 252 | for(int j = 0; j < width; j++) \ | ||
| 253 | EXPECT_EQ(ref_dst[i*iDStride+j], dst[i*iDStride+j]); \ | ||
| 254 | } | ||
| 255 | |||
| 256 | GENERATE_UT_FOR_COPY(4,4, WelsCopy4x4); | ||
| 257 | GENERATE_UT_FOR_COPY(8,8, WelsCopy8x8_c); | ||
| 258 | GENERATE_UT_FOR_COPY(8, 16, WelsCopy8x16_c); | ||
| 259 | GENERATE_UT_FOR_COPY(16, 8, WelsCopy16x8_c); | ||
| 260 | GENERATE_UT_FOR_COPY(16, 16, WelsCopy16x16_c); | ||
| 261 | #ifdef X86_ASM | ||
| 262 | GENERATE_UT_FOR_COPY(16, 8, WelsCopy16x8NotAligned_sse2); | ||
| 263 | GENERATE_UT_FOR_COPY(16, 16, WelsCopy16x16NotAligned_sse2); | ||
| 264 | GENERATE_UT_FOR_COPY(16, 16, WelsCopy16x16_sse2); | ||
| 265 | #endif | ||
| 266 | TEST(EncodeMbAuxTest, WelsGetNoneZeroCount_c) { | ||
| 267 | int16_t _iLevel[32]; | ||
| 268 | int16_t *pLevel = (int16_t*) (((((unsigned long)_iLevel) + 15) >> 4) << 4); | ||
| 269 | srand((unsigned int)time(NULL)); | ||
| 270 | int32_t result = 0; | ||
| 271 | for(int i = 0; i < 16; i++) { | ||
| 272 | pLevel[i] = (rand() & 0x07) - 4; | ||
| 273 | if(pLevel[i]) result ++; | ||
| 274 | } | ||
| 275 | int32_t nnz = WelsGetNoneZeroCount_c(pLevel); | ||
| 276 | EXPECT_EQ(nnz, result); | ||
| 277 | } | ||
| 278 | #ifdef X86_ASM | ||
| 279 | TEST(EncodeMbAuxTest, WelsGetNoneZeroCount_sse2) { | ||
| 280 | int16_t _iLevel[32]; | ||
| 281 | int16_t *pLevel = (int16_t*) (((((unsigned long)_iLevel) + 15) >> 4) << 4); | ||
| 282 | srand((unsigned int)time(NULL)); | ||
| 283 | int32_t result = 0; | ||
| 284 | for(int i = 0; i < 16; i++) { | ||
| 285 | pLevel[i] = (rand() & 0x07) - 4; | ||
| 286 | if(pLevel[i]) result ++; | ||
| 287 | } | ||
| 288 | int32_t nnz = WelsGetNoneZeroCount_sse2(pLevel); | ||
| 289 | EXPECT_EQ(nnz, result); | ||
| 290 | } | ||
| 291 | #endif | ||
| 292 | #define WELS_ABS_LC(a) ((sign ^ (int32_t)(a)) - sign) | ||
| 293 | #define NEW_QUANT(pDct, ff, mf) (((ff)+ WELS_ABS_LC(pDct))*(mf)) >>16 | ||
| 294 | #define WELS_NEW_QUANT(pDct,ff,mf) WELS_ABS_LC(NEW_QUANT(pDct, ff, mf)) | ||
| 295 | void WelsQuantFour4x4MaxAnchor(int16_t *pDct, int16_t* ff, int16_t *mf, int16_t *max) { | ||
| 296 | int32_t i, j, k, sign; | ||
| 297 | int16_t max_abs; | ||
| 298 | for( k = 0; k < 4; k++) { | ||
| 299 | max_abs = 0; | ||
| 300 | for( i = 0; i < 16; i++ ) { | ||
| 301 | j = i & 0x07; | ||
| 302 | sign = WELS_SIGN(pDct[i]); | ||
| 303 | pDct[i] = NEW_QUANT(pDct[i], ff[j], mf[j]); | ||
| 304 | if( max_abs < pDct[i]) max_abs = pDct[i]; | ||
| 305 | pDct[i] = WELS_ABS_LC(pDct[i]); | ||
| 306 | } | ||
| 307 | pDct += 16; | ||
| 308 | max[k] = max_abs; | ||
| 309 | } | ||
| 310 | } | ||
| 311 | TEST(EncodeMbAuxTest, WelsQuantFour4x4Max_c) { | ||
| 312 | int16_t ff[8], mf[8]; | ||
| 313 | int16_t iDctA[64], iMaxA[16]; | ||
| 314 | int16_t iDctC[64], iMaxC[16]; | ||
| 315 | srand((unsigned int)time(NULL)); | ||
| 316 | for(int i = 0; i < 8; i++) { | ||
| 317 | ff[i] = rand() & 32767; | ||
| 318 | mf[i] = rand() & 32767; | ||
| 319 | } | ||
| 320 | for(int i = 0; i < 64; i++) | ||
| 321 | iDctA[i] = iDctC[i] = (rand() & 65535) - 32767; | ||
| 322 | WelsQuantFour4x4MaxAnchor(iDctA, ff, mf, iMaxA); | ||
| 323 | WelsQuantFour4x4Max_c(iDctC, ff, mf, iMaxC); | ||
| 324 | for(int i = 0; i < 64; i++) | ||
| 325 | EXPECT_EQ(iDctA[i],iDctC[i]); | ||
| 326 | for(int i = 0; i < 4; i++) | ||
| 327 | EXPECT_EQ(iMaxA[i], iMaxC[i]); | ||
| 328 | } | ||
| 329 | #ifdef X86_ASM | ||
| 330 | TEST(EncodeMbAuxTest, WelsQuantFour4x4Max_sse2) { | ||
| 331 | CMemoryAlign cMemoryAlign(0); | ||
| 332 | ALLOC_MEMORY(int16_t, ff, 8); | ||
| 333 | ALLOC_MEMORY(int16_t, mf, 8); | ||
| 334 | ALLOC_MEMORY(int16_t, iDctC, 64); | ||
| 335 | ALLOC_MEMORY(int16_t, iDctS, 64); | ||
| 336 | ALLOC_MEMORY(int16_t, iMaxC, 16); | ||
| 337 | ALLOC_MEMORY(int16_t, iMaxS, 16); | ||
| 338 | srand((unsigned int)time(NULL)); | ||
| 339 | for(int i = 0; i < 8; i++) { | ||
| 340 | ff[i] = rand() & 32767; | ||
| 341 | mf[i] = rand() & 32767; | ||
| 342 | } | ||
| 343 | for(int i = 0; i < 64; i++) | ||
| 344 | iDctC[i] = iDctS[i] = (rand() & 65535) - 32767; | ||
| 345 | WelsQuantFour4x4Max_c(iDctC, ff, mf, iMaxC); | ||
| 346 | WelsQuantFour4x4Max_sse2(iDctS, ff, mf, iMaxS); | ||
| 347 | for(int i = 0; i < 64; i++) | ||
| 348 | EXPECT_EQ(iDctC[i], iDctS[i]); | ||
| 349 | for(int i = 0; i < 4; i++) | ||
| 350 | EXPECT_EQ(iMaxC[i], iMaxS[i]); | ||
| 351 | FREE_MEMORY(ff); | ||
| 352 | FREE_MEMORY(mf); | ||
| 353 | FREE_MEMORY(iDctC); | ||
| 354 | FREE_MEMORY(iDctS); | ||
| 355 | FREE_MEMORY(iMaxC); | ||
| 356 | FREE_MEMORY(iMaxS); | ||
| 357 | } | ||
| 358 | #endif | ||
| 359 | int32_t WelsHadamardQuant2x2SkipAnchor(int16_t *rs, int16_t ff, int16_t mf) { | ||
| 360 | int16_t pDct[4], s[4]; | ||
| 361 | int16_t threshold = ((1<<16)-1)/mf - ff; | ||
| 362 | s[0] = rs[0] + rs[32]; | ||
| 363 | s[1] = rs[0] - rs[32]; | ||
| 364 | s[2] = rs[16] + rs[48]; | ||
| 365 | s[3] = rs[16] - rs[48]; | ||
| 366 | pDct[0] = s[0] + s[2]; | ||
| 367 | pDct[1] = s[0] - s[2]; | ||
| 368 | pDct[2] = s[1] + s[3]; | ||
| 369 | pDct[3] = s[1] - s[3]; | ||
| 370 | return ((WELS_ABS(pDct[0]) > threshold) || (WELS_ABS(pDct[1]) > threshold) || (WELS_ABS(pDct[2]) > threshold) || (WELS_ABS(pDct[3]) > threshold)); | ||
| 371 | } | ||
| 372 | |||
| 373 | TEST(EncodeMbAuxTest, WelsHadamardQuant2x2Skip_c) { | ||
| 374 | int16_t iRS[64]; | ||
| 375 | int16_t ff, mf; | ||
| 376 | srand((unsigned int)time(NULL)); | ||
| 377 | for(int i = 0; i < 64; i++) | ||
| 378 | iRS[i] = (rand() & 32767) - 16384; | ||
| 379 | ff = rand() & 32767; | ||
| 380 | mf = rand() & 32767; | ||
| 381 | EXPECT_EQ(WelsHadamardQuant2x2Skip_c(iRS, ff, mf), WelsHadamardQuant2x2SkipAnchor(iRS, ff, mf)); | ||
| 382 | } | ||
| 383 | |||
| 384 | int32_t WelsHadamardQuant2x2Anchor(int16_t *rs, const int16_t ff, int16_t mf, int16_t * pDct, int16_t * block) { | ||
| 385 | int16_t s[4]; | ||
| 386 | int32_t sign, i, dc_nzc = 0; | ||
| 387 | |||
| 388 | s[0] = rs[0] + rs[32]; | ||
| 389 | s[1] = rs[0] - rs[32]; | ||
| 390 | s[2] = rs[16] + rs[48]; | ||
| 391 | s[3] = rs[16] - rs[48]; | ||
| 392 | |||
| 393 | rs[0] = 0; | ||
| 394 | rs[16] = 0; | ||
| 395 | rs[32] = 0; | ||
| 396 | rs[48] = 0; | ||
| 397 | |||
| 398 | pDct[0] = s[0] + s[2]; | ||
| 399 | pDct[1] = s[0] - s[2]; | ||
| 400 | pDct[2] = s[1] + s[3]; | ||
| 401 | pDct[3] = s[1] - s[3]; | ||
| 402 | |||
| 403 | sign = WELS_SIGN(pDct[0]); | ||
| 404 | pDct[0] = WELS_NEW_QUANT(pDct[0], ff, mf); | ||
| 405 | sign = WELS_SIGN(pDct[1]); | ||
| 406 | pDct[1] = WELS_NEW_QUANT(pDct[1], ff, mf); | ||
| 407 | sign = WELS_SIGN(pDct[2]); | ||
| 408 | pDct[2] = WELS_NEW_QUANT(pDct[2], ff, mf); | ||
| 409 | sign = WELS_SIGN(pDct[3]); | ||
| 410 | pDct[3] = WELS_NEW_QUANT(pDct[3], ff, mf); | ||
| 411 | ST64( block, LD64(pDct) ); | ||
| 412 | for(i=0; i<4; i++) | ||
| 413 | dc_nzc += (block[i] != 0); | ||
| 414 | return dc_nzc; | ||
| 415 | } | ||
| 416 | |||
| 417 | TEST(EncodeMbAuxTest, WelsHadamardQuant2x2_c) { | ||
| 418 | int16_t iRsC[64], iRsA[64]; | ||
| 419 | int16_t ff, mf; | ||
| 420 | int16_t iBlockA[16], iBlockC[16], iDctA[4], iDctC[4]; | ||
| 421 | srand((unsigned int)time(NULL)); | ||
| 422 | for(int i = 0; i < 64; i++) | ||
| 423 | iRsA[i] = iRsC[i] = (rand() & 32767) - 16384; | ||
| 424 | for(int i = 0; i < 4; i++) | ||
| 425 | iDctA[i] = iDctC[i] = (rand() & 32767) - 16384; | ||
| 426 | ff = rand() & 32767; | ||
| 427 | mf = rand() & 32767; | ||
| 428 | |||
| 429 | int32_t iRetA = WelsHadamardQuant2x2Anchor(iRsA, ff, mf, iDctA, iBlockA); | ||
| 430 | int32_t iRetC = WelsHadamardQuant2x2_c(iRsC, ff, mf, iDctC, iBlockC); | ||
| 431 | EXPECT_EQ(iRetA, iRetC); | ||
| 432 | for(int i = 0; i < 4; i++) | ||
| 433 | EXPECT_EQ(iDctA[i], iDctC[i]); | ||
| 434 | } | ||
| 435 | |||
| 436 | void WelsHadamardT4DcAnchor( int16_t *pLumaDc, int16_t *pDct) { | ||
| 437 | int32_t p[16], s[4]; | ||
| 438 | int32_t i, iIdx; | ||
| 439 | for(i = 0 ; i < 16 ; i +=4) { | ||
| 440 | iIdx = ((i&0x08) << 4) +((i&0x04) << 3); | ||
| 441 | s[0] = pDct[iIdx ] + pDct[iIdx+80]; | ||
| 442 | s[3] = pDct[iIdx ] - pDct[iIdx+80]; | ||
| 443 | s[1] = pDct[iIdx+16] + pDct[iIdx+64]; | ||
| 444 | s[2] = pDct[iIdx+16] - pDct[iIdx+64]; | ||
| 445 | p[i ] = s[0] + s[1]; | ||
| 446 | p[i+2] = s[0] - s[1]; | ||
| 447 | p[i+1] = s[3] + s[2]; | ||
| 448 | p[i+3] = s[3] - s[2]; | ||
| 449 | } | ||
| 450 | for(i = 0 ; i < 4 ; i ++) { | ||
| 451 | s[0] = p[i ] + p[i+12]; | ||
| 452 | s[3] = p[i ] - p[i+12]; | ||
| 453 | s[1] = p[i+4] + p[i+ 8]; | ||
| 454 | s[2] = p[i+4] - p[i+ 8]; | ||
| 455 | pLumaDc[i ] = WELS_CLIP3((s[0] + s[1] + 1) >> 1, -32768, 32767); | ||
| 456 | pLumaDc[i+8 ] = WELS_CLIP3((s[0] - s[1] + 1) >> 1, -32768, 32767); | ||
| 457 | pLumaDc[i+4 ] = WELS_CLIP3((s[3] + s[2] + 1) >> 1, -32768, 32767); | ||
| 458 | pLumaDc[i+12] = WELS_CLIP3((s[3] - s[2] + 1) >> 1, -32768, 32767); | ||
| 459 | } | ||
| 460 | } | ||
| 461 | TEST(EncodeMbAuxTest, WelsHadamardT4Dc_c) { | ||
| 462 | CMemoryAlign cMemoryAlign(0); | ||
| 463 | ALLOC_MEMORY(int16_t, iDct, 128*16); | ||
| 464 | ALLOC_MEMORY(int16_t, iLumaDcR, 16); | ||
| 465 | ALLOC_MEMORY(int16_t, iLumaDcC, 16); | ||
| 466 | srand((unsigned int)time(NULL)); | ||
| 467 | for(int i = 0; i < 128*16; i++) | ||
| 468 | iDct[i] = (rand() & 32767) - 16384; | ||
| 469 | WelsHadamardT4DcAnchor(iLumaDcR, iDct); | ||
| 470 | WelsHadamardT4Dc_c(iLumaDcC, iDct); | ||
| 471 | for(int i = 0;i < 16; i++) | ||
| 472 | EXPECT_EQ(iLumaDcR[i], iLumaDcC[i]); | ||
| 473 | FREE_MEMORY(iDct); | ||
| 474 | FREE_MEMORY(iLumaDcR); | ||
| 475 | FREE_MEMORY(iLumaDcC); | ||
| 476 | } | ||
| 477 | #ifdef X86_ASM | ||
| 478 | TEST(EncodeMbAuxTest, WelsHadamardT4Dc_sse2) { | ||
| 479 | CMemoryAlign cMemoryAlign(0); | ||
| 480 | ALLOC_MEMORY(int16_t, iDct, 128*16); | ||
| 481 | ALLOC_MEMORY(int16_t, iLumaDcC, 16); | ||
| 482 | ALLOC_MEMORY(int16_t, iLumaDcS, 16); | ||
| 483 | srand((unsigned int)time(NULL)); | ||
| 484 | for(int i = 0; i < 128*16; i++) | ||
| 485 | iDct[i] = (rand() & 32767) - 16384; | ||
| 486 | WelsHadamardT4Dc_c(iLumaDcC, iDct); | ||
| 487 | WelsHadamardT4Dc_sse2(iLumaDcS, iDct); | ||
| 488 | for(int i = 0;i < 16; i++) | ||
| 489 | EXPECT_EQ(iLumaDcC[i], iLumaDcS[i]); | ||
| 490 | FREE_MEMORY(iDct); | ||
| 491 | FREE_MEMORY(iLumaDcC); | ||
| 492 | FREE_MEMORY(iLumaDcS); | ||
| 493 | } | ||
| 494 | #endif | ||