Skip to content

Commit

Permalink
x86asm: Add lzcnt/tzcnt support
Browse files Browse the repository at this point in the history
We already support popcnt, add lzcnt and tzcnt as well.

Signed-off-by: Mathias Krause <[email protected]>
  • Loading branch information
minipli-oss committed Dec 13, 2022
1 parent 0796920 commit 9cfc8f6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions i386-asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ ALT(DEF_ASM_OP2(btcw, 0x0fba, 7, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW | OPT_EA

ALT(DEF_ASM_OP2(popcntw, 0xf30fb8, 0, OPC_MODRM | OPC_WLX, OPT_REGW | OPT_EA, OPT_REGW))

ALT(DEF_ASM_OP2(tzcntw, 0xf30fbc, 0, OPC_MODRM | OPC_WLX, OPT_REGW | OPT_EA, OPT_REGW))
ALT(DEF_ASM_OP2(lzcntw, 0xf30fbd, 0, OPC_MODRM | OPC_WLX, OPT_REGW | OPT_EA, OPT_REGW))

/* prefixes */
DEF_ASM_OP0(wait, 0x9b)
DEF_ASM_OP0(fwait, 0x9b)
Expand Down
2 changes: 2 additions & 0 deletions i386-tok.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@
DEF_WLX(btr)
DEF_WLX(btc)
DEF_WLX(popcnt)
DEF_WLX(tzcnt)
DEF_WLX(lzcnt)

DEF_WLX(lar)
DEF_WLX(lsl)
Expand Down
24 changes: 23 additions & 1 deletion tests/asmtest.S
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,29 @@ int $0x10
popcnt %rbx, %rdi
popcntq %rcx, %r8
#endif


lzcnt %cx, %ax
lzcntw %cx, %ax
lzcnt %edx, %ebx
lzcntl 8(%edi), %ecx
#ifdef __x86_64__
lzcnt %rdi, %rdx
lzcntq %r12, %r15
lzcnt 0x40(%rcx), %r11
lzcntq (%r8), %rsi
#endif

tzcnt %cx, %ax
tzcntw %cx, %ax
tzcnt %edx, %ebx
tzcntl -24(%edi), %ecx
#ifdef __x86_64__
tzcnt %rbp, %rdx
tzcntq %rax, %r15
tzcnt -8(%rbp), %rcx
tzcntq (%r8), %r12
#endif

#ifdef __i386__
boundl %edx, 0x10000
boundw %bx, 0x1000
Expand Down
3 changes: 3 additions & 0 deletions x86_64-asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ ALT(DEF_ASM_OP2(btcw, 0x0fba, 7, OPC_MODRM | OPC_WLX, OPT_IM8, OPT_REGW | OPT_EA

ALT(DEF_ASM_OP2(popcntw, 0xf30fb8, 0, OPC_MODRM | OPC_WLX, OPT_REGW | OPT_EA, OPT_REGW))

ALT(DEF_ASM_OP2(tzcntw, 0xf30fbc, 0, OPC_MODRM | OPC_WLX, OPT_REGW | OPT_EA, OPT_REGW))
ALT(DEF_ASM_OP2(lzcntw, 0xf30fbd, 0, OPC_MODRM | OPC_WLX, OPT_REGW | OPT_EA, OPT_REGW))

/* prefixes */
DEF_ASM_OP0(lock, 0xf0)
DEF_ASM_OP0(rep, 0xf3)
Expand Down

0 comments on commit 9cfc8f6

Please sign in to comment.