x86 asm: move x87 FPU instructions from x86-assembly-cheat

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-06-22 00:00:01 +00:00
parent f66e777337
commit 082901414a
12 changed files with 339 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-x87-fpu-instructions */
#include <lkmc.h>
.data
double_1_0: .double 1.0
double_minus_1_0: .double -1.0
LKMC_PROLOGUE
/* |-1| == 1 */
fldl double_minus_1_0
fabs
fldl double_1_0
fcomip %st(1)
LKMC_ASSERT(je)
finit
/* |1| == 1 */
fldl double_1_0
fabs
fldl double_1_0
fcomip %st(1)
LKMC_ASSERT(je)
finit
LKMC_EPILOGUE

View File

@@ -0,0 +1,40 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-x87-fpu-instructions */
#include <lkmc.h>
.data
double_1_5: .double 1.5
double_2_5: .double 2.5
double_4_0: .double 4.0
LKMC_PROLOGUE
/* Load to the FPU stack.
* Push value from memory to the FPU stack. */
fldl double_1_5
/* FPU stack after operation:
* ST0 == 1.5 */
fldl double_2_5
/* FPU stack after operation:
* ST0 == 2.5
* ST1 == 1.5 */
/* ST0 = ST0 + ST1 */
fadd %st, %st(1)
/* FPU stack after operation:
* ST0 == 4.0
* ST1 == 1.5 */
fldl double_4_0
/* FPU stack after operation:
* ST0 == 4.0
* ST1 == 1.5
* ST2 == 4.0 */
/* Compare ST0 == ST2 */
fcomi %st(2)
/* FPU stack after operation:
* ST0 == 4.0
* ST1 == 1.5
* ST2 == 4.0 */
LKMC_ASSERT(je)
LKMC_EPILOGUE

View File

@@ -0,0 +1,36 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-x87-fpu-instructions */
#include <lkmc.h>
.data
double_1_5: .double 1.5
double_2_5: .double 2.5
double_4_0: .double 4.0
LKMC_PROLOGUE
fldl double_1_5
/* FPU stack after operation:
* ST0 == 1.5 */
fldl double_2_5
/* FPU stack after operation:
* ST0 == 2.5
* ST1 == 1.5 */
/* ST0 = ST0 + ST1
* Pop ST0. */
faddp %st, %st(1)
/* FPU stack after operation:
* ST0 == 4.0 */
fldl double_4_0
/* FPU stack after operation:
* ST0 == 4.0
* ST1 == 4.0 */
/* Compare ST0 == ST1
* Pop ST0. */
fcomip %st(1)
/* FPU stack after operation:
* ST0 == 4.0 */
LKMC_ASSERT(je)
LKMC_EPILOGUE

View File

@@ -0,0 +1,24 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-x87-fpu-instructions */
#include <lkmc.h>
.data
double_1: .double 1.0
double_minus_1: .double -1.0
LKMC_PROLOGUE
/* -(1) == -1 */
fldl double_1
fchs
fldl double_minus_1
fcomip %st(1)
LKMC_ASSERT(je)
finit
/* -(-1) == 1 */
fldl double_minus_1
fchs
fldl double_1
fcomip %st(1)
LKMC_ASSERT(je)
finit
LKMC_EPILOGUE

View File

@@ -0,0 +1,16 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-x87-fpu-instructions */
#include <lkmc.h>
.data
double_10_0: .double 10.0
.bss
double_10_0_2: .skip 8
LKMC_PROLOGUE
movl $10, double_10_0_2
fildl double_10_0_2
fldl double_10_0
fcomip %st(1)
LKMC_ASSERT(je)
finit
LKMC_EPILOGUE

View File

@@ -0,0 +1,12 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-x87-fpu-instructions */
#include <lkmc.h>
.data
double_1_0: .double 1.0
LKMC_PROLOGUE
fld1
fldl double_1_0
fcomip %st(1)
LKMC_ASSERT(je)
LKMC_EPILOGUE

View File

@@ -0,0 +1,18 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-x87-fpu-instructions */
#include <lkmc.h>
.data
double_1_5: .double 1.5
.bss
double_1_5_2: .skip 8
LKMC_PROLOGUE
#if 0
/* Error: junk `.5' after expression */
movq $1.5, double_1_5_2
fldl double_1_5
fldl double_1_5_2
fcomi %st(1)
LKMC_ASSERT(je)
#endif
LKMC_EPILOGUE

View File

@@ -0,0 +1,12 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-x87-fpu-instructions */
#include <lkmc.h>
.data
double_0_0: .double 0.0
LKMC_PROLOGUE
fldz
fldl double_0_0
fcomip %st(1)
LKMC_ASSERT(je)
LKMC_EPILOGUE

View File

@@ -0,0 +1,34 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-x87-fpu-instructions */
#include <lkmc.h>
.data
double_1_0: .double 1.0
double_2_5: .double 2.5
double_4_0: .double 4.0
LKMC_PROLOGUE
fldl double_4_0
# ST0 = 4.0
fldl double_2_5
# ST0 = 2.5
# ST1 = 4.0
fldl double_1_0
# ST0 = 1.0
# ST1 = 2.5
# ST2 = 4.0
# ST0 = 1 * 2 ^ (RoundTowardZero(2.5))
# = 1 * 2 ^ 2
# = 4
fscale
# ST0 = 4.0
# ST1 = 2.5
# ST2 = 4.0
fcomip %st(2)
# ST0 = 4.0
# ST1 = 2.5
LKMC_ASSERT(je)
LKMC_EPILOGUE

View File

@@ -0,0 +1,26 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-x87-fpu-instructions */
#include <lkmc.h>
.data
double_1_41: .double 1.41
double_1_42: .double 1.42
double_2_0: .double 2.0
double_4_0: .double 4.0
LKMC_PROLOGUE
/* sqrt(4) == 4 */
fldl double_4_0
fsqrt
fldl double_2_0
fcomip %st(1)
LKMC_ASSERT(je)
/* 1.41 < sqrt(2) < 1.42 */
fsqrt
fldl double_1_41
fcomip %st(1)
LKMC_ASSERT(jbe)
fldl double_1_42
fcomip %st(1)
LKMC_ASSERT(jae)
LKMC_EPILOGUE

View File

@@ -0,0 +1,45 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-x87-fpu-instructions */
#include <lkmc.h>
.data
double_0_0: .double 0.0
double_1_0: .double 1.0
LKMC_PROLOGUE
fldz
# ST0 = 0.0
fld1
# ST0 = 1.0
# ST1 = 0.0
# Swap ST0 and ST1.
fxch %st(1)
# ST0 = 0.0
# ST1 = 1.0
fldz
# ST0 = 0.0
# ST1 = 0.0
# ST2 = 1.0
fcomip %st(1)
# ST0 = 0.0
# ST1 = 1.0
LKMC_ASSERT(je)
# Swap ST0 and ST1.
fxch %st(1)
# ST0 = 1.0
# ST1 = 0.0
fld1
# ST0 = 1.0
# ST1 = 1.0
# ST2 = 0.0
fcomip %st(1)
# ST0 = 1.0
# ST1 = 0.0
LKMC_ASSERT(je)
LKMC_EPILOGUE