comparison Python/ceval.c @ 33318:b57612f61ba3 legacy-trunk

Centralize WITH_TSC processing.
author Martin v. Löwis <martin@v.loewis.de>
date Sun, 29 Aug 2004 15:51:52 +0000
parents f455bbe7ea7e
children af9bedd5a8e7
comparison
equal deleted inserted replaced
33317:cf0ea19869af 33318:b57612f61ba3
14 #include "opcode.h" 14 #include "opcode.h"
15 #include "structmember.h" 15 #include "structmember.h"
16 16
17 #include <ctype.h> 17 #include <ctype.h>
18 18
19 #ifdef WITH_TSC 19 #ifndef WITH_TSC
20 #define rdtscll(var)
21 #else /*WITH_TSC defined*/
20 22
21 typedef unsigned long long uint64; 23 typedef unsigned long long uint64;
22 24
23 #if defined(__ppc__) /* <- Don't know if this is the correct symbol; this 25 #if defined(__ppc__) /* <- Don't know if this is the correct symbol; this
24 section should work for GCC on any PowerPC platform, 26 section should work for GCC on any PowerPC platform,
866 } 868 }
867 } 869 }
868 #endif 870 #endif
869 871
870 /* Main switch on opcode */ 872 /* Main switch on opcode */
871 #ifdef WITH_TSC
872 rdtscll(inst0); 873 rdtscll(inst0);
873 #endif
874 874
875 switch (opcode) { 875 switch (opcode) {
876 876
877 /* BEWARE! 877 /* BEWARE!
878 It is essential that any operation that fails sets either 878 It is essential that any operation that fails sets either
1627 case EXEC_STMT: 1627 case EXEC_STMT:
1628 w = TOP(); 1628 w = TOP();
1629 v = SECOND(); 1629 v = SECOND();
1630 u = THIRD(); 1630 u = THIRD();
1631 STACKADJ(-3); 1631 STACKADJ(-3);
1632 #ifdef WITH_TSC
1633 rdtscll(intr0); 1632 rdtscll(intr0);
1634 #endif
1635 err = exec_statement(f, u, v, w); 1633 err = exec_statement(f, u, v, w);
1636 #ifdef WITH_TSC
1637 rdtscll(intr1); 1634 rdtscll(intr1);
1638 #endif
1639 Py_DECREF(u); 1635 Py_DECREF(u);
1640 Py_DECREF(v); 1636 Py_DECREF(v);
1641 Py_DECREF(w); 1637 Py_DECREF(w);
1642 break; 1638 break;
1643 1639
2009 if (w == NULL) { 2005 if (w == NULL) {
2010 u = POP(); 2006 u = POP();
2011 x = NULL; 2007 x = NULL;
2012 break; 2008 break;
2013 } 2009 }
2014 #ifdef WITH_TSC
2015 rdtscll(intr0); 2010 rdtscll(intr0);
2016 #endif
2017 x = PyEval_CallObject(x, w); 2011 x = PyEval_CallObject(x, w);
2018 #ifdef WITH_TSC
2019 rdtscll(intr1); 2012 rdtscll(intr1);
2020 #endif
2021 Py_DECREF(w); 2013 Py_DECREF(w);
2022 SET_TOP(x); 2014 SET_TOP(x);
2023 if (x != NULL) continue; 2015 if (x != NULL) continue;
2024 break; 2016 break;
2025 2017
2029 if ((x = f->f_locals) == NULL) { 2021 if ((x = f->f_locals) == NULL) {
2030 PyErr_SetString(PyExc_SystemError, 2022 PyErr_SetString(PyExc_SystemError,
2031 "no locals found during 'import *'"); 2023 "no locals found during 'import *'");
2032 break; 2024 break;
2033 } 2025 }
2034 #ifdef WITH_TSC
2035 rdtscll(intr0); 2026 rdtscll(intr0);
2036 #endif
2037 err = import_all_from(x, v); 2027 err = import_all_from(x, v);
2038 #ifdef WITH_TSC
2039 rdtscll(intr1); 2028 rdtscll(intr1);
2040 #endif
2041 PyFrame_LocalsToFast(f, 0); 2029 PyFrame_LocalsToFast(f, 0);
2042 Py_DECREF(v); 2030 Py_DECREF(v);
2043 if (err == 0) continue; 2031 if (err == 0) continue;
2044 break; 2032 break;
2045 2033
2046 case IMPORT_FROM: 2034 case IMPORT_FROM:
2047 w = GETITEM(names, oparg); 2035 w = GETITEM(names, oparg);
2048 v = TOP(); 2036 v = TOP();
2049 #ifdef WITH_TSC
2050 rdtscll(intr0); 2037 rdtscll(intr0);
2051 #endif
2052 x = import_from(v, w); 2038 x = import_from(v, w);
2053 #ifdef WITH_TSC
2054 rdtscll(intr1); 2039 rdtscll(intr1);
2055 #endif
2056 PUSH(x); 2040 PUSH(x);
2057 if (x != NULL) continue; 2041 if (x != NULL) continue;
2058 break; 2042 break;
2059 2043
2060 case JUMP_FORWARD: 2044 case JUMP_FORWARD:
2204 na++; 2188 na++;
2205 n++; 2189 n++;
2206 } else 2190 } else
2207 Py_INCREF(func); 2191 Py_INCREF(func);
2208 sp = stack_pointer; 2192 sp = stack_pointer;
2209 #ifdef WITH_TSC
2210 rdtscll(intr0); 2193 rdtscll(intr0);
2211 #endif
2212 x = ext_do_call(func, &sp, flags, na, nk); 2194 x = ext_do_call(func, &sp, flags, na, nk);
2213 #ifdef WITH_TSC
2214 rdtscll(intr1); 2195 rdtscll(intr1);
2215 #endif
2216 stack_pointer = sp; 2196 stack_pointer = sp;
2217 Py_DECREF(func); 2197 Py_DECREF(func);
2218 2198
2219 while (stack_pointer > pfunc) { 2199 while (stack_pointer > pfunc) {
2220 w = POP(); 2200 w = POP();
2323 2303
2324 } /* switch */ 2304 } /* switch */
2325 2305
2326 on_error: 2306 on_error:
2327 2307
2328 #ifdef WITH_TSC
2329 rdtscll(inst1); 2308 rdtscll(inst1);
2330 #endif
2331 2309
2332 /* Quickly continue if no error occurred */ 2310 /* Quickly continue if no error occurred */
2333 2311
2334 if (why == WHY_NOT) { 2312 if (why == WHY_NOT) {
2335 if (err == 0 && x != NULL) { 2313 if (err == 0 && x != NULL) {
2338 if (PyErr_Occurred()) 2316 if (PyErr_Occurred())
2339 fprintf(stderr, 2317 fprintf(stderr,
2340 "XXX undetected error\n"); 2318 "XXX undetected error\n");
2341 else { 2319 else {
2342 #endif 2320 #endif
2343 #ifdef WITH_TSC
2344 rdtscll(loop1); 2321 rdtscll(loop1);
2345 #endif
2346 continue; /* Normal, fast path */ 2322 continue; /* Normal, fast path */
2347 #ifdef CHECKEXC 2323 #ifdef CHECKEXC
2348 } 2324 }
2349 #endif 2325 #endif
2350 } 2326 }
2459 2435
2460 /* End the loop if we still have an error (or return) */ 2436 /* End the loop if we still have an error (or return) */
2461 2437
2462 if (why != WHY_NOT) 2438 if (why != WHY_NOT)
2463 break; 2439 break;
2464 #ifdef WITH_TSC
2465 rdtscll(loop1); 2440 rdtscll(loop1);
2466 #endif
2467 2441
2468 } /* main loop */ 2442 } /* main loop */
2469 2443
2470 assert(why != WHY_YIELD); 2444 assert(why != WHY_YIELD);
2471 /* Pop remaining stack entries. */ 2445 /* Pop remaining stack entries. */
3558 } 3532 }
3559 } 3533 }
3560 else { 3534 else {
3561 PyObject *callargs; 3535 PyObject *callargs;
3562 callargs = load_args(pp_stack, na); 3536 callargs = load_args(pp_stack, na);
3563 #ifdef WITH_TSC
3564 rdtscll(*pintr0); 3537 rdtscll(*pintr0);
3565 #endif
3566 C_TRACE(x=PyCFunction_Call(func,callargs,NULL)); 3538 C_TRACE(x=PyCFunction_Call(func,callargs,NULL));
3567 #ifdef WITH_TSC
3568 rdtscll(*pintr1); 3539 rdtscll(*pintr1);
3569 #endif
3570 Py_XDECREF(callargs); 3540 Py_XDECREF(callargs);
3571 } 3541 }
3572 } else { 3542 } else {
3573 if (PyMethod_Check(func) && PyMethod_GET_SELF(func) != NULL) { 3543 if (PyMethod_Check(func) && PyMethod_GET_SELF(func) != NULL) {
3574 /* optimize access to bound methods */ 3544 /* optimize access to bound methods */
3582 *pfunc = self; 3552 *pfunc = self;
3583 na++; 3553 na++;
3584 n++; 3554 n++;
3585 } else 3555 } else
3586 Py_INCREF(func); 3556 Py_INCREF(func);
3587 #ifdef WITH_TSC
3588 rdtscll(*pintr0); 3557 rdtscll(*pintr0);
3589 #endif
3590 if (PyFunction_Check(func)) 3558 if (PyFunction_Check(func))
3591 x = fast_function(func, pp_stack, n, na, nk); 3559 x = fast_function(func, pp_stack, n, na, nk);
3592 else 3560 else
3593 x = do_call(func, pp_stack, na, nk); 3561 x = do_call(func, pp_stack, na, nk);
3594 #ifdef WITH_TSC
3595 rdtscll(*pintr1); 3562 rdtscll(*pintr1);
3596 #endif
3597 Py_DECREF(func); 3563 Py_DECREF(func);
3598 } 3564 }
3599 3565
3600 /* What does this do? */ 3566 /* What does this do? */
3601 while ((*pp_stack) > pfunc) { 3567 while ((*pp_stack) > pfunc) {