@Marcov: consider 'bswap' or 'movbe' <= latter only avail with Haswell ongoing iirc
Hmm. That wouldn't fix the bitfields that come out, but maybe it would work on the input to pext. Yup, that works!
procedure binstringtoint(const s:shortstring;var x :word);assembler;
// s must contain 16 characters either 1 or 0
// works, but result is bit reversed
asm
mov rax,[rcx+1]
mov r9,[rcx+9]
mov r10,$0101010101010101
bswap r9
bswap rax
pext rax,rax,r10
pext r9,r9,r10
shl rax,8
add rax,r9
mov [rdx],ax
end;
var s,s2 :shortstring;
i : integer;
x : word;
d : dword;
pd : pdword;
begin
s:='1101001000101101'; // $D22D
binstringtoint(s,x);
writeln(inttohex(x,4),' ',inttobin(x,16));
x :=$D22D;
writeln(inttohex(x,4),' ',inttobin(x,16));
end.
Generalizing this should be easy, and left as an exercise to the reader.
But you are anyway on Haswell ongoing, as you use 'pext', which only came with the BMI2 extensions.
This is all fairly new for me, since I used Ivy Bridge till september 2023. I did have a Kaveri (AMD 7850K) though which also has BMI2.
As for the purpose, that is a bit doubtful, but most of my (recent) assembler knowledge comes from writing SSE routines for image manipulation. And there it matters :-)