diff --git a/README.adoc b/README.adoc index 785286e..7f6ca12 100644 --- a/README.adoc +++ b/README.adoc @@ -12366,6 +12366,15 @@ Bibliography: ** link:userland/arch/x86_64/idiv.S[IDIV] * link:userland/arch/x86_64/cmp.S[CMP] +=== x86 logical instructions + +<> 5.1.4 "Logical Instructions" + +* link:userland/arch/x86_64/and.S[AND] +* link:userland/arch/x86_64/not.S[NOT] +* link:userland/arch/x86_64/or.S[OR] +* link:userland/arch/x86_64/xor.S[XOR] + === x86 SIMD History: diff --git a/userland/arch/x86_64/and.S b/userland/arch/x86_64/and.S new file mode 100644 index 0000000..732a3f6 --- /dev/null +++ b/userland/arch/x86_64/and.S @@ -0,0 +1,9 @@ +/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-logical-instructions */ + +#include + +LKMC_PROLOGUE + mov $0x00FF, %rax + and $0x0F0F, %rax + LKMC_ASSERT_EQ(%rax, $0x000F) +LKMC_EPILOGUE diff --git a/userland/arch/x86_64/not.S b/userland/arch/x86_64/not.S new file mode 100644 index 0000000..036bc90 --- /dev/null +++ b/userland/arch/x86_64/not.S @@ -0,0 +1,9 @@ +/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-logical-instructions */ + +#include + +LKMC_PROLOGUE + mov $0x0FF0, %rax + not %ax + LKMC_ASSERT_EQ(%rax, $0xF00F) +LKMC_EPILOGUE diff --git a/userland/arch/x86_64/or.S b/userland/arch/x86_64/or.S new file mode 100644 index 0000000..a38d7c6 --- /dev/null +++ b/userland/arch/x86_64/or.S @@ -0,0 +1,9 @@ +/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-logical-instructions */ + +#include + +LKMC_PROLOGUE + mov $0x00FF, %rax + or $0x0F0F, %ax + LKMC_ASSERT_EQ(%rax, $0x0FFF) +LKMC_EPILOGUE diff --git a/userland/arch/x86_64/xor.S b/userland/arch/x86_64/xor.S new file mode 100644 index 0000000..5855b2f --- /dev/null +++ b/userland/arch/x86_64/xor.S @@ -0,0 +1,22 @@ +/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-logical-instructions */ + +#include + +LKMC_PROLOGUE + mov $0x00FF, %rax + xor $0x0F0F, %ax + LKMC_ASSERT_EQ(%rax, $0x0FF0) + + /* xor to set to zero idiom + * + * http://stackoverflow.com/questions/1135679/does-using-xor-reg-reg-give-advantage-over-mov-reg-0 + * + * xor can be used to set a register to 0 instad of mov: + * + * Compileres often do this to generate shorter instrucitons, + * but there are also cases where `mov` is better. + */ + mov $0x1020, %rax + xor %ax, %ax + mov $0x0000, %ax +LKMC_EPILOGUE