Skip to content

Use int16 min/max for _mm_set_epi16() calls #395

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

Merged
merged 2 commits into from
Nov 13, 2024
Merged
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
36 changes: 18 additions & 18 deletions libde265/x86/sse-motion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3527,9 +3527,9 @@ void ff_hevc_put_hevc_qpel_h_1_v_1_sse(int16_t *dst, ptrdiff_t dststride,
r0 = _mm_srli_epi32(r0, 6);

r1 = _mm_and_si128(r1,
_mm_set_epi16(0, 65535, 0, 65535, 0, 65535, 0, 65535));
_mm_set_epi16(-32766, 32767, -32766, 32767, -32766, 32767, -32766, 32767));
Copy link
Contributor

Choose a reason for hiding this comment

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

@mholt I'm wondering why you have chosen these int16 values. The equivalent to (0, 65535, 0, 65535, ...) would be (0, -1, 0, -1, ...).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was a best guess to preserve the range of ~65535, but if I recall correctly it also required some tinkering to prevent the exception.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is used as a simple bit-mask that is ANDed with the input pixel vector.

Do you want to change it to (0, -1) so that I can take your PR or should I just make the type fix on my side?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll change it 👍 One sec.

r0 = _mm_and_si128(r0,
_mm_set_epi16(0, 65535, 0, 65535, 0, 65535, 0, 65535));
_mm_set_epi16(-32766, 32767, -32766, 32767, -32766, 32767, -32766, 32767));
r0 = _mm_hadd_epi16(r0, r1);
_mm_store_si128((__m128i *) &dst[x], r0);

Expand Down Expand Up @@ -3710,9 +3710,9 @@ void ff_hevc_put_hevc_qpel_h_1_v_2_sse(int16_t *dst, ptrdiff_t dststride,
r0 = _mm_srli_epi32(r0, 6);

r1 = _mm_and_si128(r1,
_mm_set_epi16(0, 65535, 0, 65535, 0, 65535, 0, 65535));
_mm_set_epi16(-32766, 32767, -32766, 32767, -32766, 32767, -32766, 32767));
r0 = _mm_and_si128(r0,
_mm_set_epi16(0, 65535, 0, 65535, 0, 65535, 0, 65535));
_mm_set_epi16(-32766, 32767, -32766, 32767, -32766, 32767, -32766, 32767));
r0 = _mm_hadd_epi16(r0, r1);
_mm_store_si128((__m128i *) &dst[x], r0);

Expand Down Expand Up @@ -3887,9 +3887,9 @@ void ff_hevc_put_hevc_qpel_h_1_v_3_sse(int16_t *dst, ptrdiff_t dststride,
r0 = _mm_srli_epi32(r0, 6);

r1 = _mm_and_si128(r1,
_mm_set_epi16(0, 65535, 0, 65535, 0, 65535, 0, 65535));
_mm_set_epi16(-32766, 32767, -32766, 32767, -32766, 32767, -32766, 32767));
r0 = _mm_and_si128(r0,
_mm_set_epi16(0, 65535, 0, 65535, 0, 65535, 0, 65535));
_mm_set_epi16(-32766, 32767, -32766, 32767, -32766, 32767, -32766, 32767));
r0 = _mm_hadd_epi16(r0, r1);
_mm_store_si128((__m128i *) &dst[x], r0);

Expand Down Expand Up @@ -4058,9 +4058,9 @@ void ff_hevc_put_hevc_qpel_h_2_v_1_sse(int16_t *dst, ptrdiff_t dststride,
r0 = _mm_srli_epi32(r0, 6);

r1 = _mm_and_si128(r1,
_mm_set_epi16(0, 65535, 0, 65535, 0, 65535, 0, 65535));
_mm_set_epi16(-32766, 32767, -32766, 32767, -32766, 32767, -32766, 32767));
r0 = _mm_and_si128(r0,
_mm_set_epi16(0, 65535, 0, 65535, 0, 65535, 0, 65535));
_mm_set_epi16(-32766, 32767, -32766, 32767, -32766, 32767, -32766, 32767));
r0 = _mm_hadd_epi16(r0, r1);
_mm_store_si128((__m128i *) &dst[x], r0);

