OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009 The Android Open Source Project | 2 * Copyright 2009 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include <emmintrin.h> | 8 #include <emmintrin.h> |
9 #include "SkBitmapProcState_opts_SSE2.h" | 9 #include "SkBitmapProcState_opts_SSE2.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 } // while count >= 4 | 625 } // while count >= 4 |
626 } // if count >= 4 | 626 } // if count >= 4 |
627 | 627 |
628 while (count-- > 0) { | 628 while (count-- > 0) { |
629 *xy++ = (SkClampMax(fy >> 16, maxY) << 16) | | 629 *xy++ = (SkClampMax(fy >> 16, maxY) << 16) | |
630 SkClampMax(fx >> 16, maxX); | 630 SkClampMax(fx >> 16, maxX); |
631 fx += dx; | 631 fx += dx; |
632 fy += dy; | 632 fy += dy; |
633 } | 633 } |
634 } | 634 } |
635 | |
636 /* SSE version of S32_D16_filter_DX_SSE2 | |
637 * Definition is in section of "D16 functions for SRC == 8888" in SkBitmapProcS
tate.cpp | |
638 * It combines S32_opaque_D32_filter_DX_SSE2 and SkPixel32ToPixel16 | |
639 */ | |
640 void S32_D16_filter_DX_SSE2(const SkBitmapProcState& s, | |
641 const uint32_t* xy, | |
642 int count, uint16_t* colors) { | |
643 SkASSERT(count > 0 && colors != nullptr); | |
644 SkASSERT(s.fFilterLevel != kNone_SkFilterQuality); | |
645 SkASSERT(kN32_SkColorType == s.fPixmap.colorType()); | |
646 SkASSERT(s.fPixmap.isOpaque()); | |
647 | |
648 SkPMColor dstColor; | |
649 const char* srcAddr = static_cast<const char*>(s.fPixmap.addr()); | |
650 size_t rb = s.fPixmap.rowBytes(); | |
651 uint32_t XY = *xy++; | |
652 unsigned y0 = XY >> 14; | |
653 const uint32_t* row0 = reinterpret_cast<const uint32_t*>(srcAddr + (y0 >> 4)
* rb); | |
654 const uint32_t* row1 = reinterpret_cast<const uint32_t*>(srcAddr + (XY & 0x3
FFF) * rb); | |
655 unsigned subY = y0 & 0xF; | |
656 | |
657 // ( 0, 0, 0, 0, 0, 0, 0, 16) | |
658 __m128i sixteen = _mm_cvtsi32_si128(16); | |
659 | |
660 // ( 0, 0, 0, 0, 16, 16, 16, 16) | |
661 sixteen = _mm_shufflelo_epi16(sixteen, 0); | |
662 | |
663 // ( 0, 0, 0, 0, 0, 0, 0, y) | |
664 __m128i allY = _mm_cvtsi32_si128(subY); | |
665 | |
666 // ( 0, 0, 0, 0, y, y, y, y) | |
667 allY = _mm_shufflelo_epi16(allY, 0); | |
668 | |
669 // ( 0, 0, 0, 0, 16-y, 16-y, 16-y, 16-y) | |
670 __m128i negY = _mm_sub_epi16(sixteen, allY); | |
671 | |
672 // (16-y, 16-y, 16-y, 16-y, y, y, y, y) | |
673 allY = _mm_unpacklo_epi64(allY, negY); | |
674 | |
675 // (16, 16, 16, 16, 16, 16, 16, 16 ) | |
676 sixteen = _mm_shuffle_epi32(sixteen, 0); | |
677 | |
678 // ( 0, 0, 0, 0, 0, 0, 0, 0) | |
679 __m128i zero = _mm_setzero_si128(); | |
680 | |
681 do { | |
682 uint32_t XX = *xy++; // x0:14 | 4 | x1:14 | |
683 unsigned x0 = XX >> 18; | |
684 unsigned x1 = XX & 0x3FFF; | |
685 | |
686 // (0, 0, 0, 0, 0, 0, 0, x) | |
687 __m128i allX = _mm_cvtsi32_si128((XX >> 14) & 0x0F); | |
688 | |
689 // (0, 0, 0, 0, x, x, x, x) | |
690 allX = _mm_shufflelo_epi16(allX, 0); | |
691 | |
692 // (x, x, x, x, x, x, x, x) | |
693 allX = _mm_shuffle_epi32(allX, 0); | |
694 | |
695 // (16-x, 16-x, 16-x, 16-x, 16-x, 16-x, 16-x) | |
696 __m128i negX = _mm_sub_epi16(sixteen, allX); | |
697 | |
698 // Load 4 samples (pixels). | |
699 __m128i a00 = _mm_cvtsi32_si128(row0[x0]); | |
700 __m128i a01 = _mm_cvtsi32_si128(row0[x1]); | |
701 __m128i a10 = _mm_cvtsi32_si128(row1[x0]); | |
702 __m128i a11 = _mm_cvtsi32_si128(row1[x1]); | |
703 | |
704 // (0, 0, a00, a10) | |
705 __m128i a00a10 = _mm_unpacklo_epi32(a10, a00); | |
706 | |
707 // Expand to 16 bits per component. | |
708 a00a10 = _mm_unpacklo_epi8(a00a10, zero); | |
709 | |
710 // ((a00 * (16-y)), (a10 * y)). | |
711 a00a10 = _mm_mullo_epi16(a00a10, allY); | |
712 | |
713 // (a00 * (16-y) * (16-x), a10 * y * (16-x)). | |
714 a00a10 = _mm_mullo_epi16(a00a10, negX); | |
715 | |
716 // (0, 0, a01, a10) | |
717 __m128i a01a11 = _mm_unpacklo_epi32(a11, a01); | |
718 | |
719 // Expand to 16 bits per component. | |
720 a01a11 = _mm_unpacklo_epi8(a01a11, zero); | |
721 | |
722 // (a01 * (16-y)), (a11 * y) | |
723 a01a11 = _mm_mullo_epi16(a01a11, allY); | |
724 | |
725 // (a01 * (16-y) * x), (a11 * y * x) | |
726 a01a11 = _mm_mullo_epi16(a01a11, allX); | |
727 | |
728 // (a00*w00 + a01*w01, a10*w10 + a11*w11) | |
729 __m128i sum = _mm_add_epi16(a00a10, a01a11); | |
730 | |
731 // (DC, a00*w00 + a01*w01) | |
732 __m128i shifted = _mm_shuffle_epi32(sum, 0xEE); | |
733 | |
734 // (DC, a00*w00 + a01*w01 + a10*w10 + a11*w11) | |
735 sum = _mm_add_epi16(sum, shifted); | |
736 | |
737 // Divide each 16 bit component by 256. | |
738 sum = _mm_srli_epi16(sum, 8); | |
739 | |
740 // Pack lower 4 16 bit values of sum into lower 4 bytes. | |
741 sum = _mm_packus_epi16(sum, zero); | |
742 | |
743 // Extract low int and store. | |
744 dstColor = _mm_cvtsi128_si32(sum); | |
745 | |
746 *colors++ = SkPixel32ToPixel16(dstColor); | |
747 } while (--count > 0); | |
748 } | |
OLD | NEW |