| @@ -47,27 +47,27 @@ static int sad16_x2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size · 46 unmodified lines |
| 47 | 47 | sad = (vector unsigned int)vec_splat_u32(0); |
| 48 | 48 | for (i = 0; i < h; i++) { |
| 49 | 49 | /* Read unaligned pixels into our vectors. The vectors are as follows: |
| 50 | | − pix1v: pix1[0]-pix1[15] |
| 51 | | − pix2v: pix2[0]-pix2[15] pix2iv: pix2[1]-pix2[16] */ |
| 50 | + * pix1v: pix1[0] - pix1[15] |
| 51 | + * pix2v: pix2[0] - pix2[15] pix2iv: pix2[1] - pix2[16] */ |
| 52 | 52 | pix1v = vec_ld( 0, pix1); |
| 53 | 53 | pix2l = vec_ld( 0, pix2); |
| 54 | 54 | pix2r = vec_ld(16, pix2); |
| 55 | 55 | pix2v = vec_perm(pix2l, pix2r, perm1); |
| 56 | 56 | pix2iv = vec_perm(pix2l, pix2r, perm2); |
| 57 | 57 | |
| 58 | | − /* Calculate the average vector */ |
| 58 | + /* Calculate the average vector. */ |
| 59 | 59 | avgv = vec_avg(pix2v, pix2iv); |
| 60 | 60 | |
| 61 | | − /* Calculate a sum of abs differences vector */ |
| 61 | + /* Calculate a sum of abs differences vector. */ |
| 62 | 62 | t5 = vec_sub(vec_max(pix1v, avgv), vec_min(pix1v, avgv)); |
| 63 | 63 | |
| 64 | | − /* Add each 4 pixel group together and put 4 results into sad */ |
| 64 | + /* Add each 4 pixel group together and put 4 results into sad. */ |
| 65 | 65 | sad = vec_sum4s(t5, sad); |
| 66 | 66 | |
| 67 | 67 | pix1 += line_size; |
| 68 | 68 | pix2 += line_size; |
| 69 | 69 | } |
| 70 | | − /* Sum up the four partial sums, and put the result into s */ |
| 70 | + /* Sum up the four partial sums, and put the result into s. */ |
| 71 | 71 | sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero); |
| 72 | 72 | sumdiffs = vec_splat(sumdiffs, 3); |
| 73 | 73 | vec_ste(sumdiffs, 0, &s); |
| @@ -91,33 +91,33 @@ static int sad16_y2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size · 17 unmodified lines |
| 91 | 91 | sad = (vector unsigned int)vec_splat_u32(0); |
| 92 | 92 | |
| 93 | 93 | /* Due to the fact that pix3 = pix2 + line_size, the pix3 of one |
| 94 | | − iteration becomes pix2 in the next iteration. We can use this |
| 95 | | − fact to avoid a potentially expensive unaligned read, each |
| 96 | | − time around the loop. |
| 97 | | − Read unaligned pixels into our vectors. The vectors are as follows: |
| 98 | | − pix2v: pix2[0]-pix2[15] |
| 99 | | − Split the pixel vectors into shorts */ |
| 94 | + * iteration becomes pix2 in the next iteration. We can use this |
| 95 | + * fact to avoid a potentially expensive unaligned read, each |
| 96 | + * time around the loop. |
| 97 | + * Read unaligned pixels into our vectors. The vectors are as follows: |
| 98 | + * pix2v: pix2[0] - pix2[15] |
| 99 | + * Split the pixel vectors into shorts. */ |
| 100 | 100 | pix2l = vec_ld( 0, pix2); |
| 101 | 101 | pix2r = vec_ld(15, pix2); |
| 102 | 102 | pix2v = vec_perm(pix2l, pix2r, perm); |
| 103 | 103 | |
| 104 | 104 | for (i = 0; i < h; i++) { |
| 105 | 105 | /* Read unaligned pixels into our vectors. The vectors are as follows: |
| 106 | | − pix1v: pix1[0]-pix1[15] |
| 107 | | − pix3v: pix3[0]-pix3[15] */ |
| 106 | + * pix1v: pix1[0] - pix1[15] |
| 107 | + * pix3v: pix3[0] - pix3[15] */ |
| 108 | 108 | pix1v = vec_ld(0, pix1); |
| 109 | 109 | |
| 110 | 110 | pix2l = vec_ld( 0, pix3); |
| 111 | 111 | pix2r = vec_ld(15, pix3); |
| 112 | 112 | pix3v = vec_perm(pix2l, pix2r, perm); |
| 113 | 113 | |
| 114 | | − /* Calculate the average vector */ |
| 114 | + /* Calculate the average vector. */ |
| 115 | 115 | avgv = vec_avg(pix2v, pix3v); |
| 116 | 116 | |
| 117 | | − /* Calculate a sum of abs differences vector */ |
| 117 | + /* Calculate a sum of abs differences vector. */ |
| 118 | 118 | t5 = vec_sub(vec_max(pix1v, avgv), vec_min(pix1v, avgv)); |
| 119 | 119 | |
| 120 | | − /* Add each 4 pixel group together and put 4 results into sad */ |
| 120 | + /* Add each 4 pixel group together and put 4 results into sad. */ |
| 121 | 121 | sad = vec_sum4s(t5, sad); |
| 122 | 122 | |
| 123 | 123 | pix1 += line_size; |
| @@ -126,7 +126,7 @@ static int sad16_y2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size · 2 unmodified lines |
| 126 | 126 | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | | − /* Sum up the four partial sums, and put the result into s */ |
| 129 | + /* Sum up the four partial sums, and put the result into s. */ |
| 130 | 130 | sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero); |
| 131 | 131 | sumdiffs = vec_splat(sumdiffs, 3); |
| 132 | 132 | vec_ste(sumdiffs, 0, &s); |
| @@ -157,12 +157,12 @@ static int sad16_xy2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_siz · 24 unmodified lines |
| 157 | 157 | s = 0; |
| 158 | 158 | |
| 159 | 159 | /* Due to the fact that pix3 = pix2 + line_size, the pix3 of one |
| 160 | | − iteration becomes pix2 in the next iteration. We can use this |
| 161 | | − fact to avoid a potentially expensive unaligned read, as well |
| 162 | | − as some splitting, and vector addition each time around the loop. |
| 163 | | − Read unaligned pixels into our vectors. The vectors are as follows: |
| 164 | | − pix2v: pix2[0]-pix2[15] pix2iv: pix2[1]-pix2[16] |
| 165 | | − Split the pixel vectors into shorts */ |
| 160 | + * iteration becomes pix2 in the next iteration. We can use this |
| 161 | + * fact to avoid a potentially expensive unaligned read, as well |
| 162 | + * as some splitting, and vector addition each time around the loop. |
| 163 | + * Read unaligned pixels into our vectors. The vectors are as follows: |
| 164 | + * pix2v: pix2[0] - pix2[15] pix2iv: pix2[1] - pix2[16] |
| 165 | + * Split the pixel vectors into shorts. */ |
| 166 | 166 | pix2l = vec_ld( 0, pix2); |
| 167 | 167 | pix2r = vec_ld(16, pix2); |
| 168 | 168 | pix2v = vec_perm(pix2l, pix2r, perm1); |
| @@ -177,8 +177,8 @@ static int sad16_xy2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_siz · 8 unmodified lines |
| 177 | 177 | |
| 178 | 178 | for (i = 0; i < h; i++) { |
| 179 | 179 | /* Read unaligned pixels into our vectors. The vectors are as follows: |
| 180 | | − pix1v: pix1[0]-pix1[15] |
| 181 | | − pix3v: pix3[0]-pix3[15] pix3iv: pix3[1]-pix3[16] */ |
| 180 | + * pix1v: pix1[0] - pix1[15] |
| 181 | + * pix3v: pix3[0] - pix3[15] pix3iv: pix3[1] - pix3[16] */ |
| 182 | 182 | pix1v = vec_ld(0, pix1); |
| 183 | 183 | |
| 184 | 184 | pix2l = vec_ld( 0, pix3); |
| @@ -187,40 +187,40 @@ static int sad16_xy2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_siz · 2 unmodified lines |
| 187 | 187 | pix3iv = vec_perm(pix2l, pix2r, perm2); |
| 188 | 188 | |
| 189 | 189 | /* Note that AltiVec does have vec_avg, but this works on vector pairs |
| 190 | | − and rounds up. We could do avg(avg(a,b),avg(c,d)), but the rounding |
| 191 | | − would mean that, for example, avg(3,0,0,1) = 2, when it should be 1. |
| 192 | | − Instead, we have to split the pixel vectors into vectors of shorts, |
| 193 | | − and do the averaging by hand. */ |
| 190 | + * and rounds up. We could do avg(avg(a, b), avg(c, d)), but the |
| 191 | + * rounding would mean that, for example, avg(3, 0, 0, 1) = 2, when |
| 192 | + * it should be 1. Instead, we have to split the pixel vectors into |
| 193 | + * vectors of shorts and do the averaging by hand. */ |
| 194 | 194 | |
| 195 | | − /* Split the pixel vectors into shorts */ |
| 195 | + /* Split the pixel vectors into shorts. */ |
| 196 | 196 | pix3hv = (vector unsigned short) vec_mergeh(zero, pix3v); |
| 197 | 197 | pix3lv = (vector unsigned short) vec_mergel(zero, pix3v); |
| 198 | 198 | pix3ihv = (vector unsigned short) vec_mergeh(zero, pix3iv); |
| 199 | 199 | pix3ilv = (vector unsigned short) vec_mergel(zero, pix3iv); |
| 200 | 200 | |
| 201 | | − /* Do the averaging on them */ |
| 201 | + /* Do the averaging on them. */ |
| 202 | 202 | t3 = vec_add(pix3hv, pix3ihv); |
| 203 | 203 | t4 = vec_add(pix3lv, pix3ilv); |
| 204 | 204 | |
| 205 | 205 | avghv = vec_sr(vec_add(vec_add(t1, t3), two), two); |
| 206 | 206 | avglv = vec_sr(vec_add(vec_add(t2, t4), two), two); |
| 207 | 207 | |
| 208 | | − /* Pack the shorts back into a result */ |
| 208 | + /* Pack the shorts back into a result. */ |
| 209 | 209 | avgv = vec_pack(avghv, avglv); |
| 210 | 210 | |
| 211 | | − /* Calculate a sum of abs differences vector */ |
| 211 | + /* Calculate a sum of abs differences vector. */ |
| 212 | 212 | t5 = vec_sub(vec_max(pix1v, avgv), vec_min(pix1v, avgv)); |
| 213 | 213 | |
| 214 | | − /* Add each 4 pixel group together and put 4 results into sad */ |
| 214 | + /* Add each 4 pixel group together and put 4 results into sad. */ |
| 215 | 215 | sad = vec_sum4s(t5, sad); |
| 216 | 216 | |
| 217 | 217 | pix1 += line_size; |
| 218 | 218 | pix3 += line_size; |
| 219 | | − /* Transfer the calculated values for pix3 into pix2 */ |
| 219 | + /* Transfer the calculated values for pix3 into pix2. */ |
| 220 | 220 | t1 = t3; |
| 221 | 221 | t2 = t4; |
| 222 | 222 | } |
| 223 | | − /* Sum up the four partial sums, and put the result into s */ |
| 223 | + /* Sum up the four partial sums, and put the result into s. */ |
| 224 | 224 | sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero); |
| 225 | 225 | sumdiffs = vec_splat(sumdiffs, 3); |
| 226 | 226 | vec_ste(sumdiffs, 0, &s); |
| @@ -242,25 +242,25 @@ static int sad16_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, i · 15 unmodified lines |
| 242 | 242 | |
| 243 | 243 | |
| 244 | 244 | for (i = 0; i < h; i++) { |
| 245 | | − /* Read potentially unaligned pixels into t1 and t2 */ |
| 245 | + /* Read potentially unaligned pixels into t1 and t2. */ |
| 246 | 246 | vector unsigned char pix2l = vec_ld( 0, pix2); |
| 247 | 247 | vector unsigned char pix2r = vec_ld(15, pix2); |
| 248 | 248 | t1 = vec_ld(0, pix1); |
| 249 | 249 | t2 = vec_perm(pix2l, pix2r, perm); |
| 250 | 250 | |
| 251 | | − /* Calculate a sum of abs differences vector */ |
| 251 | + /* Calculate a sum of abs differences vector. */ |
| 252 | 252 | t3 = vec_max(t1, t2); |
| 253 | 253 | t4 = vec_min(t1, t2); |
| 254 | 254 | t5 = vec_sub(t3, t4); |
| 255 | 255 | |
| 256 | | − /* Add each 4 pixel group together and put 4 results into sad */ |
| 256 | + /* Add each 4 pixel group together and put 4 results into sad. */ |
| 257 | 257 | sad = vec_sum4s(t5, sad); |
| 258 | 258 | |
| 259 | 259 | pix1 += line_size; |
| 260 | 260 | pix2 += line_size; |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | | − /* Sum up the four partial sums, and put the result into s */ |
| 263 | + /* Sum up the four partial sums, and put the result into s. */ |
| 264 | 264 | sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero); |
| 265 | 265 | sumdiffs = vec_splat(sumdiffs, 3); |
| 266 | 266 | vec_ste(sumdiffs, 0, &s); |
| @@ -283,9 +283,9 @@ static int sad8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, in · 16 unmodified lines |
| 283 | 283 | sad = (vector unsigned int)vec_splat_u32(0); |
| 284 | 284 | |
| 285 | 285 | for (i = 0; i < h; i++) { |
| 286 | | − /* Read potentially unaligned pixels into t1 and t2 |
| 287 | | − Since we're reading 16 pixels, and actually only want 8, |
| 288 | | − mask out the last 8 pixels. The 0s don't change the sum. */ |
| 286 | + /* Read potentially unaligned pixels into t1 and t2. |
| 287 | + * Since we're reading 16 pixels, and actually only want 8, |
| 288 | + * mask out the last 8 pixels. The 0s don't change the sum. */ |
| 289 | 289 | vector unsigned char pix1l = vec_ld(0, pix1); |
| 290 | 290 | vector unsigned char pix1r = vec_ld(7, pix1); |
| 291 | 291 | vector unsigned char pix2l = vec_ld(0, pix2); |
| @@ -293,19 +293,19 @@ static int sad8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, in · 1 unmodified line |
| 293 | 293 | t1 = vec_and(vec_perm(pix1l, pix1r, perm1), permclear); |
| 294 | 294 | t2 = vec_and(vec_perm(pix2l, pix2r, perm2), permclear); |
| 295 | 295 | |
| 296 | | − /* Calculate a sum of abs differences vector */ |
| 296 | + /* Calculate a sum of abs differences vector. */ |
| 297 | 297 | t3 = vec_max(t1, t2); |
| 298 | 298 | t4 = vec_min(t1, t2); |
| 299 | 299 | t5 = vec_sub(t3, t4); |
| 300 | 300 | |
| 301 | | − /* Add each 4 pixel group together and put 4 results into sad */ |
| 301 | + /* Add each 4 pixel group together and put 4 results into sad. */ |
| 302 | 302 | sad = vec_sum4s(t5, sad); |
| 303 | 303 | |
| 304 | 304 | pix1 += line_size; |
| 305 | 305 | pix2 += line_size; |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | | − /* Sum up the four partial sums, and put the result into s */ |
| 308 | + /* Sum up the four partial sums, and put the result into s. */ |
| 309 | 309 | sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero); |
| 310 | 310 | sumdiffs = vec_splat(sumdiffs, 3); |
| 311 | 311 | vec_ste(sumdiffs, 0, &s); |
| @@ -327,17 +327,17 @@ static int pix_norm1_altivec(uint8_t *pix, int line_size) · 15 unmodified lines |
| 327 | 327 | |
| 328 | 328 | s = 0; |
| 329 | 329 | for (i = 0; i < 16; i++) { |
| 330 | | − /* Read in the potentially unaligned pixels */ |
| 330 | + /* Read the potentially unaligned pixels. */ |
| 331 | 331 | vector unsigned char pixl = vec_ld( 0, pix); |
| 332 | 332 | vector unsigned char pixr = vec_ld(15, pix); |
| 333 | 333 | pixv = vec_perm(pixl, pixr, perm); |
| 334 | 334 | |
| 335 | | − /* Square the values, and add them to our sum */ |
| 335 | + /* Square the values, and add them to our sum. */ |
| 336 | 336 | sv = vec_msum(pixv, pixv, sv); |
| 337 | 337 | |
| 338 | 338 | pix += line_size; |
| 339 | 339 | } |
| 340 | | − /* Sum up the four partial sums, and put the result into s */ |
| 340 | + /* Sum up the four partial sums, and put the result into s. */ |
| 341 | 341 | sum = vec_sums((vector signed int) sv, (vector signed int) zero); |
| 342 | 342 | sum = vec_splat(sum, 3); |
| 343 | 343 | vec_ste(sum, 0, &s); |
| @@ -345,11 +345,8 @@ static int pix_norm1_altivec(uint8_t *pix, int line_size) · 1 unmodified line |
| 345 | 345 | return s; |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | | −/** |
| 349 | | − * Sum of Squared Errors for a 8x8 block. |
| 350 | | − * AltiVec-enhanced. |
| 351 | | − * It's the sad8_altivec code above w/ squaring added. |
| 352 | | − */ |
| 348 | +/* Sum of Squared Errors for an 8x8 block, AltiVec-enhanced. |
| 349 | + * It's the sad8_altivec code above w/ squaring added. */ |
| 353 | 350 | static int sse8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) |
| 354 | 351 | { |
| 355 | 352 | int i; |
| @@ -365,9 +362,9 @@ static int sse8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, in · 9 unmodified lines |
| 365 | 362 | sum = (vector unsigned int)vec_splat_u32(0); |
| 366 | 363 | |
| 367 | 364 | for (i = 0; i < h; i++) { |
| 368 | | − /* Read potentially unaligned pixels into t1 and t2 |
| 369 | | − Since we're reading 16 pixels, and actually only want 8, |
| 370 | | − mask out the last 8 pixels. The 0s don't change the sum. */ |
| 365 | + /* Read potentially unaligned pixels into t1 and t2. |
| 366 | + * Since we're reading 16 pixels, and actually only want 8, |
| 367 | + * mask out the last 8 pixels. The 0s don't change the sum. */ |
| 371 | 368 | vector unsigned char pix1l = vec_ld(0, pix1); |
| 372 | 369 | vector unsigned char pix1r = vec_ld(7, pix1); |
| 373 | 370 | vector unsigned char pix2l = vec_ld(0, pix2); |
| @@ -376,21 +373,21 @@ static int sse8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, in · 2 unmodified lines |
| 376 | 373 | t2 = vec_and(vec_perm(pix2l, pix2r, perm2), permclear); |
| 377 | 374 | |
| 378 | 375 | /* Since we want to use unsigned chars, we can take advantage |
| 379 | | − of the fact that abs(a-b)^2 = (a-b)^2. */ |
| 376 | + * of the fact that abs(a - b) ^ 2 = (a - b) ^ 2. */ |
| 380 | 377 | |
| 381 | | − /* Calculate abs differences vector */ |
| 378 | + /* Calculate abs differences vector. */ |
| 382 | 379 | t3 = vec_max(t1, t2); |
| 383 | 380 | t4 = vec_min(t1, t2); |
| 384 | 381 | t5 = vec_sub(t3, t4); |
| 385 | 382 | |
| 386 | | − /* Square the values and add them to our sum */ |
| 383 | + /* Square the values and add them to our sum. */ |
| 387 | 384 | sum = vec_msum(t5, t5, sum); |
| 388 | 385 | |
| 389 | 386 | pix1 += line_size; |
| 390 | 387 | pix2 += line_size; |
| 391 | 388 | } |
| 392 | 389 | |
| 393 | | − /* Sum up the four partial sums, and put the result into s */ |
| 390 | + /* Sum up the four partial sums, and put the result into s. */ |
| 394 | 391 | sumsqr = vec_sums((vector signed int) sum, (vector signed int) zero); |
| 395 | 392 | sumsqr = vec_splat(sumsqr, 3); |
| 396 | 393 | vec_ste(sumsqr, 0, &s); |
| @@ -398,11 +395,8 @@ static int sse8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, in · 1 unmodified line |
| 398 | 395 | return s; |
| 399 | 396 | } |
| 400 | 397 | |
| 401 | | −/** |
| 402 | | − * Sum of Squared Errors for a 16x16 block. |
| 403 | | − * AltiVec-enhanced. |
| 404 | | − * It's the sad16_altivec code above w/ squaring added. |
| 405 | | − */ |
| 398 | +/* Sum of Squared Errors for a 16x16 block, AltiVec-enhanced. |
| 399 | + * It's the sad16_altivec code above w/ squaring added. */ |
| 406 | 400 | static int sse16_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) |
| 407 | 401 | { |
| 408 | 402 | int i; |
| @@ -416,28 +410,28 @@ static int sse16_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, i · 7 unmodified lines |
| 416 | 410 | sum = (vector unsigned int)vec_splat_u32(0); |
| 417 | 411 | |
| 418 | 412 | for (i = 0; i < h; i++) { |
| 419 | | − /* Read potentially unaligned pixels into t1 and t2 */ |
| 413 | + /* Read potentially unaligned pixels into t1 and t2. */ |
| 420 | 414 | vector unsigned char pix2l = vec_ld( 0, pix2); |
| 421 | 415 | vector unsigned char pix2r = vec_ld(15, pix2); |
| 422 | 416 | t1 = vec_ld(0, pix1); |
| 423 | 417 | t2 = vec_perm(pix2l, pix2r, perm); |
| 424 | 418 | |
| 425 | 419 | /* Since we want to use unsigned chars, we can take advantage |
| 426 | | − of the fact that abs(a-b)^2 = (a-b)^2. */ |
| 420 | + * of the fact that abs(a - b) ^ 2 = (a - b) ^ 2. */ |
| 427 | 421 | |
| 428 | | − /* Calculate abs differences vector */ |
| 422 | + /* Calculate abs differences vector. */ |
| 429 | 423 | t3 = vec_max(t1, t2); |
| 430 | 424 | t4 = vec_min(t1, t2); |
| 431 | 425 | t5 = vec_sub(t3, t4); |
| 432 | 426 | |
| 433 | | − /* Square the values and add them to our sum */ |
| 427 | + /* Square the values and add them to our sum. */ |
| 434 | 428 | sum = vec_msum(t5, t5, sum); |
| 435 | 429 | |
| 436 | 430 | pix1 += line_size; |
| 437 | 431 | pix2 += line_size; |
| 438 | 432 | } |
| 439 | 433 | |
| 440 | | − /* Sum up the four partial sums, and put the result into s */ |
| 434 | + /* Sum up the four partial sums, and put the result into s. */ |
| 441 | 435 | sumsqr = vec_sums((vector signed int) sum, (vector signed int) zero); |
| 442 | 436 | sumsqr = vec_splat(sumsqr, 3); |
| 443 | 437 | vec_ste(sumsqr, 0, &s); |
| @@ -459,18 +453,18 @@ static int pix_sum_altivec(uint8_t * pix, int line_size) · 15 unmodified lines |
| 459 | 453 | sad = (vector unsigned int)vec_splat_u32(0); |
| 460 | 454 | |
| 461 | 455 | for (i = 0; i < 16; i++) { |
| 462 | | − /* Read the potentially unaligned 16 pixels into t1 */ |
| 456 | + /* Read the potentially unaligned 16 pixels into t1. */ |
| 463 | 457 | vector unsigned char pixl = vec_ld( 0, pix); |
| 464 | 458 | vector unsigned char pixr = vec_ld(15, pix); |
| 465 | 459 | t1 = vec_perm(pixl, pixr, perm); |
| 466 | 460 | |
| 467 | | − /* Add each 4 pixel group together and put 4 results into sad */ |
| 461 | + /* Add each 4 pixel group together and put 4 results into sad. */ |
| 468 | 462 | sad = vec_sum4s(t1, sad); |
| 469 | 463 | |
| 470 | 464 | pix += line_size; |
| 471 | 465 | } |
| 472 | 466 | |
| 473 | | − /* Sum up the four partial sums, and put the result into s */ |
| 467 | + /* Sum up the four partial sums, and put the result into s. */ |
| 474 | 468 | sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero); |
| 475 | 469 | sumdiffs = vec_splat(sumdiffs, 3); |
| 476 | 470 | vec_ste(sumdiffs, 0, &s); |
| @@ -487,6 +481,9 @@ static void get_pixels_altivec(int16_t *restrict block, const uint8_t *pixels, i · 10 unmodified lines |
| 487 | 481 | vector signed short shorts; |
| 488 | 482 | |
| 489 | 483 | for (i = 0; i < 8; i++) { |
| 484 | + /* Read potentially unaligned pixels. |
| 485 | + * We're reading 16 pixels, and actually only want 8, |
| 486 | + * but we simply ignore the extras. */ |
| 490 | 487 | // Read potentially unaligned pixels. |
| 491 | 488 | // We're reading 16 pixels, and actually only want 8, |
| 492 | 489 | // but we simply ignore the extras. |
| @@ -494,10 +491,10 @@ static void get_pixels_altivec(int16_t *restrict block, const uint8_t *pixels, i · 1 unmodified line |
| 494 | 491 | vector unsigned char pixr = vec_ld(7, pixels); |
| 495 | 492 | bytes = vec_perm(pixl, pixr, perm); |
| 496 | 493 | |
| 497 | | − // convert the bytes into shorts |
| 494 | + // Convert the bytes into shorts. |
| 498 | 495 | shorts = (vector signed short)vec_mergeh(zero, bytes); |
| 499 | 496 | |
| 500 | | − // save the data to the block, we assume the block is 16-byte aligned |
| 497 | + // Save the data to the block, we assume the block is 16-byte aligned. |
| 501 | 498 | vec_st(shorts, i*16, (vector signed short*)block); |
| 502 | 499 | |
| 503 | 500 | pixels += line_size; |
| @@ -515,60 +512,59 @@ static void diff_pixels_altivec(int16_t *restrict block, const uint8_t *s1, · 11 unmodified lines |
| 515 | 512 | vector signed short shorts1, shorts2; |
| 516 | 513 | |
| 517 | 514 | for (i = 0; i < 4; i++) { |
| 518 | | − // Read potentially unaligned pixels |
| 519 | | − // We're reading 16 pixels, and actually only want 8, |
| 520 | | − // but we simply ignore the extras. |
| 515 | + /* Read potentially unaligned pixels. |
| 516 | + * We're reading 16 pixels, and actually only want 8, |
| 517 | + * but we simply ignore the extras. */ |
| 521 | 518 | pixl = vec_ld( 0, s1); |
| 522 | 519 | pixr = vec_ld(15, s1); |
| 523 | 520 | bytes = vec_perm(pixl, pixr, perm1); |
| 524 | 521 | |
| 525 | | − // convert the bytes into shorts |
| 522 | + // Convert the bytes into shorts. |
| 526 | 523 | shorts1 = (vector signed short)vec_mergeh(zero, bytes); |
| 527 | 524 | |
| 528 | | − // Do the same for the second block of pixels |
| 525 | + // Do the same for the second block of pixels. |
| 529 | 526 | pixl = vec_ld( 0, s2); |
| 530 | 527 | pixr = vec_ld(15, s2); |
| 531 | 528 | bytes = vec_perm(pixl, pixr, perm2); |
| 532 | 529 | |
| 533 | | − // convert the bytes into shorts |
| 530 | + // Convert the bytes into shorts. |
| 534 | 531 | shorts2 = (vector signed short)vec_mergeh(zero, bytes); |
| 535 | 532 | |
| 536 | | − // Do the subtraction |
| 533 | + // Do the subtraction. |
| 537 | 534 | shorts1 = vec_sub(shorts1, shorts2); |
| 538 | 535 | |
| 539 | | − // save the data to the block, we assume the block is 16-byte aligned |
| 536 | + // Save the data to the block, we assume the block is 16-byte aligned. |
| 540 | 537 | vec_st(shorts1, 0, (vector signed short*)block); |
| 541 | 538 | |
| 542 | 539 | s1 += stride; |
| 543 | 540 | s2 += stride; |
| 544 | 541 | block += 8; |
| 545 | 542 | |
| 543 | + /* The code below is a copy of the code above... |
| 544 | + * This is a manual unroll. */ |
| 546 | 545 | |
| 547 | | − // The code below is a copy of the code above... This is a manual |
| 548 | | − // unroll. |
| 549 | | − |
| 550 | | − // Read potentially unaligned pixels |
| 551 | | − // We're reading 16 pixels, and actually only want 8, |
| 552 | | − // but we simply ignore the extras. |
| 546 | + /* Read potentially unaligned pixels. |
| 547 | + * We're reading 16 pixels, and actually only want 8, |
| 548 | + * but we simply ignore the extras. */ |
| 553 | 549 | pixl = vec_ld( 0, s1); |
| 554 | 550 | pixr = vec_ld(15, s1); |
| 555 | 551 | bytes = vec_perm(pixl, pixr, perm1); |
| 556 | 552 | |
| 557 | | − // convert the bytes into shorts |
| 553 | + // Convert the bytes into shorts. |
| 558 | 554 | shorts1 = (vector signed short)vec_mergeh(zero, bytes); |
| 559 | 555 | |
| 560 | | − // Do the same for the second block of pixels |
| 556 | + // Do the same for the second block of pixels. |
| 561 | 557 | pixl = vec_ld( 0, s2); |
| 562 | 558 | pixr = vec_ld(15, s2); |
| 563 | 559 | bytes = vec_perm(pixl, pixr, perm2); |
| 564 | 560 | |
| 565 | | − // convert the bytes into shorts |
| 561 | + // Convert the bytes into shorts. |
| 566 | 562 | shorts2 = (vector signed short)vec_mergeh(zero, bytes); |
| 567 | 563 | |
| 568 | | − // Do the subtraction |
| 564 | + // Do the subtraction. |
| 569 | 565 | shorts1 = vec_sub(shorts1, shorts2); |
| 570 | 566 | |
| 571 | | − // save the data to the block, we assume the block is 16-byte aligned |
| 567 | + // Save the data to the block, we assume the block is 16-byte aligned. |
| 572 | 568 | vec_st(shorts1, 0, (vector signed short*)block); |
| 573 | 569 | |
| 574 | 570 | s1 += stride; |
| @@ -595,14 +591,14 @@ static void add_bytes_altivec(uint8_t *dst, uint8_t *src, int w) { · 20 unmodified lines |
| 595 | 591 | register int i; |
| 596 | 592 | register vector unsigned char vdst, vsrc; |
| 597 | 593 | |
| 598 | | − /* dst and src are 16 bytes-aligned (guaranteed) */ |
| 594 | + /* dst and src are 16 bytes-aligned (guaranteed). */ |
| 599 | 595 | for (i = 0 ; (i + 15) < w ; i+=16) { |
| 600 | 596 | vdst = vec_ld(i, (unsigned char*)dst); |
| 601 | 597 | vsrc = vec_ld(i, (unsigned char*)src); |
| 602 | 598 | vdst = vec_add(vsrc, vdst); |
| 603 | 599 | vec_st(vdst, i, (unsigned char*)dst); |
| 604 | 600 | } |
| 605 | | − /* if w is not a multiple of 16 */ |
| 601 | + /* If w is not a multiple of 16. */ |
| 606 | 602 | for (; (i < w) ; i++) { |
| 607 | 603 | dst[i] = src[i]; |
| 608 | 604 | } |
| @@ -643,8 +639,8 @@ static int hadamard8_diff8x8_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, u · 34 unmodified lines |
| 643 | 639 | dst1 = vec_ld(stride * i, dst); \ |
| 644 | 640 | dst2 = vec_ld((stride * i) + 15, dst); \ |
| 645 | 641 | dstO = vec_perm(dst1, dst2, vec_lvsl(stride * i, dst)); \ |
| 646 | | − /* promote the unsigned chars to signed shorts */ \ |
| 647 | | − /* we're in the 8x8 function, we only care for the first 8 */ \ |
| 642 | + /* Promote the unsigned chars to signed shorts. */ \ |
| 643 | + /* We're in the 8x8 function, we only care for the first 8. */ \ |
| 648 | 644 | srcV = (vector signed short)vec_mergeh((vector signed char)vzero, \ |
| 649 | 645 | (vector signed char)srcO); \ |
| 650 | 646 | dstV = (vector signed short)vec_mergeh((vector signed char)vzero, \ |
| @@ -713,24 +709,23 @@ static int hadamard8_diff8x8_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, u · 62 unmodified lines |
| 713 | 709 | } |
| 714 | 710 | |
| 715 | 711 | /* |
| 716 | | −16x8 works with 16 elements; it allows to avoid replicating loads, and |
| 717 | | −give the compiler more rooms for scheduling. It's only used from |
| 718 | | −inside hadamard8_diff16_altivec. |
| 719 | | − |
| 720 | | −Unfortunately, it seems gcc-3.3 is a bit dumb, and the compiled code has a LOT |
| 721 | | −of spill code, it seems gcc (unlike xlc) cannot keep everything in registers |
| 722 | | −by itself. The following code include hand-made registers allocation. It's not |
| 723 | | −clean, but on a 7450 the resulting code is much faster (best case fall from |
| 724 | | −700+ cycles to 550). |
| 725 | | − |
| 726 | | −xlc doesn't add spill code, but it doesn't know how to schedule for the 7450, |
| 727 | | −and its code isn't much faster than gcc-3.3 on the 7450 (but uses 25% less |
| 728 | | −instructions...) |
| 729 | | − |
| 730 | | −On the 970, the hand-made RA is still a win (around 690 vs. around 780), but |
| 731 | | −xlc goes to around 660 on the regular C code... |
| 732 | | −*/ |
| 733 | | − |
| 712 | + * 16x8 works with 16 elements; it allows to avoid replicating loads, and |
| 713 | + * gives the compiler more room for scheduling. It's only used from |
| 714 | + * inside hadamard8_diff16_altivec. |
| 715 | + * |
| 716 | + * Unfortunately, it seems gcc-3.3 is a bit dumb, and the compiled code has |
| 717 | + * a LOT of spill code, it seems gcc (unlike xlc) cannot keep everything in |
| 718 | + * registers by itself. The following code includes hand-made register |
| 719 | + * allocation. It's not clean, but on a 7450 the resulting code is much faster |
| 720 | + * (best case falls from 700+ cycles to 550). |
| 721 | + * |
| 722 | + * xlc doesn't add spill code, but it doesn't know how to schedule for the |
| 723 | + * 7450, and its code isn't much faster than gcc-3.3 on the 7450 (but uses |
| 724 | + * 25% fewer instructions...) |
| 725 | + * |
| 726 | + * On the 970, the hand-made RA is still a win (around 690 vs. around 780), |
| 727 | + * but xlc goes to around 660 on the regular C code... |
| 728 | + */ |
| 734 | 729 | static int hadamard8_diff16x8_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h) { |
| 735 | 730 | int sum; |
| 736 | 731 | register vector signed short |
| @@ -805,7 +800,7 @@ static int hadamard8_diff16x8_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, · 68 unmodified lines |
| 805 | 800 | dst1 = vec_ld(stride * i, dst); \ |
| 806 | 801 | dst2 = vec_ld((stride * i) + 16, dst); \ |
| 807 | 802 | dstO = vec_perm(dst1, dst2, vec_lvsl(stride * i, dst)); \ |
| 808 | | − /* promote the unsigned chars to signed shorts */ \ |
| 803 | + /* Promote the unsigned chars to signed shorts. */ \ |
| 809 | 804 | srcV = (vector signed short)vec_mergeh((vector signed char)vzero, \ |
| 810 | 805 | (vector signed char)srcO); \ |
| 811 | 806 | dstV = (vector signed short)vec_mergeh((vector signed char)vzero, \ |