by userbinator · 1y ago · 0 comments
mov eax, 0x00043201
test cl, 8
setz al
shl cl, 2
shr eax, cl
and eax, 15
Something similar may be possible on ARM64, but I suspect it will definitely be more than 19 bytes ;-) t = 0x2020c6 >> x
return (t << (t & 31)) >> 27 return (0x43201 >> x*4) & 7
It's more understandable and the number of instructions is the same. mov eax, 0x2020c6
shr eax, cl
mov cl, al
shl eax, cl
shr eax, 27
Yet those 14 bytes definitely beats my first attempt... although I've since found an even shorter solution: mov ax, 0x4681
lea ecx, [ecx+ecx*2]
shr eax, cl
and eax, 7
12 bytes.lzcnt ecx,ecx
mov eax, 00100 0011 0010 0000 0001b shl ecx,2 shrx eax,eax,ecx and eax,15
for Zen5 rustc creates the following:
utf8_sequence_length_lookup:
shl edi, 24
mov ecx, 274945
not edi
lzcnt eax, edi
shl al, 2
shrx rax, rcx, rax
and al, 7
ret
https://rust.godbolt.org/z/hz1eKjnaGStruggling proc \n lzcnt ecx,ecx \n test cl,cl \n setz al \n lea edx,[ecx-2] ;[0,1,2] \n cmp rdx,2 \n cmovle eax,ecx \n ret \n Struggling endp
We can assume the count has already been done.