Expand Down Expand Up @@ -4241,9 +4241,9 @@ void ff_hevc_put_hevc_qpel_h_2_v_2_sse(int16_t *dst, ptrdiff_t dststride,
r0 = _mm_srli_epi32(r0, 6);

r1 = _mm_and_si128(r1,
_mm_set_epi16(0, 65535, 0, 65535, 0, 65535, 0, 65535));
_mm_set_epi16(-32766, 32767, -32766, 32767, -32766, 32767, -32766, 32767));
r0 = _mm_and_si128(r0,
_mm_set_epi16(0, 65535, 0, 65535, 0, 65535, 0, 65535));
_mm_set_epi16(-32766, 32767, -32766, 32767, -32766, 32767, -32766, 32767));
r0 = _mm_hadd_epi16(r0, r1);
_mm_store_si128((__m128i *) &dst[x], r0);

Expand Down Expand Up @@ -4419,9 +4419,9 @@ void ff_hevc_put_hevc_qpel_h_2_v_3_sse(int16_t *dst, ptrdiff_t dststride,
r0 = _mm_srli_epi32(r0, 6);

r1 = _mm_and_si128(r1,
_mm_set_epi16(0, 65535, 0, 65535, 0, 65535, 0, 65535));
_mm_set_epi16(-32766, 32767, -32766, 32767, -32766, 32767, -32766, 32767));
r0 = _mm_and_si128(r0,
_mm_set_epi16(0, 65535, 0, 65535, 0, 65535, 0, 65535));
_mm_set_epi16(-32766, 32767, -32766, 32767, -32766, 32767, -32766, 32767));
r0 = _mm_hadd_epi16(r0, r1);
_mm_store_si128((__m128i *) &dst[x], r0);

Expand Down Expand Up @@ -4592,9 +4592,9 @@ void ff_hevc_put_hevc_qpel_h_3_v_1_sse(int16_t *dst, ptrdiff_t dststride,
r0 = _mm_srli_epi32(r0, 6);

r1 = _mm_and_si128(r1,
_mm_set_epi16(0, 65535, 0, 65535, 0, 65535, 0, 65535));
_mm_set_epi16(-32766, 32767, -32766, 32767, -32766, 32767, -32766, 32767));
r0 = _mm_and_si128(r0,
_mm_set_epi16(0, 65535, 0, 65535, 0, 65535, 0, 65535));
_mm_set_epi16(-32766, 32767, -32766, 32767, -32766, 32767, -32766, 32767));
r0 = _mm_hadd_epi16(r0, r1);
_mm_store_si128((__m128i *) &dst[x], r0);

Expand Down Expand Up @@ -4778,9 +4778,9 @@ void ff_hevc_put_hevc_qpel_h_3_v_2_sse(int16_t *dst, ptrdiff_t dststride,
r0 = _mm_srli_epi32(r0, 6);

r1 = _mm_and_si128(r1,
_mm_set_epi16(0, 65535, 0, 65535, 0, 65535, 0, 65535));
_mm_set_epi16(-32766, 32767, -32766, 32767, -32766, 32767, -32766, 32767));
r0 = _mm_and_si128(r0,
_mm_set_epi16(0, 65535, 0, 65535, 0, 65535, 0, 65535));
_mm_set_epi16(-32766, 32767, -32766, 32767, -32766, 32767, -32766, 32767));
r0 = _mm_hadd_epi16(r0, r1);
_mm_store_si128((__m128i *) &dst[x], r0);

Expand Down Expand Up @@ -4958,9 +4958,9 @@ void ff_hevc_put_hevc_qpel_h_3_v_3_sse(int16_t *dst, ptrdiff_t dststride,
r0 = _mm_srli_epi32(r0, 6);

r1 = _mm_and_si128(r1,
_mm_set_epi16(0, 65535, 0, 65535, 0, 65535, 0, 65535));
_mm_set_epi16(-32766, 32767, -32766, 32767, -32766, 32767, -32766, 32767));
r0 = _mm_and_si128(r0,
_mm_set_epi16(0, 65535, 0, 65535, 0, 65535, 0, 65535));
_mm_set_epi16(-32766, 32767, -32766, 32767, -32766, 32767, -32766, 32767));
r0 = _mm_hadd_epi16(r0, r1);
_mm_store_si128((__m128i *) &dst[x], r0);

Expand Down