mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
x86 asm: move POPCNT in from x86-assembly-cheat
This commit is contained in:
@@ -12427,6 +12427,9 @@ Do a BT and then swap the value of the tested bit.
|
||||
* link:userland/arch/x86_64/setcc.S[SETcc]
|
||||
+
|
||||
Set a a byte of a register to 0 or 1 depending on the cc condition.
|
||||
* link:userland/arch/x86_64/popcnt.S[POPCNT]
|
||||
+
|
||||
Count the number of 1 bits.
|
||||
* link:userland/arch/x86_64/test.S[TEST]
|
||||
+
|
||||
Like <<x86-binary-arithmetic-instructions,CMP>> but does AND instead of SUB:
|
||||
|
||||
37
userland/arch/x86_64/popcnt.S
Normal file
37
userland/arch/x86_64/popcnt.S
Normal file
@@ -0,0 +1,37 @@
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-bit-and-byte-instructions */
|
||||
|
||||
#include <lkmc.h>
|
||||
|
||||
LKMC_PROLOGUE
|
||||
mov $0, %rbx
|
||||
popcnt %rbx, %rax
|
||||
LKMC_ASSERT_EQ(%rax, $0)
|
||||
|
||||
mov $1, %rbx
|
||||
popcnt %rbx, %rax
|
||||
LKMC_ASSERT_EQ(%rax, $1)
|
||||
|
||||
mov $2, %rbx
|
||||
popcnt %rbx, %rax
|
||||
LKMC_ASSERT_EQ(%rax, $1)
|
||||
|
||||
mov $3, %rbx
|
||||
popcnt %rbx, %rax
|
||||
LKMC_ASSERT_EQ(%rax, $2)
|
||||
|
||||
mov $4, %rbx
|
||||
popcnt %rbx, %rax
|
||||
LKMC_ASSERT_EQ(%rax, $1)
|
||||
|
||||
mov $5, %rbx
|
||||
popcnt %rbx, %rax
|
||||
LKMC_ASSERT_EQ(%rax, $2)
|
||||
|
||||
mov $6, %rbx
|
||||
popcnt %rbx, %rax
|
||||
LKMC_ASSERT_EQ(%rax, $2)
|
||||
|
||||
mov $7, %rbx
|
||||
popcnt %rbx, %rax
|
||||
LKMC_ASSERT_EQ(%rax, $3)
|
||||
LKMC_EPILOGUE
|
||||
Reference in New Issue
Block a user