[Stackless-checkins] CVS: slpdev/src/2.3/dev/Stackless/platf slp_platformselect.h, 1.5, 1.6 switch_x86_msvc.h, 1.33, 1.34 switch_amd64_unix.h, NONE, 1.1 switch_x64_masm.asm, NONE, 1.1 switch_x64_msvc.h, NONE, 1.1

Christian Tismer tismer at centera.de
Tue Dec 20 14:17:52 CET 2005


Update of /home/cvs/slpdev/src/2.3/dev/Stackless/platf
In directory centera.de:/tmp/cvs-serv14441/src/2.3/dev/Stackless/platf

Modified Files:
	slp_platformselect.h switch_x86_msvc.h 
Added Files:
	switch_amd64_unix.h switch_x64_masm.asm switch_x64_msvc.h 
Log Message:
ported x64 to Stackless 3.1 . There is still an issue with taskspeed that doesn't finish. Checking against MSVC 7.0 now...

Index: slp_platformselect.h
===================================================================
RCS file: /home/cvs/slpdev/src/2.3/dev/Stackless/platf/slp_platformselect.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** slp_platformselect.h	24 May 2004 01:40:17 -0000	1.5
--- slp_platformselect.h	20 Dec 2005 13:17:49 -0000	1.6
***************
*** 5,10 ****
--- 5,14 ----
  #if   defined(MS_WIN32) && !defined(MS_WIN64) && defined(_M_IX86)
  #include "switch_x86_msvc.h" /* MS Visual Studio on X86 */
+ #elif defined(MS_WIN64) && defined(_M_X64)
+ #include "switch_x64_msvc.h" /* MS Visual Studio on X64 */
  #elif defined(__GNUC__) && defined(__i386__)
  #include "switch_x86_unix.h" /* gcc on X86 */
+ #elif defined(__GNUC__) && defined(__amd64__)
+ #include "switch_amd64_unix.h" /* gcc on amd64 */
  #elif defined(__GNUC__) && defined(__PPC__) && defined(__linux__)
  #include "switch_ppc_unix.h" /* gcc on PowerPC */

Index: switch_x86_msvc.h
===================================================================
RCS file: /home/cvs/slpdev/src/2.3/dev/Stackless/platf/switch_x86_msvc.h,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -d -r1.33 -r1.34
*** switch_x86_msvc.h	12 Jul 2004 18:56:55 -0000	1.33
--- switch_x86_msvc.h	20 Dec 2005 13:17:49 -0000	1.34
***************
*** 35,38 ****
--- 35,40 ----
  #define STACK_MAGIC 0
  
+ #pragma optimize("", off)
+ 
  static int
  slp_switch(void)

--- NEW FILE: switch_amd64_unix.h ---
/*
 * this is the internal transfer function.
 *
 * HISTORY
 * 01-Apr-04  Hye-Shik Chang    <perky at FreeBSD.org>
 *      Ported from i386 to amd64.
 * 24-Nov-02  Christian Tismer  <tismer at tismer.com>
 *      needed to add another magic constant to insure
 *      that f in slp_eval_frame(PyFrameObject *f)
 *      STACK_REFPLUS will probably be 1 in most cases.
 *      gets included into the saved stack area.
 * 17-Sep-02  Christian Tismer  <tismer at tismer.com>
 *      after virtualizing stack save/restore, the
 *      stack size shrunk a bit. Needed to introduce
 *      an adjustment STACK_MAGIC per platform.
 * 15-Sep-02  Gerd Woetzel       <gerd.woetzel at GMD.DE>
 *      slightly changed framework for spark
 * 31-Avr-02  Armin Rigo         <arigo at ulb.ac.be>
 *      Added ebx, esi and edi register-saves.
 * 01-Mar-02  Samual M. Rushing  <rushing at ironport.com>
 *      Ported from i386.
 */

#define STACK_REFPLUS 1

#ifdef SLP_EVAL

/* #define STACK_MAGIC 3 */
/* the above works fine with gcc 2.96, but 2.95.3 wants this */
#define STACK_MAGIC 0

#define REGS_TO_SAVE "rdx", "rbx", "r12", "r13", "r14", "r15"


static int
slp_switch(void)
{
    register long *stackref, stsizediff;
    __asm__ volatile ("" : : : REGS_TO_SAVE);
    __asm__ ("movq %%rsp, %0" : "=g" (stackref));
    {
        SLP_SAVE_STATE(stackref, stsizediff);
        __asm__ volatile (
            "addq %0, %%rsp\n"
            "addq %0, %%rbp\n"
            :
            : "r" (stsizediff)
            );
        SLP_RESTORE_STATE();
        return 0;
    }
    __asm__ volatile ("" : : : REGS_TO_SAVE);
}

#endif
/*
 * further self-processing support
 */

/* 
 * if you want to add self-inspection tools, place them
 * here. See the x86_msvc for the necessary defines.
 * These features are highly experimental und not
 * essential yet.
 */

