123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- void jsimd_ycc_rgb_convert_altivec(JDIMENSION out_width, JSAMPIMAGE input_buf,
- JDIMENSION input_row, JSAMPARRAY output_buf,
- int num_rows)
- {
- JSAMPROW outptr, inptr0, inptr1, inptr2;
- int pitch = out_width * RGB_PIXELSIZE, num_cols;
- #if __BIG_ENDIAN__
- int offset;
- #endif
- unsigned char __attribute__((aligned(16))) tmpbuf[RGB_PIXELSIZE * 16];
- __vector unsigned char rgb0, rgb1, rgb2, rgbx0, rgbx1, rgbx2, rgbx3,
- y, cb, cr;
- #if __BIG_ENDIAN__
- __vector unsigned char edgel, edgeh, edges, out0, out1, out2, out3;
- #if RGB_PIXELSIZE == 4
- __vector unsigned char out4;
- #endif
- #endif
- #if RGB_PIXELSIZE == 4
- __vector unsigned char rgb3;
- #endif
- __vector short rg0, rg1, rg2, rg3, bx0, bx1, bx2, bx3, yl, yh, cbl, cbh,
- crl, crh, rl, rh, gl, gh, bl, bh, g0w, g1w, g2w, g3w;
- __vector int g0, g1, g2, g3;
-
- __vector short pw_f0402 = { __8X(F_0_402 >> 1) },
- pw_mf0228 = { __8X(-F_0_228 >> 1) },
- pw_mf0344_f0285 = { __4X2(-F_0_344, F_0_285) },
- pw_one = { __8X(1) }, pw_255 = { __8X(255) },
- pw_cj = { __8X(CENTERJSAMPLE) };
- __vector int pd_onehalf = { __4X(ONE_HALF) };
- __vector unsigned char pb_zero = { __16X(0) },
- #if __BIG_ENDIAN__
- shift_pack_index =
- { 0, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28, 29 };
- #else
- shift_pack_index =
- { 2, 3, 6, 7, 10, 11, 14, 15, 18, 19, 22, 23, 26, 27, 30, 31 };
- #endif
- while (--num_rows >= 0) {
- inptr0 = input_buf[0][input_row];
- inptr1 = input_buf[1][input_row];
- inptr2 = input_buf[2][input_row];
- input_row++;
- outptr = *output_buf++;
- for (num_cols = pitch; num_cols > 0;
- num_cols -= RGB_PIXELSIZE * 16, outptr += RGB_PIXELSIZE * 16,
- inptr0 += 16, inptr1 += 16, inptr2 += 16) {
- y = vec_ld(0, inptr0);
-
- yl = (__vector signed short)VEC_UNPACKHU(y);
- yh = (__vector signed short)VEC_UNPACKLU(y);
- cb = vec_ld(0, inptr1);
- cbl = (__vector signed short)VEC_UNPACKHU(cb);
- cbh = (__vector signed short)VEC_UNPACKLU(cb);
- cbl = vec_sub(cbl, pw_cj);
- cbh = vec_sub(cbh, pw_cj);
- cr = vec_ld(0, inptr2);
- crl = (__vector signed short)VEC_UNPACKHU(cr);
- crh = (__vector signed short)VEC_UNPACKLU(cr);
- crl = vec_sub(crl, pw_cj);
- crh = vec_sub(crh, pw_cj);
-
- bl = vec_add(cbl, cbl);
- bh = vec_add(cbh, cbh);
- bl = vec_madds(bl, pw_mf0228, pw_one);
- bh = vec_madds(bh, pw_mf0228, pw_one);
- bl = vec_sra(bl, (__vector unsigned short)pw_one);
- bh = vec_sra(bh, (__vector unsigned short)pw_one);
- bl = vec_add(bl, cbl);
- bh = vec_add(bh, cbh);
- bl = vec_add(bl, cbl);
- bh = vec_add(bh, cbh);
- bl = vec_add(bl, yl);
- bh = vec_add(bh, yh);
- rl = vec_add(crl, crl);
- rh = vec_add(crh, crh);
- rl = vec_madds(rl, pw_f0402, pw_one);
- rh = vec_madds(rh, pw_f0402, pw_one);
- rl = vec_sra(rl, (__vector unsigned short)pw_one);
- rh = vec_sra(rh, (__vector unsigned short)pw_one);
- rl = vec_add(rl, crl);
- rh = vec_add(rh, crh);
- rl = vec_add(rl, yl);
- rh = vec_add(rh, yh);
- g0w = vec_mergeh(cbl, crl);
- g1w = vec_mergel(cbl, crl);
- g0 = vec_msums(g0w, pw_mf0344_f0285, pd_onehalf);
- g1 = vec_msums(g1w, pw_mf0344_f0285, pd_onehalf);
- g2w = vec_mergeh(cbh, crh);
- g3w = vec_mergel(cbh, crh);
- g2 = vec_msums(g2w, pw_mf0344_f0285, pd_onehalf);
- g3 = vec_msums(g3w, pw_mf0344_f0285, pd_onehalf);
-
- gl = vec_perm((__vector short)g0, (__vector short)g1, shift_pack_index);
- gh = vec_perm((__vector short)g2, (__vector short)g3, shift_pack_index);
- gl = vec_sub(gl, crl);
- gh = vec_sub(gh, crh);
- gl = vec_add(gl, yl);
- gh = vec_add(gh, yh);
- rg0 = vec_mergeh(rl, gl);
- bx0 = vec_mergeh(bl, pw_255);
- rg1 = vec_mergel(rl, gl);
- bx1 = vec_mergel(bl, pw_255);
- rg2 = vec_mergeh(rh, gh);
- bx2 = vec_mergeh(bh, pw_255);
- rg3 = vec_mergel(rh, gh);
- bx3 = vec_mergel(bh, pw_255);
- rgbx0 = vec_packsu(rg0, bx0);
- rgbx1 = vec_packsu(rg1, bx1);
- rgbx2 = vec_packsu(rg2, bx2);
- rgbx3 = vec_packsu(rg3, bx3);
- #if RGB_PIXELSIZE == 3
-
- rgb0 = vec_perm(rgbx0, rgbx1, (__vector unsigned char)RGB_INDEX0);
- rgb1 = vec_perm(rgbx1, rgbx2, (__vector unsigned char)RGB_INDEX1);
- rgb2 = vec_perm(rgbx2, rgbx3, (__vector unsigned char)RGB_INDEX2);
- #else
-
- rgb0 = vec_perm(rgbx0, rgbx0, (__vector unsigned char)RGB_INDEX);
- rgb1 = vec_perm(rgbx1, rgbx1, (__vector unsigned char)RGB_INDEX);
- rgb2 = vec_perm(rgbx2, rgbx2, (__vector unsigned char)RGB_INDEX);
- rgb3 = vec_perm(rgbx3, rgbx3, (__vector unsigned char)RGB_INDEX);
- #endif
- #if __BIG_ENDIAN__
- offset = (size_t)outptr & 15;
- if (offset) {
- __vector unsigned char unaligned_shift_index;
- int bytes = num_cols + offset;
- if (bytes < (RGB_PIXELSIZE + 1) * 16 && (bytes & 15)) {
-
- vec_st(rgb0, 0, tmpbuf);
- vec_st(rgb1, 16, tmpbuf);
- vec_st(rgb2, 32, tmpbuf);
- #if RGB_PIXELSIZE == 4
- vec_st(rgb3, 48, tmpbuf);
- #endif
- memcpy(outptr, tmpbuf, min(num_cols, RGB_PIXELSIZE * 16));
- } else {
-
- unaligned_shift_index = vec_lvsl(0, outptr);
- edgel = vec_ld(0, outptr);
- edgeh = vec_ld(min(num_cols - 1, RGB_PIXELSIZE * 16), outptr);
- edges = vec_perm(edgeh, edgel, unaligned_shift_index);
- unaligned_shift_index = vec_lvsr(0, outptr);
- out0 = vec_perm(edges, rgb0, unaligned_shift_index);
- out1 = vec_perm(rgb0, rgb1, unaligned_shift_index);
- out2 = vec_perm(rgb1, rgb2, unaligned_shift_index);
- #if RGB_PIXELSIZE == 4
- out3 = vec_perm(rgb2, rgb3, unaligned_shift_index);
- out4 = vec_perm(rgb3, edges, unaligned_shift_index);
- #else
- out3 = vec_perm(rgb2, edges, unaligned_shift_index);
- #endif
- vec_st(out0, 0, outptr);
- if (bytes > 16)
- vec_st(out1, 16, outptr);
- if (bytes > 32)
- vec_st(out2, 32, outptr);
- if (bytes > 48)
- vec_st(out3, 48, outptr);
- #if RGB_PIXELSIZE == 4
- if (bytes > 64)
- vec_st(out4, 64, outptr);
- #endif
- }
- } else {
- #endif
- if (num_cols < RGB_PIXELSIZE * 16 && (num_cols & 15)) {
-
- VEC_ST(rgb0, 0, tmpbuf);
- VEC_ST(rgb1, 16, tmpbuf);
- VEC_ST(rgb2, 32, tmpbuf);
- #if RGB_PIXELSIZE == 4
- VEC_ST(rgb3, 48, tmpbuf);
- #endif
- memcpy(outptr, tmpbuf, min(num_cols, RGB_PIXELSIZE * 16));
- } else {
-
- VEC_ST(rgb0, 0, outptr);
- if (num_cols > 16)
- VEC_ST(rgb1, 16, outptr);
- if (num_cols > 32)
- VEC_ST(rgb2, 32, outptr);
- #if RGB_PIXELSIZE == 4
- if (num_cols > 48)
- VEC_ST(rgb3, 48, outptr);
- #endif
- }
- #if __BIG_ENDIAN__
- }
- #endif
- }
- }
- }
|