File tree 3 files changed +50
-8
lines changed
3 files changed +50
-8
lines changed Original file line number Diff line number Diff line change @@ -17,15 +17,26 @@ typedef struct {
17
17
} _PyUOpInstruction ;
18
18
19
19
typedef struct {
20
+ PyObject_VAR_HEAD
20
21
_PyExecutorObject base ;
21
- _PyUOpInstruction trace [_Py_UOP_MAX_TRACE_LENGTH ]; // TODO: variable length
22
+ _PyUOpInstruction trace [1 ];
22
23
} _PyUOpExecutorObject ;
23
24
24
25
_PyInterpreterFrame * _PyUopExecute (
25
26
_PyExecutorObject * executor ,
26
27
_PyInterpreterFrame * frame ,
27
28
PyObject * * stack_pointer );
28
29
30
+ /* Cast argument to _PyUOpExecutorObject* type. */
31
+ #define _PyUOpExecutor_CAST (op ) \
32
+ _Py_CAST(_PyUOpExecutorObject*, (op))
33
+
34
+ static inline Py_ssize_t PyUOpExecutor_GET_SIZE (PyObject * op ) {
35
+ _PyUOpExecutorObject * executor = _PyUOpExecutor_CAST (op );
36
+ return Py_SIZE (executor );
37
+ }
38
+ #define PyUOpExecutor_GET_SIZE (op ) PyUOpExecutor_GET_SIZE(_PyObject_CAST(op))
39
+
29
40
#ifdef __cplusplus
30
41
}
31
42
#endif
Original file line number Diff line number Diff line change 31
31
#define ENABLE_SPECIALIZATION 0
32
32
33
33
34
+ // TODO: continue editing this from tupleobject.c to fit _PyUOpExecutorObject
35
+ static _PyUOpExecutorObject *
36
+ tuple_alloc (Py_ssize_t size )
37
+ {
38
+ _PyUOpExecutorObject * op = maybe_freelist_pop (size );
39
+ if (op == NULL ) {
40
+ /* Check for overflow */
41
+ if ((size_t )size > ((size_t )PY_SSIZE_T_MAX - (sizeof (PyTupleObject ) -
42
+ sizeof (PyObject * ))) / sizeof (PyObject * )) {
43
+ return (_PyUOpExecutorObject * )PyErr_NoMemory ();
44
+ }
45
+ op = PyObject_GC_NewVar (_PyUOpExecutorObject , & PyTuple_Type , size );
46
+ if (op == NULL )
47
+ return NULL ;
48
+ }
49
+ return op ;
50
+ }
51
+
52
+ PyObject *
53
+ PyUOpExecutor_New (_PyUOpInstruction trace [], Py_ssize_t size )
54
+ {
55
+ _PyUOpExecutorObject * op ;
56
+ op = tuple_alloc (size );
57
+ if (op == NULL ) {
58
+ return NULL ;
59
+ }
60
+ for (Py_ssize_t i = 0 ; i < size ; i ++ ) {
61
+ op -> trace [i ] = trace [i ];
62
+ }
63
+ _PyObject_GC_TRACK (op );
64
+ return (PyObject * ) op ;
65
+ }
66
+
34
67
_PyInterpreterFrame *
35
68
_PyUopExecute (_PyExecutorObject * executor , _PyInterpreterFrame * frame , PyObject * * stack_pointer )
36
69
{
Original file line number Diff line number Diff line change @@ -320,13 +320,7 @@ uop_name(int index) {
320
320
static Py_ssize_t
321
321
uop_len (_PyUOpExecutorObject * self )
322
322
{
323
- int count = 0 ;
324
- for (; count < _Py_UOP_MAX_TRACE_LENGTH ; count ++ ) {
325
- if (self -> trace [count ].opcode == 0 ) {
326
- break ;
327
- }
328
- }
329
- return count ;
323
+ return PyUOpExecutor_GET_SIZE (self );
330
324
}
331
325
332
326
static PyObject *
@@ -703,6 +697,10 @@ uop_optimize(
703
697
return -1 ;
704
698
}
705
699
executor -> base .execute = _PyUopExecute ;
700
+ /*
701
+ This should replace PyObject_New and memcpy
702
+ _PyUOpExecutorObject *executor = PyUOpExecutor_New(trace, trace_length);
703
+ */
706
704
memcpy (executor -> trace , trace , trace_length * sizeof (_PyUOpInstruction ));
707
705
if (trace_length < _Py_UOP_MAX_TRACE_LENGTH ) {
708
706
executor -> trace [trace_length ].opcode = 0 ; // Sentinel
You can’t perform that action at this time.
0 commit comments