Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized SSE2 alpha blit algorithm #2766

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src_c/simd_blitters_sse2.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ pg_neon_at_runtime_but_uncompiled()
#define DO_SSE2_DIV255_U16(MM128I) \
_mm_srli_epi16(_mm_mulhi_epu16(MM128I, _mm_set1_epi16((short)0x8081)), 7);

static inline __m128i
pg_mm_blendv_epi8(__m128i a, __m128i b, __m128i mask)
{
return _mm_or_si128(_mm_and_si128(mask, b), _mm_andnot_si128(mask, a));
}

void
alphablit_alpha_sse2_argb_surf_alpha(SDL_BlitInfo *info)
{
Expand Down Expand Up @@ -339,6 +345,8 @@ alphablit_alpha_sse2_argb_no_surf_alpha(SDL_BlitInfo *info)
mm_src_alpha = _mm_and_si128(mm_src, mm_alpha_mask);
mm_dst_alpha = _mm_and_si128(mm_dst, mm_alpha_mask);

__m128i mask = _mm_cmpeq_epi32(mm_dst_alpha, mm_zero);

mm_src_alpha = _mm_srli_si128(mm_src_alpha, 3);
mm_dst_alpha = _mm_srli_si128(mm_dst_alpha, 3);
mm_res_a = _mm_add_epi16(mm_src_alpha, mm_dst_alpha);
Expand Down Expand Up @@ -392,6 +400,9 @@ alphablit_alpha_sse2_argb_no_surf_alpha(SDL_BlitInfo *info)
mm_res_pixels = _mm_and_si128(mm_res_pixels, mm_rgb_mask);
mm_res_pixels = _mm_or_si128(mm_res_pixels, mm_res_a);

mm_res_pixels =
pg_mm_blendv_epi8(mm_res_pixels, mm_src, mask);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've figured out that this the equivalent of the if (!(*dstp & amask)) { below, but when reading through this the first time I was very confused about why you added this to one codepath and not the other. This should be explained in a comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes absolutely, I'll add a lot of comments but it will take a little while.


_mm_storeu_si128(dstp128, mm_res_pixels);
srcp128++;
dstp128++;
Expand Down
Loading