flat assembler
Message board for the users of flat assembler.
Index
> Main > Optimization Challenge: 13-bit technology |
Author |
|
bitRAKE 08 Oct 2024, 18:34
Is this cheating (BMI2) ...
Code: EncodeDecode dq 0x7FF_07FF_07FF pext rax, rax, [EncodeDecode] ; pack word bits mov [rdi], rax add rdi, 5 ; 40 bits pdep rax, rax, [EncodeDecode] ; unpack bits to words mov [rdi], rax add rdi, 6 ; three words _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
08 Oct 2024, 18:34 |
|
macomics 08 Oct 2024, 23:00
bitRAKE wrote:
Code: EncodeDecode dq 0x1FFF_1FFF_1FFF If you restrict yourself to just basic (<Pentium) 32-bit commands Code: ; eax=u*13, ecx=v*13, edx=w*13 - UINT13; x - undefined; 0 or 1 - defined and eax, 01111111111111b ; eax = 0000000000000000`000uuuuu`uuuuuuuub and ecx, 01111111111111b ; ecx = 0000000000000000`000vvvvv`vvvvvvvvb shl ecx, 13 ; ecx = 000000vvvvvvvvvv`vvv00000`00000000b or eax, ecx ; eax = 000000vvvvvvvvvv`vvvuuuuu`uuuuuuuub shl eax, 6 ; eax = vvvvvvvvvvvvvuuu`uuuuuuuu`uu000000b shl edx, 2 ; edx = xxxxxxxxxxxxxxxx`xwwwwwww`wwwwww00b shr dl, 2 ; edx = xxxxxxxxxxxxxxxx`xwwwwwww`00wwwwwwb or al, dl ; eax = vvvvvvvvvvvvvuuu`uuuuuuuu`uuwwwwwwb ror eax, 6 ; eax = wwwwwwvvvvvvvvvv`vvvuuuuu`uuuuuuuub and dh, 01111111b ; edx = xxxxxxxxxxxxxxxx`0wwwwwww`00wwwwwwb mov [ebx], eax ; store 31-0 bits mov [ebx+4], dh ; store 39-32 bits Code: mov eax, [ebx] ; eax = wwwwwwvvvvvvvvvv`vvvuuuuu`uuuuuuuub mov dh, [ebx+4] ; edx = xxxxxxxxxxxxxxxx`xwwwwwww`xxxxxxxxb mov ecx, eax ; ecx = wwwwwwvvvvvvvvvv`vvvuuuuu`uuuuuuuub rol eax, 6 ; eax = vvvvvvvvvvvvvuuu`uuuuuuuu`uuwwwwwwb mov dl, al ; edx = xxxxxxxxxxxxxxxx`xwwwwwww`uuwwwwwwb mov eax, ecx ; eax = wwwwwwvvvvvvvvvv`vvvuuuuu`uuuuuuuub shl dl, 2 ; edx = xxxxxxxxxxxxxxxx`xwwwwwww`wwwwww00b shr ecx, 13 ; ecx = 0000000000000www`wwwvvvvv`vvvvvvvvb shr edx, 2 ; edx = 00xxxxxxxxxxxxxx`xxxwwwww`wwwwwwwwb and eax, 01111111111111b ; eax = 0000000000000000`000uuuuu`uuuuuuuub and ecx, 01111111111111b ; ecx = 0000000000000000`000vvvvv`vvvvvvvvb and edx, 01111111111111b ; edx = 0000000000000000`000wwwww`wwwwwwwwb ; eax=u*13, ecx=v*13, edx=w*13 - UINT13; x - undefined; 0 or 1 - defined Using shld/shrd Code: ; eax=u*13, ecx=v*13, edx=w*13 - UINT13; x - undefined; 0 or 1 - defined ror eax, 13 ; eax = uuuuuuuuuuuuuxxx`xxxxxxxx`xxxxxxxxb shrd eax, ecx, 13 ; eax = vvvvvvvvvvvvvuuu`uuuuuuuu`uuxxxxxxb shrd eax, edx, 6 ; eax = wwwwwwvvvvvvvvvv`vvvuuuuu`uuuuuuuub shl edx, 2 ; edx = xxxxxxxxxxxxxxxx`xwwwwwww`wwwwww00b and dh, 01111111b ; edx = xxxxxxxxxxxxxxxx`0wwwwwww`wwwwww00b mov [ebx], eax ; store 31-0 bits mov [ebx+4], dh ; store 39-32 bits Code: mov dl, [ebx+4] ; edx = xxxxxxxxxxxxxxxx`xxxxxxxx`0wwwwwwwb mov eax, [ebx] ; eax = wwwwwwvvvvvvvvvv`vvvuuuuu`uuuuuuuub shld edx, eax, 6 ; edx = xxxxxxxxxxxxxxxx`xx0wwwww`wwwwwwwwb shrd ecx, eax, 26 ; ecx = vvvvvvvvvvvvvuuu`uuuuuuuu`uuxxxxxxb and eax, 01111111111111b ; eax = 0000000000000000`000uuuuu`uuuuuuuub shr ecx, 19 ; ecx = 0000000000000000`000vvvvv`vvvvvvvvb and edx, 01111111111111b ; edx = 0000000000000000`000wwwww`wwwwwwwwb ; eax=u*13, ecx=v*13, edx=w*13 - UINT13; x - undefined; 0 or 1 - defined Last edited by macomics on 09 Oct 2024, 00:47; edited 9 times in total |
|||
08 Oct 2024, 23:00 |
|
revolution 08 Oct 2024, 23:55
What are we supposed to be optimising for?
|
|||
08 Oct 2024, 23:55 |
|
macomics 09 Oct 2024, 00:33
DOS386 wrote:
|
|||
09 Oct 2024, 00:33 |
|
edfed 09 Oct 2024, 16:36
macomics: good wih shld shrd
can't pick into dl because maybe a 64bits compatibility for future or any bug???? but if 64bits, bitrake's is enough |
|||
09 Oct 2024, 16:36 |
|
macomics 09 Oct 2024, 17:36
edfed wrote: can't pick into dl because maybe a 64bits compatibility for future or any bug???? but if 64bits, bitrake's is enough |
|||
09 Oct 2024, 17:36 |
|
edfed 11 Oct 2024, 18:37
macomics wrote:
oops, true. then, why? |
|||
11 Oct 2024, 18:37 |
|
macomics 11 Oct 2024, 20:09
edfed wrote: oops, true. So that at least one part of 1 byte was available for each register, doubling was thrown out for the first 4 registers. Intel SDM wrote: 2.2.1.2 More on REX Prefix Fields |
|||
11 Oct 2024, 20:09 |
|
DOS386 13 Oct 2024, 18:28
macomics wrote:
It didn't work when I tried. I can no longer reproduce the problem now. Strange. macomics wrote: If you restrict yourself to just basic (<Pentium) 32-bit commands This looks very interesting, thanks. I'll test. revolution wrote: What are we supposed to be optimising for? YES, a sane mixture of above plus compatibility. _________________ Bug Nr.: 12345 Title: Hello World program compiles to 100 KB !!! Status: Closed: NOT a Bug |
|||
13 Oct 2024, 18:28 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.