823
746
pixelsv = vec_perm(blockv, pixelsv, vcprm(s0,s1,2,3));
826
749
blockv = vec_avg(blockv, pixelsv);
828
751
vec_st(blockv, 0, block);
830
753
pixels += line_size;
831
754
block += line_size;
834
757
POWERPC_PERF_STOP_COUNT(altivec_avg_pixels8_num, 1);
836
#endif /* ALTIVEC_USE_REFERENCE_C_CODE */
839
760
/* next one assumes that ((line_size % 8) == 0) */
840
761
void put_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h)
842
763
POWERPC_PERF_DECLARE(altivec_put_pixels8_xy2_num, 1);
843
#ifdef ALTIVEC_USE_REFERENCE_C_CODE
765
register vector unsigned char
768
register vector unsigned char
769
blockv, temp1, temp2;
770
register vector unsigned short
771
pixelssum1, pixelssum2, temp3;
772
register const_vector unsigned char vczero = (const_vector unsigned char)vec_splat_u8(0);
773
register const_vector unsigned short vctwo = (const_vector unsigned short)vec_splat_u16(2);
775
temp1 = vec_ld(0, pixels);
776
temp2 = vec_ld(16, pixels);
777
pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(0, pixels));
778
if ((((unsigned long)pixels) & 0x0000000F) == 0x0000000F)
784
pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(1, pixels));
786
pixelsv1 = vec_mergeh(vczero, pixelsv1);
787
pixelsv2 = vec_mergeh(vczero, pixelsv2);
788
pixelssum1 = vec_add((vector unsigned short)pixelsv1,
789
(vector unsigned short)pixelsv2);
790
pixelssum1 = vec_add(pixelssum1, vctwo);
845
792
POWERPC_PERF_START_COUNT(altivec_put_pixels8_xy2_num, 1);
846
for (j = 0; j < 2; j++) {
848
const uint32_t a = (((const struct unaligned_32 *) (pixels))->l);
850
(((const struct unaligned_32 *) (pixels + 1))->l);
852
(a & 0x03030303UL) + (b & 0x03030303UL) + 0x02020202UL;
854
((a & 0xFCFCFCFCUL) >> 2) + ((b & 0xFCFCFCFCUL) >> 2);
857
for (i = 0; i < h; i += 2) {
858
uint32_t a = (((const struct unaligned_32 *) (pixels))->l);
859
uint32_t b = (((const struct unaligned_32 *) (pixels + 1))->l);
860
l1 = (a & 0x03030303UL) + (b & 0x03030303UL);
861
h1 = ((a & 0xFCFCFCFCUL) >> 2) + ((b & 0xFCFCFCFCUL) >> 2);
862
*((uint32_t *) block) =
863
h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL);
866
a = (((const struct unaligned_32 *) (pixels))->l);
867
b = (((const struct unaligned_32 *) (pixels + 1))->l);
868
l0 = (a & 0x03030303UL) + (b & 0x03030303UL) + 0x02020202UL;
869
h0 = ((a & 0xFCFCFCFCUL) >> 2) + ((b & 0xFCFCFCFCUL) >> 2);
870
*((uint32_t *) block) =
871
h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL);
874
} pixels += 4 - line_size * (h + 1);
875
block += 4 - line_size * h;
878
POWERPC_PERF_STOP_COUNT(altivec_put_pixels8_xy2_num, 1);
880
#else /* ALTIVEC_USE_REFERENCE_C_CODE */
882
register vector unsigned char
885
register vector unsigned char
886
blockv, temp1, temp2;
887
register vector unsigned short
888
pixelssum1, pixelssum2, temp3;
889
register const vector unsigned char vczero = (const vector unsigned char)vec_splat_u8(0);
890
register const vector unsigned short vctwo = (const vector unsigned short)vec_splat_u16(2);
892
temp1 = vec_ld(0, pixels);
893
temp2 = vec_ld(16, pixels);
894
pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(0, pixels));
895
if ((((unsigned long)pixels) & 0x0000000F) == 0x0000000F)
901
pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(1, pixels));
903
pixelsv1 = vec_mergeh(vczero, pixelsv1);
904
pixelsv2 = vec_mergeh(vczero, pixelsv2);
905
pixelssum1 = vec_add((vector unsigned short)pixelsv1,
906
(vector unsigned short)pixelsv2);
907
pixelssum1 = vec_add(pixelssum1, vctwo);
909
POWERPC_PERF_START_COUNT(altivec_put_pixels8_xy2_num, 1);
910
793
for (i = 0; i < h ; i++) {
911
794
int rightside = ((unsigned long)block & 0x0000000F);
912
795
blockv = vec_ld(0, block);
941
824
blockv = vec_perm(blockv, pixelsavg, vcprm(s0, s1, 2, 3));
944
827
vec_st(blockv, 0, block);
946
829
block += line_size;
947
830
pixels += line_size;
950
833
POWERPC_PERF_STOP_COUNT(altivec_put_pixels8_xy2_num, 1);
951
#endif /* ALTIVEC_USE_REFERENCE_C_CODE */
954
836
/* next one assumes that ((line_size % 8) == 0) */
955
837
void put_no_rnd_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h)
957
839
POWERPC_PERF_DECLARE(altivec_put_no_rnd_pixels8_xy2_num, 1);
958
#ifdef ALTIVEC_USE_REFERENCE_C_CODE
841
register vector unsigned char
844
register vector unsigned char
845
blockv, temp1, temp2;
846
register vector unsigned short
847
pixelssum1, pixelssum2, temp3;
848
register const_vector unsigned char vczero = (const_vector unsigned char)vec_splat_u8(0);
849
register const_vector unsigned short vcone = (const_vector unsigned short)vec_splat_u16(1);
850
register const_vector unsigned short vctwo = (const_vector unsigned short)vec_splat_u16(2);
852
temp1 = vec_ld(0, pixels);
853
temp2 = vec_ld(16, pixels);
854
pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(0, pixels));
855
if ((((unsigned long)pixels) & 0x0000000F) == 0x0000000F)
861
pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(1, pixels));
863
pixelsv1 = vec_mergeh(vczero, pixelsv1);
864
pixelsv2 = vec_mergeh(vczero, pixelsv2);
865
pixelssum1 = vec_add((vector unsigned short)pixelsv1,
866
(vector unsigned short)pixelsv2);
867
pixelssum1 = vec_add(pixelssum1, vcone);
960
869
POWERPC_PERF_START_COUNT(altivec_put_no_rnd_pixels8_xy2_num, 1);
961
for (j = 0; j < 2; j++) {
963
const uint32_t a = (((const struct unaligned_32 *) (pixels))->l);
965
(((const struct unaligned_32 *) (pixels + 1))->l);
967
(a & 0x03030303UL) + (b & 0x03030303UL) + 0x01010101UL;
969
((a & 0xFCFCFCFCUL) >> 2) + ((b & 0xFCFCFCFCUL) >> 2);
972
for (i = 0; i < h; i += 2) {
973
uint32_t a = (((const struct unaligned_32 *) (pixels))->l);
974
uint32_t b = (((const struct unaligned_32 *) (pixels + 1))->l);
975
l1 = (a & 0x03030303UL) + (b & 0x03030303UL);
976
h1 = ((a & 0xFCFCFCFCUL) >> 2) + ((b & 0xFCFCFCFCUL) >> 2);
977
*((uint32_t *) block) =
978
h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL);
981
a = (((const struct unaligned_32 *) (pixels))->l);
982
b = (((const struct unaligned_32 *) (pixels + 1))->l);
983
l0 = (a & 0x03030303UL) + (b & 0x03030303UL) + 0x01010101UL;
984
h0 = ((a & 0xFCFCFCFCUL) >> 2) + ((b & 0xFCFCFCFCUL) >> 2);
985
*((uint32_t *) block) =
986
h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL);
989
} pixels += 4 - line_size * (h + 1);
990
block += 4 - line_size * h;
993
POWERPC_PERF_STOP_COUNT(altivec_put_no_rnd_pixels8_xy2_num, 1);
995
#else /* ALTIVEC_USE_REFERENCE_C_CODE */
997
register vector unsigned char
1000
register vector unsigned char
1001
blockv, temp1, temp2;
1002
register vector unsigned short
1003
pixelssum1, pixelssum2, temp3;
1004
register const vector unsigned char vczero = (const vector unsigned char)vec_splat_u8(0);
1005
register const vector unsigned short vcone = (const vector unsigned short)vec_splat_u16(1);
1006
register const vector unsigned short vctwo = (const vector unsigned short)vec_splat_u16(2);
1008
temp1 = vec_ld(0, pixels);
1009
temp2 = vec_ld(16, pixels);
1010
pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(0, pixels));
1011
if ((((unsigned long)pixels) & 0x0000000F) == 0x0000000F)
1017
pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(1, pixels));
1019
pixelsv1 = vec_mergeh(vczero, pixelsv1);
1020
pixelsv2 = vec_mergeh(vczero, pixelsv2);
1021
pixelssum1 = vec_add((vector unsigned short)pixelsv1,
1022
(vector unsigned short)pixelsv2);
1023
pixelssum1 = vec_add(pixelssum1, vcone);
1025
POWERPC_PERF_START_COUNT(altivec_put_no_rnd_pixels8_xy2_num, 1);
1026
870
for (i = 0; i < h ; i++) {
1027
871
int rightside = ((unsigned long)block & 0x0000000F);
1028
872
blockv = vec_ld(0, block);
1299
1065
pixelssum1 = vec_add(pixelssum2, vcone);
1301
1067
blockv = vec_packsu(temp3, temp4);
1303
1069
vec_st(blockv, 0, block);
1305
1071
block += line_size;
1306
1072
pixels += line_size;
1309
1075
POWERPC_PERF_STOP_COUNT(altivec_put_no_rnd_pixels16_xy2_num, 1);
1310
#endif /* ALTIVEC_USE_REFERENCE_C_CODE */
1078
int hadamard8_diff8x8_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){
1079
POWERPC_PERF_DECLARE(altivec_hadamard8_diff8x8_num, 1);
1081
register const_vector unsigned char vzero =
1082
(const_vector unsigned char)vec_splat_u8(0);
1083
register vector signed short temp0, temp1, temp2, temp3, temp4,
1084
temp5, temp6, temp7;
1085
POWERPC_PERF_START_COUNT(altivec_hadamard8_diff8x8_num, 1);
1087
register const_vector signed short vprod1 =(const_vector signed short)
1088
AVV( 1,-1, 1,-1, 1,-1, 1,-1);
1089
register const_vector signed short vprod2 =(const_vector signed short)
1090
AVV( 1, 1,-1,-1, 1, 1,-1,-1);
1091
register const_vector signed short vprod3 =(const_vector signed short)
1092
AVV( 1, 1, 1, 1,-1,-1,-1,-1);
1093
register const_vector unsigned char perm1 = (const_vector unsigned char)
1094
AVV(0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05,
1095
0x0A, 0x0B, 0x08, 0x09, 0x0E, 0x0F, 0x0C, 0x0D);
1096
register const_vector unsigned char perm2 = (const_vector unsigned char)
1097
AVV(0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03,
1098
0x0C, 0x0D, 0x0E, 0x0F, 0x08, 0x09, 0x0A, 0x0B);
1099
register const_vector unsigned char perm3 = (const_vector unsigned char)
1100
AVV(0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
1101
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07);
1103
#define ONEITERBUTTERFLY(i, res) \
1105
register vector unsigned char src1, src2, srcO; \
1106
register vector unsigned char dst1, dst2, dstO; \
1107
register vector signed short srcV, dstV; \
1108
register vector signed short but0, but1, but2, op1, op2, op3; \
1109
src1 = vec_ld(stride * i, src); \
1110
src2 = vec_ld((stride * i) + 15, src); \
1111
srcO = vec_perm(src1, src2, vec_lvsl(stride * i, src)); \
1112
dst1 = vec_ld(stride * i, dst); \
1113
dst2 = vec_ld((stride * i) + 15, dst); \
1114
dstO = vec_perm(dst1, dst2, vec_lvsl(stride * i, dst)); \
1115
/* promote the unsigned chars to signed shorts */ \
1116
/* we're in the 8x8 function, we only care for the first 8 */ \
1118
(vector signed short)vec_mergeh((vector signed char)vzero, \
1119
(vector signed char)srcO); \
1121
(vector signed short)vec_mergeh((vector signed char)vzero, \
1122
(vector signed char)dstO); \
1123
/* substractions inside the first butterfly */ \
1124
but0 = vec_sub(srcV, dstV); \
1125
op1 = vec_perm(but0, but0, perm1); \
1126
but1 = vec_mladd(but0, vprod1, op1); \
1127
op2 = vec_perm(but1, but1, perm2); \
1128
but2 = vec_mladd(but1, vprod2, op2); \
1129
op3 = vec_perm(but2, but2, perm3); \
1130
res = vec_mladd(but2, vprod3, op3); \
1132
ONEITERBUTTERFLY(0, temp0);
1133
ONEITERBUTTERFLY(1, temp1);
1134
ONEITERBUTTERFLY(2, temp2);
1135
ONEITERBUTTERFLY(3, temp3);
1136
ONEITERBUTTERFLY(4, temp4);
1137
ONEITERBUTTERFLY(5, temp5);
1138
ONEITERBUTTERFLY(6, temp6);
1139
ONEITERBUTTERFLY(7, temp7);
1141
#undef ONEITERBUTTERFLY
1143
register vector signed int vsum;
1144
register vector signed short line0 = vec_add(temp0, temp1);
1145
register vector signed short line1 = vec_sub(temp0, temp1);
1146
register vector signed short line2 = vec_add(temp2, temp3);
1147
register vector signed short line3 = vec_sub(temp2, temp3);
1148
register vector signed short line4 = vec_add(temp4, temp5);
1149
register vector signed short line5 = vec_sub(temp4, temp5);
1150
register vector signed short line6 = vec_add(temp6, temp7);
1151
register vector signed short line7 = vec_sub(temp6, temp7);
1153
register vector signed short line0B = vec_add(line0, line2);
1154
register vector signed short line2B = vec_sub(line0, line2);
1155
register vector signed short line1B = vec_add(line1, line3);
1156
register vector signed short line3B = vec_sub(line1, line3);
1157
register vector signed short line4B = vec_add(line4, line6);
1158
register vector signed short line6B = vec_sub(line4, line6);
1159
register vector signed short line5B = vec_add(line5, line7);
1160
register vector signed short line7B = vec_sub(line5, line7);
1162
register vector signed short line0C = vec_add(line0B, line4B);
1163
register vector signed short line4C = vec_sub(line0B, line4B);
1164
register vector signed short line1C = vec_add(line1B, line5B);
1165
register vector signed short line5C = vec_sub(line1B, line5B);
1166
register vector signed short line2C = vec_add(line2B, line6B);
1167
register vector signed short line6C = vec_sub(line2B, line6B);
1168
register vector signed short line3C = vec_add(line3B, line7B);
1169
register vector signed short line7C = vec_sub(line3B, line7B);
1171
vsum = vec_sum4s(vec_abs(line0C), vec_splat_s32(0));
1172
vsum = vec_sum4s(vec_abs(line1C), vsum);
1173
vsum = vec_sum4s(vec_abs(line2C), vsum);
1174
vsum = vec_sum4s(vec_abs(line3C), vsum);
1175
vsum = vec_sum4s(vec_abs(line4C), vsum);
1176
vsum = vec_sum4s(vec_abs(line5C), vsum);
1177
vsum = vec_sum4s(vec_abs(line6C), vsum);
1178
vsum = vec_sum4s(vec_abs(line7C), vsum);
1179
vsum = vec_sums(vsum, (vector signed int)vzero);
1180
vsum = vec_splat(vsum, 3);
1181
vec_ste(vsum, 0, &sum);
1183
POWERPC_PERF_STOP_COUNT(altivec_hadamard8_diff8x8_num, 1);
1188
16x8 works with 16 elements ; it allows to avoid replicating
1189
loads, and give the compiler more rooms for scheduling.
1190
It's only used from inside hadamard8_diff16_altivec.
1192
Unfortunately, it seems gcc-3.3 is a bit dumb, and
1193
the compiled code has a LOT of spill code, it seems
1194
gcc (unlike xlc) cannot keep everything in registers
1195
by itself. The following code include hand-made
1196
registers allocation. It's not clean, but on
1197
a 7450 the resulting code is much faster (best case
1198
fall from 700+ cycles to 550).
1200
xlc doesn't add spill code, but it doesn't know how to
1201
schedule for the 7450, and its code isn't much faster than
1202
gcc-3.3 on the 7450 (but uses 25% less instructions...)
1204
On the 970, the hand-made RA is still a win (arount 690
1205
vs. around 780), but xlc goes to around 660 on the
1209
static int hadamard8_diff16x8_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h) {
1211
register vector signed short
1220
register vector signed short
1229
register const_vector unsigned char vzero REG_v(v31)=
1230
(const_vector unsigned char)vec_splat_u8(0);
1232
register const_vector signed short vprod1 REG_v(v16)=
1233
(const_vector signed short)AVV( 1,-1, 1,-1, 1,-1, 1,-1);
1234
register const_vector signed short vprod2 REG_v(v17)=
1235
(const_vector signed short)AVV( 1, 1,-1,-1, 1, 1,-1,-1);
1236
register const_vector signed short vprod3 REG_v(v18)=
1237
(const_vector signed short)AVV( 1, 1, 1, 1,-1,-1,-1,-1);
1238
register const_vector unsigned char perm1 REG_v(v19)=
1239
(const_vector unsigned char)
1240
AVV(0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05,
1241
0x0A, 0x0B, 0x08, 0x09, 0x0E, 0x0F, 0x0C, 0x0D);
1242
register const_vector unsigned char perm2 REG_v(v20)=
1243
(const_vector unsigned char)
1244
AVV(0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03,
1245
0x0C, 0x0D, 0x0E, 0x0F, 0x08, 0x09, 0x0A, 0x0B);
1246
register const_vector unsigned char perm3 REG_v(v21)=
1247
(const_vector unsigned char)
1248
AVV(0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
1249
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07);
1251
#define ONEITERBUTTERFLY(i, res1, res2) \
1253
register vector unsigned char src1 REG_v(v22), \
1260
register vector signed short srcV REG_v(v24), \
1277
src1 = vec_ld(stride * i, src); \
1278
src2 = vec_ld((stride * i) + 16, src); \
1279
srcO = vec_perm(src1, src2, vec_lvsl(stride * i, src)); \
1280
dst1 = vec_ld(stride * i, dst); \
1281
dst2 = vec_ld((stride * i) + 16, dst); \
1282
dstO = vec_perm(dst1, dst2, vec_lvsl(stride * i, dst)); \
1283
/* promote the unsigned chars to signed shorts */ \
1285
(vector signed short)vec_mergeh((vector signed char)vzero, \
1286
(vector signed char)srcO); \
1288
(vector signed short)vec_mergeh((vector signed char)vzero, \
1289
(vector signed char)dstO); \
1291
(vector signed short)vec_mergel((vector signed char)vzero, \
1292
(vector signed char)srcO); \
1294
(vector signed short)vec_mergel((vector signed char)vzero, \
1295
(vector signed char)dstO); \
1296
/* substractions inside the first butterfly */ \
1297
but0 = vec_sub(srcV, dstV); \
1298
but0S = vec_sub(srcW, dstW); \
1299
op1 = vec_perm(but0, but0, perm1); \
1300
but1 = vec_mladd(but0, vprod1, op1); \
1301
op1S = vec_perm(but0S, but0S, perm1); \
1302
but1S = vec_mladd(but0S, vprod1, op1S); \
1303
op2 = vec_perm(but1, but1, perm2); \
1304
but2 = vec_mladd(but1, vprod2, op2); \
1305
op2S = vec_perm(but1S, but1S, perm2); \
1306
but2S = vec_mladd(but1S, vprod2, op2S); \
1307
op3 = vec_perm(but2, but2, perm3); \
1308
res1 = vec_mladd(but2, vprod3, op3); \
1309
op3S = vec_perm(but2S, but2S, perm3); \
1310
res2 = vec_mladd(but2S, vprod3, op3S); \
1312
ONEITERBUTTERFLY(0, temp0, temp0S);
1313
ONEITERBUTTERFLY(1, temp1, temp1S);
1314
ONEITERBUTTERFLY(2, temp2, temp2S);
1315
ONEITERBUTTERFLY(3, temp3, temp3S);
1316
ONEITERBUTTERFLY(4, temp4, temp4S);
1317
ONEITERBUTTERFLY(5, temp5, temp5S);
1318
ONEITERBUTTERFLY(6, temp6, temp6S);
1319
ONEITERBUTTERFLY(7, temp7, temp7S);
1321
#undef ONEITERBUTTERFLY
1323
register vector signed int vsum;
1324
register vector signed short line0S, line1S, line2S, line3S, line4S,
1325
line5S, line6S, line7S, line0BS,line2BS,
1326
line1BS,line3BS,line4BS,line6BS,line5BS,
1327
line7BS,line0CS,line4CS,line1CS,line5CS,
1328
line2CS,line6CS,line3CS,line7CS;
1330
register vector signed short line0 = vec_add(temp0, temp1);
1331
register vector signed short line1 = vec_sub(temp0, temp1);
1332
register vector signed short line2 = vec_add(temp2, temp3);
1333
register vector signed short line3 = vec_sub(temp2, temp3);
1334
register vector signed short line4 = vec_add(temp4, temp5);
1335
register vector signed short line5 = vec_sub(temp4, temp5);
1336
register vector signed short line6 = vec_add(temp6, temp7);
1337
register vector signed short line7 = vec_sub(temp6, temp7);
1339
register vector signed short line0B = vec_add(line0, line2);
1340
register vector signed short line2B = vec_sub(line0, line2);
1341
register vector signed short line1B = vec_add(line1, line3);
1342
register vector signed short line3B = vec_sub(line1, line3);
1343
register vector signed short line4B = vec_add(line4, line6);
1344
register vector signed short line6B = vec_sub(line4, line6);
1345
register vector signed short line5B = vec_add(line5, line7);
1346
register vector signed short line7B = vec_sub(line5, line7);
1348
register vector signed short line0C = vec_add(line0B, line4B);
1349
register vector signed short line4C = vec_sub(line0B, line4B);
1350
register vector signed short line1C = vec_add(line1B, line5B);
1351
register vector signed short line5C = vec_sub(line1B, line5B);
1352
register vector signed short line2C = vec_add(line2B, line6B);
1353
register vector signed short line6C = vec_sub(line2B, line6B);
1354
register vector signed short line3C = vec_add(line3B, line7B);
1355
register vector signed short line7C = vec_sub(line3B, line7B);
1357
vsum = vec_sum4s(vec_abs(line0C), vec_splat_s32(0));
1358
vsum = vec_sum4s(vec_abs(line1C), vsum);
1359
vsum = vec_sum4s(vec_abs(line2C), vsum);
1360
vsum = vec_sum4s(vec_abs(line3C), vsum);
1361
vsum = vec_sum4s(vec_abs(line4C), vsum);
1362
vsum = vec_sum4s(vec_abs(line5C), vsum);
1363
vsum = vec_sum4s(vec_abs(line6C), vsum);
1364
vsum = vec_sum4s(vec_abs(line7C), vsum);
1366
line0S = vec_add(temp0S, temp1S);
1367
line1S = vec_sub(temp0S, temp1S);
1368
line2S = vec_add(temp2S, temp3S);
1369
line3S = vec_sub(temp2S, temp3S);
1370
line4S = vec_add(temp4S, temp5S);
1371
line5S = vec_sub(temp4S, temp5S);
1372
line6S = vec_add(temp6S, temp7S);
1373
line7S = vec_sub(temp6S, temp7S);
1375
line0BS = vec_add(line0S, line2S);
1376
line2BS = vec_sub(line0S, line2S);
1377
line1BS = vec_add(line1S, line3S);
1378
line3BS = vec_sub(line1S, line3S);
1379
line4BS = vec_add(line4S, line6S);
1380
line6BS = vec_sub(line4S, line6S);
1381
line5BS = vec_add(line5S, line7S);
1382
line7BS = vec_sub(line5S, line7S);
1384
line0CS = vec_add(line0BS, line4BS);
1385
line4CS = vec_sub(line0BS, line4BS);
1386
line1CS = vec_add(line1BS, line5BS);
1387
line5CS = vec_sub(line1BS, line5BS);
1388
line2CS = vec_add(line2BS, line6BS);
1389
line6CS = vec_sub(line2BS, line6BS);
1390
line3CS = vec_add(line3BS, line7BS);
1391
line7CS = vec_sub(line3BS, line7BS);
1393
vsum = vec_sum4s(vec_abs(line0CS), vsum);
1394
vsum = vec_sum4s(vec_abs(line1CS), vsum);
1395
vsum = vec_sum4s(vec_abs(line2CS), vsum);
1396
vsum = vec_sum4s(vec_abs(line3CS), vsum);
1397
vsum = vec_sum4s(vec_abs(line4CS), vsum);
1398
vsum = vec_sum4s(vec_abs(line5CS), vsum);
1399
vsum = vec_sum4s(vec_abs(line6CS), vsum);
1400
vsum = vec_sum4s(vec_abs(line7CS), vsum);
1401
vsum = vec_sums(vsum, (vector signed int)vzero);
1402
vsum = vec_splat(vsum, 3);
1403
vec_ste(vsum, 0, &sum);
1408
int hadamard8_diff16_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){
1409
POWERPC_PERF_DECLARE(altivec_hadamard8_diff16_num, 1);
1411
POWERPC_PERF_START_COUNT(altivec_hadamard8_diff16_num, 1);
1412
score = hadamard8_diff16x8_altivec(s, dst, src, stride, 8);
1416
score += hadamard8_diff16x8_altivec(s, dst, src, stride, 8);
1418
POWERPC_PERF_STOP_COUNT(altivec_hadamard8_diff16_num, 1);
1313
1422
int has_altivec(void)
1426
extern struct ExecIFace *IExec;
1428
IExec->GetCPUInfoTags(GCIT_VectorUnit, &result, TAG_DONE);
1429
if (result == VECTORTYPE_ALTIVEC) return 1;
1431
#else /* __AMIGAOS4__ */
1315
1433
#ifdef CONFIG_DARWIN
1316
1434
int sels[2] = {CTL_HW, HW_VECTORUNIT};
1317
1435
int has_vu = 0;
1330
1448
signal (SIGILL, SIG_DFL);
1334
1452
asm volatile ("mtspr 256, %0\n\t"
1335
1453
"vand %%v0, %%v0, %%v0"
1339
1457
signal (SIGILL, SIG_DFL);
1343
1461
#endif /* CONFIG_DARWIN */
1463
#endif /* __AMIGAOS4__ */
1466
static void vorbis_inverse_coupling_altivec(float *mag, float *ang,
1471
vector bool int t0, t1;
1472
const vector unsigned int v_31 = //XXX
1473
vec_add(vec_add(vec_splat_u32(15),vec_splat_u32(15)),vec_splat_u32(1));
1474
for(i=0; i<blocksize; i+=4) {
1475
m = vec_ld(0, mag+i);
1476
a = vec_ld(0, ang+i);
1477
t0 = vec_cmple(m, (vector float)vec_splat_u32(0));
1478
t1 = vec_cmple(a, (vector float)vec_splat_u32(0));
1479
a = vec_xor(a, (vector float) vec_sl((vector unsigned int)t0, v_31));
1480
t0 = (vector bool int)vec_and(a, t1);
1481
t1 = (vector bool int)vec_andc(a, t1);
1482
a = vec_sub(m, (vector float)t1);
1483
m = vec_add(m, (vector float)t0);
1484
vec_stl(a, 0, ang+i);
1485
vec_stl(m, 0, mag+i);
1489
/* next one assumes that ((line_size % 8) == 0) */
1490
void avg_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h)
1492
POWERPC_PERF_DECLARE(altivec_avg_pixels8_xy2_num, 1);
1494
register vector unsigned char pixelsv1, pixelsv2, pixelsavg;
1495
register vector unsigned char blockv, temp1, temp2, blocktemp;
1496
register vector unsigned short pixelssum1, pixelssum2, temp3;
1498
register const_vector unsigned char vczero = (const_vector unsigned char)
1500
register const_vector unsigned short vctwo = (const_vector unsigned short)
1503
temp1 = vec_ld(0, pixels);
1504
temp2 = vec_ld(16, pixels);
1505
pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(0, pixels));
1506
if ((((unsigned long)pixels) & 0x0000000F) == 0x0000000F) {
1509
pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(1, pixels));
1511
pixelsv1 = vec_mergeh(vczero, pixelsv1);
1512
pixelsv2 = vec_mergeh(vczero, pixelsv2);
1513
pixelssum1 = vec_add((vector unsigned short)pixelsv1,
1514
(vector unsigned short)pixelsv2);
1515
pixelssum1 = vec_add(pixelssum1, vctwo);
1517
POWERPC_PERF_START_COUNT(altivec_avg_pixels8_xy2_num, 1);
1518
for (i = 0; i < h ; i++) {
1519
int rightside = ((unsigned long)block & 0x0000000F);
1520
blockv = vec_ld(0, block);
1522
temp1 = vec_ld(line_size, pixels);
1523
temp2 = vec_ld(line_size + 16, pixels);
1524
pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(line_size, pixels));
1525
if (((((unsigned long)pixels) + line_size) & 0x0000000F) == 0x0000000F)
1529
pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(line_size + 1, pixels));
1532
pixelsv1 = vec_mergeh(vczero, pixelsv1);
1533
pixelsv2 = vec_mergeh(vczero, pixelsv2);
1534
pixelssum2 = vec_add((vector unsigned short)pixelsv1,
1535
(vector unsigned short)pixelsv2);
1536
temp3 = vec_add(pixelssum1, pixelssum2);
1537
temp3 = vec_sra(temp3, vctwo);
1538
pixelssum1 = vec_add(pixelssum2, vctwo);
1539
pixelsavg = vec_packsu(temp3, (vector unsigned short) vczero);
1542
blocktemp = vec_perm(blockv, pixelsavg, vcprm(0, 1, s0, s1));
1544
blocktemp = vec_perm(blockv, pixelsavg, vcprm(s0, s1, 2, 3));
1547
blockv = vec_avg(blocktemp, blockv);
1548
vec_st(blockv, 0, block);
1551
pixels += line_size;
1554
POWERPC_PERF_STOP_COUNT(altivec_avg_pixels8_xy2_num, 1);
1557
void dsputil_init_altivec(DSPContext* c, AVCodecContext *avctx)
1559
c->pix_abs[0][1] = sad16_x2_altivec;
1560
c->pix_abs[0][2] = sad16_y2_altivec;
1561
c->pix_abs[0][3] = sad16_xy2_altivec;
1562
c->pix_abs[0][0] = sad16_altivec;
1563
c->pix_abs[1][0] = sad8_altivec;
1564
c->sad[0]= sad16_altivec;
1565
c->sad[1]= sad8_altivec;
1566
c->pix_norm1 = pix_norm1_altivec;
1567
c->sse[1]= sse8_altivec;
1568
c->sse[0]= sse16_altivec;
1569
c->pix_sum = pix_sum_altivec;
1570
c->diff_pixels = diff_pixels_altivec;
1571
c->get_pixels = get_pixels_altivec;
1572
c->add_bytes= add_bytes_altivec;
1573
c->put_pixels_tab[0][0] = put_pixels16_altivec;
1574
/* the two functions do the same thing, so use the same code */
1575
c->put_no_rnd_pixels_tab[0][0] = put_pixels16_altivec;
1576
c->avg_pixels_tab[0][0] = avg_pixels16_altivec;
1577
c->avg_pixels_tab[1][0] = avg_pixels8_altivec;
1578
c->avg_pixels_tab[1][3] = avg_pixels8_xy2_altivec;
1579
c->put_pixels_tab[1][3] = put_pixels8_xy2_altivec;
1580
c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy2_altivec;
1581
c->put_pixels_tab[0][3] = put_pixels16_xy2_altivec;
1582
c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_altivec;
1584
c->hadamard8_diff[0] = hadamard8_diff16_altivec;
1585
c->hadamard8_diff[1] = hadamard8_diff8x8_altivec;
1586
#ifdef CONFIG_VORBIS_DECODER
1587
c->vorbis_inverse_coupling = vorbis_inverse_coupling_altivec;