Skip to content

Instantly share code, notes, and snippets.

@imaami
Last active September 13, 2024 18:39
Show Gist options
  • Save imaami/1ffd437e259a46114ded84c2fbceb480 to your computer and use it in GitHub Desktop.
Save imaami/1ffd437e259a46114ded84c2fbceb480 to your computer and use it in GitHub Desktop.
Expand all overlapping 4-bit subsequences of a circular 16-bit sequence
static uint64_t
b24_expand (uint16_t seq)
{
#define seq_prep(x) 0, (uint32_t)((x) << 12U | \
(x) >> 4U) << 16U | (x)
__m128i k = _mm_shuffle_epi8(
_mm_set_epi64x(seq_prep(seq)),
_mm_set_epi64x(UINT64_C(0x0303030301010101), \
UINT64_C(0x0202020200000000)));
#undef seq_prep
#define pext_mask UINT64_C(0x783c1e0f783c1e0f)
return _pext_u64((uint64_t)_mm_extract_epi64(k, 1), pext_mask) << 32U
| _pext_u64((uint64_t)_mm_extract_epi64(k, 0), pext_mask);
#undef pext_mask
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment