From: Armin R. <ar...@us...> - 2001-12-24 17:01:21
|
Update of /cvsroot/psyco/psyco/c/Python In directory usw-pr-cvs1:/tmp/cvs-serv21727/Python Modified Files: pycheader.h pycompiler.c pycompiler.h Log Message: removed quadratic dispatcher bottleneck Index: pycheader.h =================================================================== RCS file: /cvsroot/psyco/psyco/c/Python/pycheader.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** pycheader.h 2001/12/04 16:12:07 1.1 --- pycheader.h 2001/12/24 17:01:18 1.2 *************** *** 37,53 **** */ ! #define INDEX_LOC_CODE 0 /* running code object */ ! #define INDEX_LOC_GLOBALS 1 /* globals() dict object */ ! #define INDEX_LOC_LOCALS_PLUS 2 /* local variables + stack */ ! #define INDEX_LOC_NEXT_INSTR 3 /* next instruction index */ ! #define NB_LOCALS 4 ! #define LOC_CODE po->vlocals.items[INDEX_LOC_CODE] ! #define LOC_GLOBALS po->vlocals.items[INDEX_LOC_GLOBALS] ! #define LOC_LOCALS_PLUS po->vlocals.items[INDEX_LOC_LOCALS_PLUS] ! #define LOC_NEXT_INSTR po->vlocals.items[INDEX_LOC_NEXT_INSTR] typedef struct { int auto_recursion; /* # levels to auto-compile calls to Python functions */ int iblock; /* index in blockstack */ --- 37,50 ---- */ ! #define INDEX_LOC_GLOBALS 0 /* globals() dict object */ ! #define INDEX_LOC_LOCALS_PLUS 1 /* start of local variables + stack */ ! #define LOC_GLOBALS (po->vlocals.items[INDEX_LOC_GLOBALS]) ! #define LOC_LOCALS_PLUS (po->vlocals.items + INDEX_LOC_LOCALS_PLUS) typedef struct { + PyCodeObject* co; /* code object we are compiling */ + int next_instr; /* next instruction to compile */ int auto_recursion; /* # levels to auto-compile calls to Python functions */ int iblock; /* index in blockstack */ *************** *** 57,61 **** int stack_base; /* number of items before the stack in LOC_LOCALS_PLUS */ int stack_level; /* see note below */ ! char* merge_points; /* see mergepoints.h */ vinfo_t* exc; /* current compile-time (pseudo) exception, see below */ vinfo_t* val; /* exception value */ --- 54,58 ---- int stack_base; /* number of items before the stack in LOC_LOCALS_PLUS */ int stack_level; /* see note below */ ! PyObject* merge_points; /* see mergepoints.h */ vinfo_t* exc; /* current compile-time (pseudo) exception, see below */ vinfo_t* val; /* exception value */ Index: pycompiler.c =================================================================== RCS file: /cvsroot/psyco/psyco/c/Python/pycompiler.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** pycompiler.c 2001/12/05 10:20:37 1.2 --- pycompiler.c 2001/12/24 17:01:18 1.3 *************** *** 313,328 **** DEFINEFN ! void pyc_data_build(PsycoObject* po) { /* rebuild the data in the pyc_data_t */ int i; ! KNOWN_VAR(PyCodeObject*, co, LOC_CODE); ! int stack_base = LOC_LOCALS_PLUS->array->count - co->co_stacksize; ! for (i=stack_base; i<LOC_LOCALS_PLUS->array->count; i++) ! if (LOC_LOCALS_PLUS->array->items[i] == NULL) break; po->pr.stack_base = stack_base; po->pr.stack_level = i - stack_base; ! po->pr.merge_points = psyco_get_merge_points(co); } --- 313,328 ---- DEFINEFN ! void pyc_data_build(PsycoObject* po, PyObject* merge_points) { /* rebuild the data in the pyc_data_t */ int i; ! PyCodeObject* co = po->pr.co; ! int stack_base = po->vlocals.count - co->co_stacksize; ! for (i=stack_base; i<po->vlocals.count; i++) ! if (po->vlocals.items[i] == NULL) break; po->pr.stack_base = stack_base; po->pr.stack_level = i - stack_base; ! po->pr.merge_points = merge_points; } *************** *** 596,600 **** #define CHKSTACK(n) extra_assert(0 <= po->pr.stack_level+(n) && \ po->pr.stack_base+po->pr.stack_level+(n) < \ ! LOC_LOCALS_PLUS->array->count) #define NEXTOP() (bytecode[next_instr++]) --- 596,600 ---- #define CHKSTACK(n) extra_assert(0 <= po->pr.stack_level+(n) && \ po->pr.stack_base+po->pr.stack_level+(n) < \ ! po->vlocals.count) #define NEXTOP() (bytecode[next_instr++]) *************** *** 614,618 **** #define GETNAMEV(i) (PyTuple_GET_ITEM(co->co_names, i)) ! #define GETLOCAL(i) (LOC_LOCALS_PLUS->array->items[i]) #define SETLOCAL(i, v) do { vinfo_decref(GETLOCAL(i), po); \ GETLOCAL(i) = v; } while (0) --- 614,618 ---- #define GETNAMEV(i) (PyTuple_GET_ITEM(co->co_names, i)) ! #define GETLOCAL(i) (LOC_LOCALS_PLUS[i]) #define SETLOCAL(i, v) do { vinfo_decref(GETLOCAL(i), po); \ GETLOCAL(i) = v; } while (0) *************** *** 624,635 **** #define JUMPTO(target) (next_instr = (target)) ! #define SAVE_NEXT_INSTR(next_instr) \ ! (LOC_NEXT_INSTR->source = set_ct_value(LOC_NEXT_INSTR->source, next_instr)) ! #define MISSING_OPCODE(opcode) \ ! case opcode: \ ! PycException_SetString(po, PyExc_PsycoError, \ ! "opcode '" #opcode "' not implemented"); \ ! break --- 624,634 ---- #define JUMPTO(target) (next_instr = (target)) ! #define SAVE_NEXT_INSTR(nextinstr1) (po->pr.next_instr = (nextinstr1)) ! /* #define MISSING_OPCODE(opcode) */ ! /* case opcode: */ ! /* PycException_SetString(po, PyExc_PsycoError, */ ! /* "opcode '" #opcode "' not implemented"); */ ! /* break */ *************** *** 680,684 **** code_t* code = cg->originalmacrocode; vinfo_t* v; ! vinfo_t** stack_a = LOC_LOCALS_PLUS->array->items + po->pr.stack_base; KNOWN_VAR(PyDictObject*, globals, LOC_GLOBALS); PyDictEntry* ep; --- 679,684 ---- code_t* code = cg->originalmacrocode; vinfo_t* v; ! vinfo_t** stack_a = po->vlocals.items + po->pr.stack_base; ! mergepoint_t* mp; KNOWN_VAR(PyDictObject*, globals, LOC_GLOBALS); PyDictEntry* ep; *************** *** 717,721 **** PUSH(v); /* 'v' is now run-time, recompile */ ! target = psyco_compile_code(po)->codeptr; /* XXX don't know what to do with the reference returned by XXX psyco_compile_code() */ --- 717,722 ---- PUSH(v); /* 'v' is now run-time, recompile */ ! mp = psyco_exact_merge_point(po->pr.merge_points, po->pr.next_instr); ! target = psyco_compile_code(po, mp)->codeptr; /* XXX don't know what to do with the reference returned by XXX psyco_compile_code() */ *************** *** 1172,1185 **** static code_t* exit_function(PsycoObject* po) { - int i; vinfo_t** locals_plus; NonVirtualSource retsource; /* clear the stack and the locals */ ! locals_plus = LOC_LOCALS_PLUS->array->items; ! for (i=LOC_LOCALS_PLUS->array->count; i--; ) ! if (locals_plus[i] != NULL) { ! vinfo_decref(locals_plus[i], po); ! locals_plus[i] = NULL; } --- 1173,1186 ---- static code_t* exit_function(PsycoObject* po) { vinfo_t** locals_plus; + vinfo_t** pp; NonVirtualSource retsource; /* clear the stack and the locals */ ! locals_plus = LOC_LOCALS_PLUS; ! for (pp = po->vlocals.items + po->vlocals.count; --pp >= locals_plus; ) ! if (*pp != NULL) { ! vinfo_decref(*pp, po); ! *pp = NULL; } *************** *** 1222,1226 **** { /* 'stack_a' is the Python stack base pointer */ ! vinfo_t** stack_a = LOC_LOCALS_PLUS->array->items + po->pr.stack_base; code_t* code1; --- 1223,1227 ---- { /* 'stack_a' is the Python stack base pointer */ ! vinfo_t** stack_a = po->vlocals.items + po->pr.stack_base; code_t* code1; *************** *** 1229,1236 **** PyErr_Fetch(&old_py_exc, &old_py_val, &old_py_tb); ! while (LOC_NEXT_INSTR != NULL) { /* 'co' is the code object we are interpreting/compiling */ ! KNOWN_VAR(PyCodeObject*, co, LOC_CODE); unsigned char* bytecode = (unsigned char*) PyString_AS_STRING(co->co_code); int opcode=0; /* Current opcode */ --- 1230,1237 ---- PyErr_Fetch(&old_py_exc, &old_py_val, &old_py_tb); ! while (po->pr.next_instr != -1) { /* 'co' is the code object we are interpreting/compiling */ ! PyCodeObject* co = po->pr.co; unsigned char* bytecode = (unsigned char*) PyString_AS_STRING(co->co_code); int opcode=0; /* Current opcode */ *************** *** 1240,1244 **** condition_code_t cc; /* 'next_instr' is the position in the byte-code of the next instr */ ! KNOWN_VAR(int, next_instr, LOC_NEXT_INSTR); /* main loop */ --- 1241,1247 ---- condition_code_t cc; /* 'next_instr' is the position in the byte-code of the next instr */ ! int next_instr = po->pr.next_instr; ! mergepoint_t* mp = psyco_next_merge_point(po->pr.merge_points, ! next_instr+1); /* main loop */ *************** *** 1270,1273 **** --- 1273,1280 ---- end when you are sure everything when fine. */ + /* All opcodes found here must also be listed in mergepoints.c. + Python code objects using a bytecode instruction not listed + in mergepoints.c are never Psyco-ified. */ + switch (opcode) { *************** *** 1386,1395 **** BINARY_OPCODE(BINARY_DIVIDE, PsycoNumber_Divide); ! #ifdef BINARY_FLOOR_DIVIDE ! MISSING_OPCODE(BINARY_FLOOR_DIVIDE); /* XXX */ ! MISSING_OPCODE(BINARY_TRUE_DIVIDE); ! MISSING_OPCODE(INPLACE_FLOOR_DIVIDE); ! MISSING_OPCODE(INPLACE_TRUE_DIVIDE); ! #endif BINARY_OPCODE(BINARY_MODULO, PsycoNumber_Remainder); --- 1393,1402 ---- BINARY_OPCODE(BINARY_DIVIDE, PsycoNumber_Divide); ! /*#ifdef BINARY_FLOOR_DIVIDE ! MISSING_OPCODE(BINARY_FLOOR_DIVIDE); ! MISSING_OPCODE(BINARY_TRUE_DIVIDE); ! MISSING_OPCODE(INPLACE_FLOOR_DIVIDE); ! MISSING_OPCODE(INPLACE_TRUE_DIVIDE); ! #endif*/ BINARY_OPCODE(BINARY_MODULO, PsycoNumber_Remainder); *************** *** 1529,1533 **** goto fine; ! MISSING_OPCODE(PRINT_EXPR); case PRINT_ITEM: --- 1536,1540 ---- goto fine; ! /*MISSING_OPCODE(PRINT_EXPR);*/ case PRINT_ITEM: *************** *** 1572,1577 **** break; ! MISSING_OPCODE(RAISE_VARARGS); ! MISSING_OPCODE(LOAD_LOCALS); case RETURN_VALUE: --- 1579,1584 ---- break; ! /*MISSING_OPCODE(RAISE_VARARGS); ! MISSING_OPCODE(LOAD_LOCALS);*/ case RETURN_VALUE: *************** *** 1580,1587 **** break; ! #ifdef YIELD_VALUE ! MISSING_OPCODE(YIELD_VALUE); ! #endif ! MISSING_OPCODE(EXEC_STMT); case POP_BLOCK: --- 1587,1591 ---- break; ! /*MISSING_OPCODE(EXEC_STMT);*/ case POP_BLOCK: *************** *** 1636,1642 **** } ! MISSING_OPCODE(BUILD_CLASS); ! MISSING_OPCODE(STORE_NAME); ! MISSING_OPCODE(DELETE_NAME); case UNPACK_SEQUENCE: --- 1640,1646 ---- } ! /*MISSING_OPCODE(BUILD_CLASS); ! MISSING_OPCODE(STORE_NAME); ! MISSING_OPCODE(DELETE_NAME);*/ case UNPACK_SEQUENCE: *************** *** 1780,1784 **** goto fine; ! MISSING_OPCODE(LOAD_NAME); case LOAD_GLOBAL: --- 1784,1788 ---- goto fine; ! /*MISSING_OPCODE(LOAD_NAME);*/ case LOAD_GLOBAL: *************** *** 1834,1840 **** goto fine; ! MISSING_OPCODE(LOAD_CLOSURE); ! MISSING_OPCODE(LOAD_DEREF); ! MISSING_OPCODE(STORE_DEREF); case BUILD_TUPLE: --- 1838,1844 ---- goto fine; ! /*MISSING_OPCODE(LOAD_CLOSURE); ! MISSING_OPCODE(LOAD_DEREF); ! MISSING_OPCODE(STORE_DEREF);*/ case BUILD_TUPLE: *************** *** 1909,1914 **** break; ! MISSING_OPCODE(IN); ! MISSING_OPCODE(NOT_IN); case EXC_MATCH: --- 1913,1918 ---- break; ! /*MISSING_OPCODE(IN); ! MISSING_OPCODE(NOT_IN);*/ case EXC_MATCH: *************** *** 1937,1946 **** } ! MISSING_OPCODE(IMPORT_NAME); ! MISSING_OPCODE(IMPORT_STAR); ! MISSING_OPCODE(IMPORT_FROM); case JUMP_FORWARD: JUMPBY(oparg); goto fine; --- 1941,1951 ---- } ! /*MISSING_OPCODE(IMPORT_NAME); ! MISSING_OPCODE(IMPORT_STAR); ! MISSING_OPCODE(IMPORT_FROM);*/ case JUMP_FORWARD: JUMPBY(oparg); + mp = psyco_next_merge_point(po->pr.merge_points, next_instr); goto fine; *************** *** 1962,1970 **** JUMPBY(oparg); SAVE_NEXT_INSTR(next_instr); ! psyco_compile_cond(po, cc); next_instr = current_instr; } ! else if (cc == CC_ALWAYS_TRUE) JUMPBY(oparg); /* always jump */ else ; /* never jump */ --- 1967,1981 ---- JUMPBY(oparg); SAVE_NEXT_INSTR(next_instr); ! psyco_compile_cond(po, ! psyco_exact_merge_point(po->pr.merge_points, ! next_instr), ! cc); next_instr = current_instr; } ! else if (cc == CC_ALWAYS_TRUE) { JUMPBY(oparg); /* always jump */ + mp = psyco_next_merge_point(po->pr.merge_points, + next_instr); + } else ; /* never jump */ *************** *** 1973,1976 **** --- 1984,1988 ---- case JUMP_ABSOLUTE: JUMPTO(oparg); + mp = psyco_next_merge_point(po->pr.merge_points, next_instr); goto fine; *************** *** 1999,2002 **** --- 2011,2016 ---- POP_DECREF(); JUMPBY(oparg); + mp = psyco_next_merge_point(po->pr.merge_points, + next_instr); } else *************** *** 2005,2009 **** goto fine; ! MISSING_OPCODE(FOR_LOOP); case SETUP_LOOP: --- 2019,2023 ---- goto fine; ! /*MISSING_OPCODE(FOR_LOOP);*/ case SETUP_LOOP: *************** *** 2063,2072 **** } ! MISSING_OPCODE(CALL_FUNCTION_VAR); ! MISSING_OPCODE(CALL_FUNCTION_KW); ! MISSING_OPCODE(CALL_FUNCTION_VAR_KW); ! MISSING_OPCODE(MAKE_FUNCTION); ! MISSING_OPCODE(MAKE_CLOSURE); ! MISSING_OPCODE(BUILD_SLICE); case EXTENDED_ARG: --- 2077,2086 ---- } ! /*MISSING_OPCODE(CALL_FUNCTION_VAR); ! MISSING_OPCODE(CALL_FUNCTION_KW); ! MISSING_OPCODE(CALL_FUNCTION_VAR_KW); ! MISSING_OPCODE(MAKE_FUNCTION); ! MISSING_OPCODE(MAKE_CLOSURE); ! MISSING_OPCODE(BUILD_SLICE);*/ case EXTENDED_ARG: *************** *** 2089,2092 **** --- 2103,2108 ---- fine: extra_assert(!PycException_Occurred(po)); + extra_assert(mp == psyco_next_merge_point(po->pr.merge_points, + next_instr)); /* are we running out of space in the current code buffer? */ *************** *** 2094,2108 **** extra_assert(!is_respawning(po)); SAVE_NEXT_INSTR(next_instr); ! code1 = psyco_compile(po, false); goto finished; } /* mark merge points via a call to psyco_compile() */ ! if (CHECK_ARRAY_BIT(po->pr.merge_points, next_instr)) { extra_assert(!is_respawning(po)); SAVE_NEXT_INSTR(next_instr); ! code1 = psyco_compile(po, true); if (code1 != NULL) goto finished; } } /* end of the main loop, exit if exception */ --- 2110,2127 ---- extra_assert(!is_respawning(po)); SAVE_NEXT_INSTR(next_instr); ! if (mp->bytecode_position != next_instr) ! mp = NULL; ! code1 = psyco_compile(po, mp, false); goto finished; } /* mark merge points via a call to psyco_compile() */ ! if (mp->bytecode_position == next_instr) { extra_assert(!is_respawning(po)); SAVE_NEXT_INSTR(next_instr); ! code1 = psyco_compile(po, mp, true); if (code1 != NULL) goto finished; + mp++; } } /* end of the main loop, exit if exception */ *************** *** 2175,2180 **** might represent a pseudo-exception like EReturn. */ int next_instr; ! vinfo_t** stack_a = LOC_LOCALS_PLUS->array->items + ! po->pr.stack_base; vinfo_t* exc_info = PsycoTuple_New(3, NULL); PycException_Fetch(po); --- 2194,2198 ---- might represent a pseudo-exception like EReturn. */ int next_instr; ! vinfo_t** stack_a = po->vlocals.items + po->pr.stack_base; vinfo_t* exc_info = PsycoTuple_New(3, NULL); PycException_Fetch(po); *************** *** 2195,2200 **** and the end of an EXCEPT block. */ int next_instr; ! vinfo_t** stack_a = LOC_LOCALS_PLUS->array->items + ! po->pr.stack_base; while (!PycException_FetchNormalize(po)) { /* got an exception while initializing the EXCEPT --- 2213,2217 ---- and the end of an EXCEPT block. */ int next_instr; ! vinfo_t** stack_a = po->vlocals.items + po->pr.stack_base; while (!PycException_FetchNormalize(po)) { /* got an exception while initializing the EXCEPT *************** *** 2215,2222 **** /* End the function if we still have a (pseudo) exception */ if (PycException_Occurred(po)) { ! /* at the end of the function we set LOC_NEXT_INSTR to NULL because the actual position has no longer any importance */ ! vinfo_decref(LOC_NEXT_INSTR, po); ! LOC_NEXT_INSTR = NULL; } } --- 2232,2238 ---- /* End the function if we still have a (pseudo) exception */ if (PycException_Occurred(po)) { ! /* at the end of the function we set next_instr to -1 because the actual position has no longer any importance */ ! po->pr.next_instr = -1; } } Index: pycompiler.h =================================================================== RCS file: /cvsroot/psyco/psyco/c/Python/pycompiler.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** pycompiler.h 2001/12/06 15:47:29 1.2 --- pycompiler.h 2001/12/24 17:01:18 1.3 *************** *** 293,300 **** /* construction for non-frozen snapshots */ ! EXTERNFN void pyc_data_build(PsycoObject* po); inline void pyc_data_duplicate(pyc_data_t* target, pyc_data_t* source) { memcpy(target, source, sizeof(pyc_data_t)); target->exc = NULL; } inline void pyc_data_release(pyc_data_t* pyc) { --- 293,301 ---- /* construction for non-frozen snapshots */ ! EXTERNFN void pyc_data_build(PsycoObject* po, PyObject* merge_points); inline void pyc_data_duplicate(pyc_data_t* target, pyc_data_t* source) { memcpy(target, source, sizeof(pyc_data_t)); target->exc = NULL; + target->val = NULL; } inline void pyc_data_release(pyc_data_t* pyc) { |