| @@ -47,27 +47,27 @@ static int sad16_x2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size · 46 unmodified lines |
| 47 | sad = (vector unsigned int)vec_splat_u32(0); | 47 | sad = (vector unsigned int)vec_splat_u32(0); |
| 48 | for (i = 0; i < h; i++) { | 48 | for (i = 0; i < h; i++) { |
| 49 | /* Read unaligned pixels into our vectors. The vectors are as follows: | 49 | /* Read unaligned pixels into our vectors. The vectors are as follows: |
| 50 | pix1v: pix1[0]-pix1[15] | 50 | * pix1v: pix1[0] - pix1[15] |
| 51 | pix2v: pix2[0]-pix2[15] pix2iv: pix2[1]-pix2[16] */ | 51 | * pix2v: pix2[0] - pix2[15] pix2iv: pix2[1] - pix2[16] */ |
| 52 | pix1v = vec_ld( 0, pix1); | 52 | pix1v = vec_ld( 0, pix1); |
| 53 | pix2l = vec_ld( 0, pix2); | 53 | pix2l = vec_ld( 0, pix2); |
| 54 | pix2r = vec_ld(16, pix2); | 54 | pix2r = vec_ld(16, pix2); |
| 55 | pix2v = vec_perm(pix2l, pix2r, perm1); | 55 | pix2v = vec_perm(pix2l, pix2r, perm1); |
| 56 | pix2iv = vec_perm(pix2l, pix2r, perm2); | 56 | pix2iv = vec_perm(pix2l, pix2r, perm2); |
| 57 | | 57 | |
| 58 | /* Calculate the average vector */ | 58 | /* Calculate the average vector. */ |
| 59 | avgv = vec_avg(pix2v, pix2iv); | 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 | t5 = vec_sub(vec_max(pix1v, avgv), vec_min(pix1v, avgv)); | 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 | sad = vec_sum4s(t5, sad); | 65 | sad = vec_sum4s(t5, sad); |
| 66 | | 66 | |
| 67 | pix1 += line_size; | 67 | pix1 += line_size; |
| 68 | pix2 += line_size; | 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 | sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero); | 71 | sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero); |
| 72 | sumdiffs = vec_splat(sumdiffs, 3); | 72 | sumdiffs = vec_splat(sumdiffs, 3); |
| 73 | vec_ste(sumdiffs, 0, &s); | 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 | sad = (vector unsigned int)vec_splat_u32(0); | 91 | sad = (vector unsigned int)vec_splat_u32(0); |
| 92 | | 92 | |
| 93 | /* Due to the fact that pix3 = pix2 + line_size, the pix3 of one | 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 | 94 | * iteration becomes pix2 in the next iteration. We can use this |
| 95 | fact to avoid a potentially expensive unaligned read, each | 95 | * fact to avoid a potentially expensive unaligned read, each |
| 96 | time around the loop. | 96 | * time around the loop. |
| 97 | Read unaligned pixels into our vectors. The vectors are as follows: | 97 | * Read unaligned pixels into our vectors. The vectors are as follows: |
| 98 | pix2v: pix2[0]-pix2[15] | 98 | * pix2v: pix2[0] - pix2[15] |
| 99 | Split the pixel vectors into shorts */ | 99 | * Split the pixel vectors into shorts. */ |
| 100 | pix2l = vec_ld( 0, pix2); | 100 | pix2l = vec_ld( 0, pix2); |
| 101 | pix2r = vec_ld(15, pix2); | 101 | pix2r = vec_ld(15, pix2); |
| 102 | pix2v = vec_perm(pix2l, pix2r, perm); | 102 | pix2v = vec_perm(pix2l, pix2r, perm); |
| 103 | | 103 | |
| 104 | for (i = 0; i < h; i++) { | 104 | for (i = 0; i < h; i++) { |
| 105 | /* Read unaligned pixels into our vectors. The vectors are as follows: | 105 | /* Read unaligned pixels into our vectors. The vectors are as follows: |
| 106 | pix1v: pix1[0]-pix1[15] | 106 | * pix1v: pix1[0] - pix1[15] |
| 107 | pix3v: pix3[0]-pix3[15] */ | 107 | * pix3v: pix3[0] - pix3[15] */ |
| 108 | pix1v = vec_ld(0, pix1); | 108 | pix1v = vec_ld(0, pix1); |
| 109 | | 109 | |
| 110 | pix2l = vec_ld( 0, pix3); | 110 | pix2l = vec_ld( 0, pix3); |
| 111 | pix2r = vec_ld(15, pix3); | 111 | pix2r = vec_ld(15, pix3); |
| 112 | pix3v = vec_perm(pix2l, pix2r, perm); | 112 | pix3v = vec_perm(pix2l, pix2r, perm); |
| 113 | | 113 | |
| 114 | /* Calculate the average vector */ | 114 | /* Calculate the average vector. */ |
| 115 | avgv = vec_avg(pix2v, pix3v); | 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 | t5 = vec_sub(vec_max(pix1v, avgv), vec_min(pix1v, avgv)); | 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 | sad = vec_sum4s(t5, sad); | 121 | sad = vec_sum4s(t5, sad); |
| 122 | | 122 | |
| 123 | pix1 += line_size; | 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 | sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero); | 130 | sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero); |
| 131 | sumdiffs = vec_splat(sumdiffs, 3); | 131 | sumdiffs = vec_splat(sumdiffs, 3); |
| 132 | vec_ste(sumdiffs, 0, &s); | 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 | s = 0; | 157 | s = 0; |
| 158 | | 158 | |
| 159 | /* Due to the fact that pix3 = pix2 + line_size, the pix3 of one | 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 | 160 | * iteration becomes pix2 in the next iteration. We can use this |
| 161 | fact to avoid a potentially expensive unaligned read, as well | 161 | * fact to avoid a potentially expensive unaligned read, as well |
| 162 | as some splitting, and vector addition each time around the loop. | 162 | * as some splitting, and vector addition each time around the loop. |
| 163 | Read unaligned pixels into our vectors. The vectors are as follows: | 163 | * Read unaligned pixels into our vectors. The vectors are as follows: |
| 164 | pix2v: pix2[0]-pix2[15] pix2iv: pix2[1]-pix2[16] | 164 | * pix2v: pix2[0] - pix2[15] pix2iv: pix2[1] - pix2[16] |
| 165 | Split the pixel vectors into shorts */ | 165 | * Split the pixel vectors into shorts. */ |
| 166 | pix2l = vec_ld( 0, pix2); | 166 | pix2l = vec_ld( 0, pix2); |
| 167 | pix2r = vec_ld(16, pix2); | 167 | pix2r = vec_ld(16, pix2); |
| 168 | pix2v = vec_perm(pix2l, pix2r, perm1); | 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 | for (i = 0; i < h; i++) { | 178 | for (i = 0; i < h; i++) { |
| 179 | /* Read unaligned pixels into our vectors. The vectors are as follows: | 179 | /* Read unaligned pixels into our vectors. The vectors are as follows: |
| 180 | pix1v: pix1[0]-pix1[15] | 180 | * pix1v: pix1[0] - pix1[15] |
| 181 | pix3v: pix3[0]-pix3[15] pix3iv: pix3[1]-pix3[16] */ | 181 | * pix3v: pix3[0] - pix3[15] pix3iv: pix3[1] - pix3[16] */ |
| 182 | pix1v = vec_ld(0, pix1); | 182 | pix1v = vec_ld(0, pix1); |
| 183 | | 183 | |
| 184 | pix2l = vec_ld( 0, pix3); | 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 | pix3iv = vec_perm(pix2l, pix2r, perm2); | 187 | pix3iv = vec_perm(pix2l, pix2r, perm2); |
| 188 | | 188 | |
| 189 | /* Note that AltiVec does have vec_avg, but this works on vector pairs | 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 | 190 | * and rounds up. We could do avg(avg(a, b), avg(c, d)), but the |
| 191 | would mean that, for example, avg(3,0,0,1) = 2, when it should be 1. | 191 | * rounding would mean that, for example, avg(3, 0, 0, 1) = 2, when |
| 192 | Instead, we have to split the pixel vectors into vectors of shorts, | 192 | * it should be 1. Instead, we have to split the pixel vectors into |
| 193 | and do the averaging by hand. */ | 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 | pix3hv = (vector unsigned short) vec_mergeh(zero, pix3v); | 196 | pix3hv = (vector unsigned short) vec_mergeh(zero, pix3v); |
| 197 | pix3lv = (vector unsigned short) vec_mergel(zero, pix3v); | 197 | pix3lv = (vector unsigned short) vec_mergel(zero, pix3v); |
| 198 | pix3ihv = (vector unsigned short) vec_mergeh(zero, pix3iv); | 198 | pix3ihv = (vector unsigned short) vec_mergeh(zero, pix3iv); |
| 199 | pix3ilv = (vector unsigned short) vec_mergel(zero, pix3iv); | 199 | pix3ilv = (vector unsigned short) vec_mergel(zero, pix3iv); |
| 200 | | 200 | |
| 201 | /* Do the averaging on them */ | 201 | /* Do the averaging on them. */ |
| 202 | t3 = vec_add(pix3hv, pix3ihv); | 202 | t3 = vec_add(pix3hv, pix3ihv); |
| 203 | t4 = vec_add(pix3lv, pix3ilv); | 203 | t4 = vec_add(pix3lv, pix3ilv); |
| 204 | | 204 | |
| 205 | avghv = vec_sr(vec_add(vec_add(t1, t3), two), two); | 205 | avghv = vec_sr(vec_add(vec_add(t1, t3), two), two); |
| 206 | avglv = vec_sr(vec_add(vec_add(t2, t4), two), two); | 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 | avgv = vec_pack(avghv, avglv); | 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 | t5 = vec_sub(vec_max(pix1v, avgv), vec_min(pix1v, avgv)); | 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 | sad = vec_sum4s(t5, sad); | 215 | sad = vec_sum4s(t5, sad); |
| 216 | | 216 | |
| 217 | pix1 += line_size; | 217 | pix1 += line_size; |
| 218 | pix3 += line_size; | 218 | pix3 += line_size; |
| 219 | /* Transfer the calculated values for pix3 into pix2 */ | 219 | /* Transfer the calculated values for pix3 into pix2. */ |
| 220 | t1 = t3; | 220 | t1 = t3; |
| 221 | t2 = t4; | 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 | sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero); | 224 | sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero); |
| 225 | sumdiffs = vec_splat(sumdiffs, 3); | 225 | sumdiffs = vec_splat(sumdiffs, 3); |
| 226 | vec_ste(sumdiffs, 0, &s); | 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 | for (i = 0; i < h; i++) { | 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 | vector unsigned char pix2l = vec_ld( 0, pix2); | 246 | vector unsigned char pix2l = vec_ld( 0, pix2); |
| 247 | vector unsigned char pix2r = vec_ld(15, pix2); | 247 | vector unsigned char pix2r = vec_ld(15, pix2); |
| 248 | t1 = vec_ld(0, pix1); | 248 | t1 = vec_ld(0, pix1); |
| 249 | t2 = vec_perm(pix2l, pix2r, perm); | 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 | t3 = vec_max(t1, t2); | 252 | t3 = vec_max(t1, t2); |
| 253 | t4 = vec_min(t1, t2); | 253 | t4 = vec_min(t1, t2); |
| 254 | t5 = vec_sub(t3, t4); | 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 | sad = vec_sum4s(t5, sad); | 257 | sad = vec_sum4s(t5, sad); |
| 258 | | 258 | |
| 259 | pix1 += line_size; | 259 | pix1 += line_size; |
| 260 | pix2 += line_size; | 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 | sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero); | 264 | sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero); |
| 265 | sumdiffs = vec_splat(sumdiffs, 3); | 265 | sumdiffs = vec_splat(sumdiffs, 3); |
| 266 | vec_ste(sumdiffs, 0, &s); | 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 | sad = (vector unsigned int)vec_splat_u32(0); | 283 | sad = (vector unsigned int)vec_splat_u32(0); |
| 284 | | 284 | |
| 285 | for (i = 0; i < h; i++) { | 285 | for (i = 0; i < h; i++) { |
| 286 | /* Read potentially unaligned pixels into t1 and t2 | 286 | /* Read potentially unaligned pixels into t1 and t2. |
| 287 | Since we're reading 16 pixels, and actually only want 8, | 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. */ | 288 | * mask out the last 8 pixels. The 0s don't change the sum. */ |
| 289 | vector unsigned char pix1l = vec_ld(0, pix1); | 289 | vector unsigned char pix1l = vec_ld(0, pix1); |
| 290 | vector unsigned char pix1r = vec_ld(7, pix1); | 290 | vector unsigned char pix1r = vec_ld(7, pix1); |
| 291 | vector unsigned char pix2l = vec_ld(0, pix2); | 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 | t1 = vec_and(vec_perm(pix1l, pix1r, perm1), permclear); | 293 | t1 = vec_and(vec_perm(pix1l, pix1r, perm1), permclear); |
| 294 | t2 = vec_and(vec_perm(pix2l, pix2r, perm2), permclear); | 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 | t3 = vec_max(t1, t2); | 297 | t3 = vec_max(t1, t2); |
| 298 | t4 = vec_min(t1, t2); | 298 | t4 = vec_min(t1, t2); |
| 299 | t5 = vec_sub(t3, t4); | 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 | sad = vec_sum4s(t5, sad); | 302 | sad = vec_sum4s(t5, sad); |
| 303 | | 303 | |
| 304 | pix1 += line_size; | 304 | pix1 += line_size; |
| 305 | pix2 += line_size; | 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 | sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero); | 309 | sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero); |
| 310 | sumdiffs = vec_splat(sumdiffs, 3); | 310 | sumdiffs = vec_splat(sumdiffs, 3); |
| 311 | vec_ste(sumdiffs, 0, &s); | 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 | s = 0; | 328 | s = 0; |
| 329 | for (i = 0; i < 16; i++) { | 329 | for (i = 0; i < 16; i++) { |
| 330 | /* Read in the potentially unaligned pixels */ | 330 | /* Read the potentially unaligned pixels. */ |
| 331 | vector unsigned char pixl = vec_ld( 0, pix); | 331 | vector unsigned char pixl = vec_ld( 0, pix); |
| 332 | vector unsigned char pixr = vec_ld(15, pix); | 332 | vector unsigned char pixr = vec_ld(15, pix); |
| 333 | pixv = vec_perm(pixl, pixr, perm); | 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 | sv = vec_msum(pixv, pixv, sv); | 336 | sv = vec_msum(pixv, pixv, sv); |
| 337 | | 337 | |
| 338 | pix += line_size; | 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 | sum = vec_sums((vector signed int) sv, (vector signed int) zero); | 341 | sum = vec_sums((vector signed int) sv, (vector signed int) zero); |
| 342 | sum = vec_splat(sum, 3); | 342 | sum = vec_splat(sum, 3); |
| 343 | vec_ste(sum, 0, &s); | 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 | return s; | 345 | return s; |
| 346 | } | 346 | } |
| 347 | | 347 | |
| 348 | /** | 348 | /* Sum of Squared Errors for an 8x8 block, AltiVec-enhanced. |
| 349 | * Sum of Squared Errors for a 8x8 block. | 349 | * It's the sad8_altivec code above w/ squaring added. */ |
| 350 | * AltiVec-enhanced. | | |
| 351 | * It's the sad8_altivec code above w/ squaring added. | | |
| 352 | */ | | |
| 353 | static int sse8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) | 350 | static int sse8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) |
| 354 | { | 351 | { |
| 355 | int i; | 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 | sum = (vector unsigned int)vec_splat_u32(0); | 362 | sum = (vector unsigned int)vec_splat_u32(0); |
| 366 | | 363 | |
| 367 | for (i = 0; i < h; i++) { | 364 | for (i = 0; i < h; i++) { |
| 368 | /* Read potentially unaligned pixels into t1 and t2 | 365 | /* Read potentially unaligned pixels into t1 and t2. |
| 369 | Since we're reading 16 pixels, and actually only want 8, | 366 | * 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. */ | 367 | * mask out the last 8 pixels. The 0s don't change the sum. */ |
| 371 | vector unsigned char pix1l = vec_ld(0, pix1); | 368 | vector unsigned char pix1l = vec_ld(0, pix1); |
| 372 | vector unsigned char pix1r = vec_ld(7, pix1); | 369 | vector unsigned char pix1r = vec_ld(7, pix1); |
| 373 | vector unsigned char pix2l = vec_ld(0, pix2); | 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 | t2 = vec_and(vec_perm(pix2l, pix2r, perm2), permclear); | 373 | t2 = vec_and(vec_perm(pix2l, pix2r, perm2), permclear); |
| 377 | | 374 | |
| 378 | /* Since we want to use unsigned chars, we can take advantage | 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 | t3 = vec_max(t1, t2); | 379 | t3 = vec_max(t1, t2); |
| 383 | t4 = vec_min(t1, t2); | 380 | t4 = vec_min(t1, t2); |
| 384 | t5 = vec_sub(t3, t4); | 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 | sum = vec_msum(t5, t5, sum); | 384 | sum = vec_msum(t5, t5, sum); |
| 388 | | 385 | |
| 389 | pix1 += line_size; | 386 | pix1 += line_size; |
| 390 | pix2 += line_size; | 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 | sumsqr = vec_sums((vector signed int) sum, (vector signed int) zero); | 391 | sumsqr = vec_sums((vector signed int) sum, (vector signed int) zero); |
| 395 | sumsqr = vec_splat(sumsqr, 3); | 392 | sumsqr = vec_splat(sumsqr, 3); |
| 396 | vec_ste(sumsqr, 0, &s); | 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 | return s; | 395 | return s; |
| 399 | } | 396 | } |
| 400 | | 397 | |
| 401 | /** | 398 | /* Sum of Squared Errors for a 16x16 block, AltiVec-enhanced. |
| 402 | * Sum of Squared Errors for a 16x16 block. | 399 | * It's the sad16_altivec code above w/ squaring added. */ |
| 403 | * AltiVec-enhanced. | | |
| 404 | * It's the sad16_altivec code above w/ squaring added. | | |
| 405 | */ | | |
| 406 | static int sse16_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) | 400 | static int sse16_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) |
| 407 | { | 401 | { |
| 408 | int i; | 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 | sum = (vector unsigned int)vec_splat_u32(0); | 410 | sum = (vector unsigned int)vec_splat_u32(0); |
| 417 | | 411 | |
| 418 | for (i = 0; i < h; i++) { | 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 | vector unsigned char pix2l = vec_ld( 0, pix2); | 414 | vector unsigned char pix2l = vec_ld( 0, pix2); |
| 421 | vector unsigned char pix2r = vec_ld(15, pix2); | 415 | vector unsigned char pix2r = vec_ld(15, pix2); |
| 422 | t1 = vec_ld(0, pix1); | 416 | t1 = vec_ld(0, pix1); |
| 423 | t2 = vec_perm(pix2l, pix2r, perm); | 417 | t2 = vec_perm(pix2l, pix2r, perm); |
| 424 | | 418 | |
| 425 | /* Since we want to use unsigned chars, we can take advantage | 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 | t3 = vec_max(t1, t2); | 423 | t3 = vec_max(t1, t2); |
| 430 | t4 = vec_min(t1, t2); | 424 | t4 = vec_min(t1, t2); |
| 431 | t5 = vec_sub(t3, t4); | 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 | sum = vec_msum(t5, t5, sum); | 428 | sum = vec_msum(t5, t5, sum); |
| 435 | | 429 | |
| 436 | pix1 += line_size; | 430 | pix1 += line_size; |
| 437 | pix2 += line_size; | 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 | sumsqr = vec_sums((vector signed int) sum, (vector signed int) zero); | 435 | sumsqr = vec_sums((vector signed int) sum, (vector signed int) zero); |
| 442 | sumsqr = vec_splat(sumsqr, 3); | 436 | sumsqr = vec_splat(sumsqr, 3); |
| 443 | vec_ste(sumsqr, 0, &s); | 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 | sad = (vector unsigned int)vec_splat_u32(0); | 453 | sad = (vector unsigned int)vec_splat_u32(0); |
| 460 | | 454 | |
| 461 | for (i = 0; i < 16; i++) { | 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 | vector unsigned char pixl = vec_ld( 0, pix); | 457 | vector unsigned char pixl = vec_ld( 0, pix); |
| 464 | vector unsigned char pixr = vec_ld(15, pix); | 458 | vector unsigned char pixr = vec_ld(15, pix); |
| 465 | t1 = vec_perm(pixl, pixr, perm); | 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 | sad = vec_sum4s(t1, sad); | 462 | sad = vec_sum4s(t1, sad); |
| 469 | | 463 | |
| 470 | pix += line_size; | 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 | sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero); | 468 | sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero); |
| 475 | sumdiffs = vec_splat(sumdiffs, 3); | 469 | sumdiffs = vec_splat(sumdiffs, 3); |
| 476 | vec_ste(sumdiffs, 0, &s); | 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 | vector signed short shorts; | 481 | vector signed short shorts; |
| 488 | | 482 | |
| 489 | for (i = 0; i < 8; i++) { | 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 | // Read potentially unaligned pixels. | 487 | // Read potentially unaligned pixels. |
| 491 | // We're reading 16 pixels, and actually only want 8, | 488 | // We're reading 16 pixels, and actually only want 8, |
| 492 | // but we simply ignore the extras. | 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 | vector unsigned char pixr = vec_ld(7, pixels); | 491 | vector unsigned char pixr = vec_ld(7, pixels); |
| 495 | bytes = vec_perm(pixl, pixr, perm); | 492 | bytes = vec_perm(pixl, pixr, perm); |
| 496 | | 493 | |
| 497 | // convert the bytes into shorts | 494 | // Convert the bytes into shorts. |
| 498 | shorts = (vector signed short)vec_mergeh(zero, bytes); | 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 | vec_st(shorts, i*16, (vector signed short*)block); | 498 | vec_st(shorts, i*16, (vector signed short*)block); |
| 502 | | 499 | |
| 503 | pixels += line_size; | 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 | vector signed short shorts1, shorts2; | 512 | vector signed short shorts1, shorts2; |
| 516 | | 513 | |
| 517 | for (i = 0; i < 4; i++) { | 514 | for (i = 0; i < 4; i++) { |
| 518 | // Read potentially unaligned pixels | 515 | /* Read potentially unaligned pixels. |
| 519 | // We're reading 16 pixels, and actually only want 8, | 516 | * We're reading 16 pixels, and actually only want 8, |
| 520 | // but we simply ignore the extras. | 517 | * but we simply ignore the extras. */ |
| 521 | pixl = vec_ld( 0, s1); | 518 | pixl = vec_ld( 0, s1); |
| 522 | pixr = vec_ld(15, s1); | 519 | pixr = vec_ld(15, s1); |
| 523 | bytes = vec_perm(pixl, pixr, perm1); | 520 | bytes = vec_perm(pixl, pixr, perm1); |
| 524 | | 521 | |
| 525 | // convert the bytes into shorts | 522 | // Convert the bytes into shorts. |
| 526 | shorts1 = (vector signed short)vec_mergeh(zero, bytes); | 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 | pixl = vec_ld( 0, s2); | 526 | pixl = vec_ld( 0, s2); |
| 530 | pixr = vec_ld(15, s2); | 527 | pixr = vec_ld(15, s2); |
| 531 | bytes = vec_perm(pixl, pixr, perm2); | 528 | bytes = vec_perm(pixl, pixr, perm2); |
| 532 | | 529 | |
| 533 | // convert the bytes into shorts | 530 | // Convert the bytes into shorts. |
| 534 | shorts2 = (vector signed short)vec_mergeh(zero, bytes); | 531 | shorts2 = (vector signed short)vec_mergeh(zero, bytes); |
| 535 | | 532 | |
| 536 | // Do the subtraction | 533 | // Do the subtraction. |
| 537 | shorts1 = vec_sub(shorts1, shorts2); | 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 | vec_st(shorts1, 0, (vector signed short*)block); | 537 | vec_st(shorts1, 0, (vector signed short*)block); |
| 541 | | 538 | |
| 542 | s1 += stride; | 539 | s1 += stride; |
| 543 | s2 += stride; | 540 | s2 += stride; |
| 544 | block += 8; | 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 | 546 | /* Read potentially unaligned pixels. |
| 548 | // unroll. | 547 | * We're reading 16 pixels, and actually only want 8, |
| 549 | | 548 | * but we simply ignore the extras. */ |
| 550 | // Read potentially unaligned pixels | | |
| 551 | // We're reading 16 pixels, and actually only want 8, | | |
| 552 | // but we simply ignore the extras. | | |
| 553 | pixl = vec_ld( 0, s1); | 549 | pixl = vec_ld( 0, s1); |
| 554 | pixr = vec_ld(15, s1); | 550 | pixr = vec_ld(15, s1); |
| 555 | bytes = vec_perm(pixl, pixr, perm1); | 551 | bytes = vec_perm(pixl, pixr, perm1); |
| 556 | | 552 | |
| 557 | // convert the bytes into shorts | 553 | // Convert the bytes into shorts. |
| 558 | shorts1 = (vector signed short)vec_mergeh(zero, bytes); | 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 | pixl = vec_ld( 0, s2); | 557 | pixl = vec_ld( 0, s2); |
| 562 | pixr = vec_ld(15, s2); | 558 | pixr = vec_ld(15, s2); |
| 563 | bytes = vec_perm(pixl, pixr, perm2); | 559 | bytes = vec_perm(pixl, pixr, perm2); |
| 564 | | 560 | |
| 565 | // convert the bytes into shorts | 561 | // Convert the bytes into shorts. |
| 566 | shorts2 = (vector signed short)vec_mergeh(zero, bytes); | 562 | shorts2 = (vector signed short)vec_mergeh(zero, bytes); |
| 567 | | 563 | |
| 568 | // Do the subtraction | 564 | // Do the subtraction. |
| 569 | shorts1 = vec_sub(shorts1, shorts2); | 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 | vec_st(shorts1, 0, (vector signed short*)block); | 568 | vec_st(shorts1, 0, (vector signed short*)block); |
| 573 | | 569 | |
| 574 | s1 += stride; | 570 | s1 += stride; |
| @@ -595,14 +591,14 @@ static void add_bytes_altivec(uint8_t *dst, uint8_t *src, int w) { · 20 unmodified lines |
| 595 | register int i; | 591 | register int i; |
| 596 | register vector unsigned char vdst, vsrc; | 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 | for (i = 0 ; (i + 15) < w ; i+=16) { | 595 | for (i = 0 ; (i + 15) < w ; i+=16) { |
| 600 | vdst = vec_ld(i, (unsigned char*)dst); | 596 | vdst = vec_ld(i, (unsigned char*)dst); |
| 601 | vsrc = vec_ld(i, (unsigned char*)src); | 597 | vsrc = vec_ld(i, (unsigned char*)src); |
| 602 | vdst = vec_add(vsrc, vdst); | 598 | vdst = vec_add(vsrc, vdst); |
| 603 | vec_st(vdst, i, (unsigned char*)dst); | 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 | for (; (i < w) ; i++) { | 602 | for (; (i < w) ; i++) { |
| 607 | dst[i] = src[i]; | 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 | dst1 = vec_ld(stride * i, dst); \ | 639 | dst1 = vec_ld(stride * i, dst); \ |
| 644 | dst2 = vec_ld((stride * i) + 15, dst); \ | 640 | dst2 = vec_ld((stride * i) + 15, dst); \ |
| 645 | dstO = vec_perm(dst1, dst2, vec_lvsl(stride * i, dst)); \ | 641 | dstO = vec_perm(dst1, dst2, vec_lvsl(stride * i, dst)); \ |
| 646 | /* promote the unsigned chars to signed shorts */ \ | 642 | /* Promote the unsigned chars to signed shorts. */ \ |
| 647 | /* we're in the 8x8 function, we only care for the first 8 */ \ | 643 | /* We're in the 8x8 function, we only care for the first 8. */ \ |
| 648 | srcV = (vector signed short)vec_mergeh((vector signed char)vzero, \ | 644 | srcV = (vector signed short)vec_mergeh((vector signed char)vzero, \ |
| 649 | (vector signed char)srcO); \ | 645 | (vector signed char)srcO); \ |
| 650 | dstV = (vector signed short)vec_mergeh((vector signed char)vzero, \ | 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 | 712 | * 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 | 713 | * gives the compiler more room for scheduling. It's only used from |
| 718 | inside hadamard8_diff16_altivec. | 714 | * inside hadamard8_diff16_altivec. |
| 719 | | 715 | * |
| 720 | Unfortunately, it seems gcc-3.3 is a bit dumb, and the compiled code has a LOT | 716 | * Unfortunately, it seems gcc-3.3 is a bit dumb, and the compiled code has |
| 721 | of spill code, it seems gcc (unlike xlc) cannot keep everything in registers | 717 | * a LOT of spill code, it seems gcc (unlike xlc) cannot keep everything in |
| 722 | by itself. The following code include hand-made registers allocation. It's not | 718 | * registers by itself. The following code includes hand-made register |
| 723 | clean, but on a 7450 the resulting code is much faster (best case fall from | 719 | * allocation. It's not clean, but on a 7450 the resulting code is much faster |
| 724 | 700+ cycles to 550). | 720 | * (best case falls from 700+ cycles to 550). |
| 725 | | 721 | * |
| 726 | xlc doesn't add spill code, but it doesn't know how to schedule for the 7450, | 722 | * xlc doesn't add spill code, but it doesn't know how to schedule for the |
| 727 | and its code isn't much faster than gcc-3.3 on the 7450 (but uses 25% less | 723 | * 7450, and its code isn't much faster than gcc-3.3 on the 7450 (but uses |
| 728 | instructions...) | 724 | * 25% fewer instructions...) |
| 729 | | 725 | * |
| 730 | On the 970, the hand-made RA is still a win (around 690 vs. around 780), but | 726 | * On the 970, the hand-made RA is still a win (around 690 vs. around 780), |
| 731 | xlc goes to around 660 on the regular C code... | 727 | * but xlc goes to around 660 on the regular C code... |
| 732 | */ | 728 | */ |
| 733 | | | |
| 734 | static int hadamard8_diff16x8_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h) { | 729 | static int hadamard8_diff16x8_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h) { |
| 735 | int sum; | 730 | int sum; |
| 736 | register vector signed short | 731 | register vector signed short |
| @@ -805,7 +800,7 @@ static int hadamard8_diff16x8_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, · 68 unmodified lines |
| 805 | dst1 = vec_ld(stride * i, dst); \ | 800 | dst1 = vec_ld(stride * i, dst); \ |
| 806 | dst2 = vec_ld((stride * i) + 16, dst); \ | 801 | dst2 = vec_ld((stride * i) + 16, dst); \ |
| 807 | dstO = vec_perm(dst1, dst2, vec_lvsl(stride * i, dst)); \ | 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 | srcV = (vector signed short)vec_mergeh((vector signed char)vzero, \ | 804 | srcV = (vector signed short)vec_mergeh((vector signed char)vzero, \ |
| 810 | (vector signed char)srcO); \ | 805 | (vector signed char)srcO); \ |
| 811 | dstV = (vector signed short)vec_mergeh((vector signed char)vzero, \ | 806 | dstV = (vector signed short)vec_mergeh((vector signed char)vzero, \ |