Skip to content

Commit 0d4ad3e

Browse files
committed
x86 asm: move POPCNT in from x86-assembly-cheat
1 parent 76c7cfe commit 0d4ad3e

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

README.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12427,6 +12427,9 @@ Do a BT and then swap the value of the tested bit.
1242712427
* link:userland/arch/x86_64/setcc.S[SETcc]
1242812428
+
1242912429
Set a a byte of a register to 0 or 1 depending on the cc condition.
12430+
* link:userland/arch/x86_64/popcnt.S[POPCNT]
12431+
+
12432+
Count the number of 1 bits.
1243012433
* link:userland/arch/x86_64/test.S[TEST]
1243112434
+
1243212435
Like <<x86-binary-arithmetic-instructions,CMP>> but does AND instead of SUB:

userland/arch/x86_64/popcnt.S

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-bit-and-byte-instructions */
2+
3+
#include <lkmc.h>
4+
5+
LKMC_PROLOGUE
6+
mov $0, %rbx
7+
popcnt %rbx, %rax
8+
LKMC_ASSERT_EQ(%rax, $0)
9+
10+
mov $1, %rbx
11+
popcnt %rbx, %rax
12+
LKMC_ASSERT_EQ(%rax, $1)
13+
14+
mov $2, %rbx
15+
popcnt %rbx, %rax
16+
LKMC_ASSERT_EQ(%rax, $1)
17+
18+
mov $3, %rbx
19+
popcnt %rbx, %rax
20+
LKMC_ASSERT_EQ(%rax, $2)
21+
22+
mov $4, %rbx
23+
popcnt %rbx, %rax
24+
LKMC_ASSERT_EQ(%rax, $1)
25+
26+
mov $5, %rbx
27+
popcnt %rbx, %rax
28+
LKMC_ASSERT_EQ(%rax, $2)
29+
30+
mov $6, %rbx
31+
popcnt %rbx, %rax
32+
LKMC_ASSERT_EQ(%rax, $2)
33+
34+
mov $7, %rbx
35+
popcnt %rbx, %rax
36+
LKMC_ASSERT_EQ(%rax, $3)
37+
LKMC_EPILOGUE

0 commit comments

Comments
 (0)