--- NEW FILE: switch_x64_masm.asm ---
;
; stack switching code for MASM on x641
; Kristjan Valur Jonsson, sept 2005
;


;prototypes for our calls
slp_save_state PROTO	
slp_restore_state PROTO


pushxmm MACRO reg
    sub rsp, 16
    .allocstack 16
    movaps [rsp], reg ; faster than movups, but we must be aligned
    ; .savexmm128 reg, offset  (don't know what offset is, no documentation)
ENDM
popxmm MACRO reg
	movaps reg, [rsp] ; faster than movups, but we must be aligned
    add rsp, 16
ENDM

pushreg MACRO reg
	push reg
	.pushreg reg
ENDM
popreg MACRO reg
	pop reg
ENDM


.code
slp_switch PROC FRAME
	;realign stack to 16 bytes after return address push, makes the following faster
	sub rsp,8
	.allocstack 8
	
	pushxmm xmm15
	pushxmm xmm14
	pushxmm xmm13
	pushxmm xmm12
	pushxmm xmm11
	pushxmm xmm10
	pushxmm xmm9
	pushxmm xmm8
	pushxmm xmm7
	pushxmm xmm6
	
	pushreg r15
	pushreg r14
	pushreg r13
	pushreg r12
	
	pushreg rbp
	pushreg rbx
	pushreg rdi
	pushreg rsi
	
	sub rsp, 10h ;allocate the singlefunction argument (must be multiple of 16)
	.allocstack 10h
.endprolog

	lea rcx, [rsp+10h] ;load stack base that we are saving
	call slp_save_state ;pass stackpointer, return offset in eax
	test rax, 1  ; an odd value means that we don't restore
	jnz NORESTORE
	;actual stack switch:
	add rsp, rax
	call slp_restore_state
	xor rax, rax ;return 0
	
EXIT:
	
	add rsp, 10h
	popreg rsi
	popreg rdi
	popreg rbx
	popreg rbp
	
	popreg r12
	popreg r13
	popreg r14
	popreg r15
	
	popxmm xmm6
	popxmm xmm7
	popxmm xmm8
	popxmm xmm9
	popxmm xmm10
	popxmm xmm11
	popxmm xmm12
	popxmm xmm13
	popxmm xmm14
	popxmm xmm15

	add rsp, 8
	ret
	
NORESTORE:
    sar rax, 1 ; return value is -1 for error
    jmp EXIT

slp_switch ENDP 
	
END
--- NEW FILE: switch_x64_msvc.h ---
/*
 * this is the internal transfer function.
 *
 * HISTORY
 * 24-Nov-02  Christian Tismer  <tismer at tismer.com>
 *      needed to add another magic constant to insure
 *      that f in slp_eval_frame(PyFrameObject *f)
 *      STACK_REFPLUS will probably be 1 in most cases.
 *      gets included into the saved stack area.
 * 26-Sep-02  Christian Tismer  <tismer at tismer.com>
 *      again as a result of virtualized stack access,
 *      the compiler used less registers. Needed to
 *      explicit mention registers in order to get them saved.
 *      Thanks to Jeff Senn for pointing this out and help.
 * 17-Sep-02  Christian Tismer  <tismer at tismer.com>
 *      after virtualizing stack save/restore, the
 *      stack size shrunk a bit. Needed to introduce
 *      an adjustment STACK_MAGIC per platform.
 * 15-Sep-02  Gerd Woetzel       <gerd.woetzel at GMD.DE>
 *      slightly changed framework for sparc
 * 01-Mar-02  Christian Tismer  <tismer at tismer.com>
 *      Initial final version after lots of iterations for i386.
 */

#define alloca _alloca

#define STACK_REFPLUS 1

#ifdef SLP_EVAL

#define STACK_MAGIC 0

extern int slp_switch(void); /* defined in masm assembler */

/* These two are called from the assembler module */
SSIZE_T slp_save_state(intptr_t *ref) {
	SSIZE_T diff;
	SLP_SAVE_STATE(ref, diff);
	return diff;
}

void slp_restore_state(void)
{
	SLP_RESTORE_STATE();
}

#endif

/*
 * further self-processing support
 */

/* we have IsBadReadPtr available, so we can peek at objects */
#define STACKLESS_SPY

#ifdef IMPLEMENT_STACKLESSMODULE
#include "Windows.h"
#define CANNOT_READ_MEM(p, bytes) IsBadReadPtr(p, bytes)

static int IS_ON_STACK(void*p)
{
    int stackref;
    intptr_t stackbase = ((intptr_t)&stackref) & 0xfffff000;
    return (intptr_t)p >= stackbase && (intptr_t)p < stackbase + 0x00100000;
} 

#endif


_______________________________________________
Stackless-checkins mailing list
Stackless-checkins at stackless.com
http://www.stackless.com/mailman/listinfo/stackless-checkins



More information about the Stackless-checkins mailing list