From 57ffdae57f2533b2542777fae471c7da8f743985 Mon Sep 17 00:00:00 2001 From: Phil Dawes Date: Fri, 4 Sep 2009 20:13:44 +0100 Subject: [PATCH] asm math functions pass vm ptr to overflow function in 3rd arg (X86.32) --- vm/cpu-ppc.hpp | 1 + vm/cpu-x86.32.S | 1 + vm/cpu-x86.32.hpp | 1 + vm/cpu-x86.64.hpp | 2 +- vm/cpu-x86.S | 10 +++++++--- vm/math.cpp | 6 +++--- vm/math.hpp | 6 +++--- vm/vm.hpp | 6 +++--- 8 files changed, 20 insertions(+), 13 deletions(-) diff --git a/vm/cpu-ppc.hpp b/vm/cpu-ppc.hpp index 495eb375ec..d0036fb84f 100644 --- a/vm/cpu-ppc.hpp +++ b/vm/cpu-ppc.hpp @@ -3,6 +3,7 @@ namespace factor #define FACTOR_CPU_STRING "ppc" #define VM_ASM_API VM_C_API +#define VM_ASM_API_OVERFLOW VM_C_API register cell ds asm("r13"); register cell rs asm("r14"); diff --git a/vm/cpu-x86.32.S b/vm/cpu-x86.32.S index 326ddb6eb8..1618171b5b 100644 --- a/vm/cpu-x86.32.S +++ b/vm/cpu-x86.32.S @@ -2,6 +2,7 @@ #define ARG0 %eax #define ARG1 %edx +#define ARG2 %ecx #define STACK_REG %esp #define DS_REG %esi #define RETURN_REG %eax diff --git a/vm/cpu-x86.32.hpp b/vm/cpu-x86.32.hpp index 351865f776..a95179a49b 100644 --- a/vm/cpu-x86.32.hpp +++ b/vm/cpu-x86.32.hpp @@ -7,4 +7,5 @@ register cell ds asm("esi"); register cell rs asm("edi"); #define VM_ASM_API VM_C_API __attribute__ ((regparm (2))) +#define VM_ASM_API_OVERFLOW VM_C_API __attribute__ ((regparm (3))) } diff --git a/vm/cpu-x86.64.hpp b/vm/cpu-x86.64.hpp index 679c301548..841705c171 100644 --- a/vm/cpu-x86.64.hpp +++ b/vm/cpu-x86.64.hpp @@ -7,5 +7,5 @@ register cell ds asm("r14"); register cell rs asm("r15"); #define VM_ASM_API VM_C_API - +#define VM_ASM_API_OVERFLOW VM_C_API } diff --git a/vm/cpu-x86.S b/vm/cpu-x86.S index 2599ba3f97..a18d1483fb 100644 --- a/vm/cpu-x86.S +++ b/vm/cpu-x86.S @@ -1,4 +1,5 @@ -DEF(void,primitive_fixnum_add,(void)): +DEF(void,primitive_fixnum_add,(void *myvm)): + mov ARG0, ARG2 /* save vm ptr for overflow */ mov (DS_REG),ARG0 mov -CELL_SIZE(DS_REG),ARG1 sub $CELL_SIZE,DS_REG @@ -8,7 +9,8 @@ DEF(void,primitive_fixnum_add,(void)): mov ARITH_TEMP_1,(DS_REG) ret -DEF(void,primitive_fixnum_subtract,(void)): +DEF(void,primitive_fixnum_subtract,(void *myvm)): + mov ARG0, ARG2 /* save vm ptr for overflow */ mov (DS_REG),ARG1 mov -CELL_SIZE(DS_REG),ARG0 sub $CELL_SIZE,DS_REG @@ -18,7 +20,8 @@ DEF(void,primitive_fixnum_subtract,(void)): mov ARITH_TEMP_1,(DS_REG) ret -DEF(void,primitive_fixnum_multiply,(void)): +DEF(void,primitive_fixnum_multiply,(void *myvm)): + mov ARG0, ARG2 /* save vm ptr for overflow */ mov (DS_REG),ARITH_TEMP_1 mov ARITH_TEMP_1,DIV_RESULT mov -CELL_SIZE(DS_REG),ARITH_TEMP_2 @@ -28,6 +31,7 @@ DEF(void,primitive_fixnum_multiply,(void)): jo multiply_overflow mov DIV_RESULT,(DS_REG) ret + multiply_overflow: sar $3,ARITH_TEMP_1 mov ARITH_TEMP_1,ARG0 diff --git a/vm/math.cpp b/vm/math.cpp index fbb946e19f..be285872f5 100755 --- a/vm/math.cpp +++ b/vm/math.cpp @@ -842,7 +842,7 @@ inline void factorvm::overflow_fixnum_add(fixnum x, fixnum y) untag_fixnum(x) + untag_fixnum(y)))); } -VM_ASM_API void overflow_fixnum_add(fixnum x, fixnum y, factorvm *myvm) +VM_ASM_API_OVERFLOW void overflow_fixnum_add(fixnum x, fixnum y, factorvm *myvm) { return PRIMITIVE_OVERFLOW_GETVM()->overflow_fixnum_add(x,y); } @@ -853,7 +853,7 @@ inline void factorvm::overflow_fixnum_subtract(fixnum x, fixnum y) untag_fixnum(x) - untag_fixnum(y)))); } -VM_ASM_API void overflow_fixnum_subtract(fixnum x, fixnum y, factorvm *myvm) +VM_ASM_API_OVERFLOW void overflow_fixnum_subtract(fixnum x, fixnum y, factorvm *myvm) { return PRIMITIVE_OVERFLOW_GETVM()->overflow_fixnum_subtract(x,y); } @@ -867,7 +867,7 @@ inline void factorvm::overflow_fixnum_multiply(fixnum x, fixnum y) drepl(tag(bignum_multiply(bx,by))); } -VM_ASM_API void overflow_fixnum_multiply(fixnum x, fixnum y, factorvm *myvm) +VM_ASM_API_OVERFLOW void overflow_fixnum_multiply(fixnum x, fixnum y, factorvm *myvm) { return PRIMITIVE_OVERFLOW_GETVM()->overflow_fixnum_multiply(x,y); } diff --git a/vm/math.hpp b/vm/math.hpp index 5183f85f45..5e6121afb2 100644 --- a/vm/math.hpp +++ b/vm/math.hpp @@ -83,8 +83,8 @@ VM_C_API u64 to_unsigned_8(cell obj, factorvm *vm); VM_C_API fixnum to_fixnum(cell tagged, factorvm *vm); VM_C_API cell to_cell(cell tagged, factorvm *vm); -VM_ASM_API void overflow_fixnum_add(fixnum x, fixnum y, factorvm *vm); -VM_ASM_API void overflow_fixnum_subtract(fixnum x, fixnum y, factorvm *vm); -VM_ASM_API void overflow_fixnum_multiply(fixnum x, fixnum y, factorvm *vm); +VM_ASM_API_OVERFLOW void overflow_fixnum_add(fixnum x, fixnum y, factorvm *vm); +VM_ASM_API_OVERFLOW void overflow_fixnum_subtract(fixnum x, fixnum y, factorvm *vm); +VM_ASM_API_OVERFLOW void overflow_fixnum_multiply(fixnum x, fixnum y, factorvm *vm); } diff --git a/vm/vm.hpp b/vm/vm.hpp index a199885f49..3c0f4a246b 100644 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -626,10 +626,10 @@ struct factorvm : factorvmdata { #ifdef FACTOR_SINGLE_THREADED_TESTING /* calls are dispatched as per multithreaded, but checked against singleton */ extern factorvm *vm; - #define PRIMITIVE_GETVM() ((factorvm*)myvm) - #define PRIMITIVE_OVERFLOW_GETVM() vm - #define VM_PTR myvm #define ASSERTVM() assert(vm==myvm) + #define PRIMITIVE_GETVM() ((factorvm*)myvm) + #define PRIMITIVE_OVERFLOW_GETVM() ASSERTVM(); myvm + #define VM_PTR myvm #define SIGNAL_VM_PTR() tls_vm() #endif