Skip to content

Commit

Permalink
initial cmq implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
iritkatriel committed Dec 10, 2024
1 parent c91ccbe commit bd44a02
Show file tree
Hide file tree
Showing 21 changed files with 792 additions and 398 deletions.
3 changes: 3 additions & 0 deletions Include/cpython/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ struct _typeobject {
/* bitset of which type-watchers care about this type */
unsigned char tp_watched;
uint16_t tp_versions_used;

/* hooks to specializers */
binaryopspecfunc tp_binary_op_specialize;
};

/* This struct is used by the specializer
Expand Down
19 changes: 17 additions & 2 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ typedef struct {

typedef struct {
_Py_BackoffCounter counter;
uint16_t external_cache[4];
} _PyBinaryOpCache;

#define INLINE_CACHE_ENTRIES_BINARY_OP CACHE_ENTRIES(_PyBinaryOpCache)
Expand Down Expand Up @@ -345,8 +346,8 @@ extern void _Py_Specialize_Call(_PyStackRef callable, _Py_CODEUNIT *instr,
int nargs);
extern void _Py_Specialize_CallKw(_PyStackRef callable, _Py_CODEUNIT *instr,
int nargs);
extern void _Py_Specialize_BinaryOp(_PyStackRef lhs, _PyStackRef rhs, _Py_CODEUNIT *instr,
int oparg, _PyStackRef *locals);
extern int _Py_Specialize_BinaryOp(_PyStackRef lhs, _PyStackRef rhs, _Py_CODEUNIT *instr,
int oparg, _PyStackRef *locals);
extern void _Py_Specialize_CompareOp(_PyStackRef lhs, _PyStackRef rhs,
_Py_CODEUNIT *instr, int oparg);
extern void _Py_Specialize_UnpackSequence(_PyStackRef seq, _Py_CODEUNIT *instr,
Expand Down Expand Up @@ -443,6 +444,12 @@ write_obj(uint16_t *p, PyObject *val)
memcpy(p, &val, sizeof(val));
}

static inline void
write_void(uint16_t *p, void *val)
{
memcpy(p, &val, sizeof(val));
}

static inline uint16_t
read_u16(uint16_t *p)
{
Expand Down Expand Up @@ -473,6 +480,14 @@ read_obj(uint16_t *p)
return val;
}

static inline void *
read_void(uint16_t *p)
{
void *val;
memcpy(&val, p, sizeof(val));
return val;
}

/* See Objects/exception_handling_notes.txt for details.
*/
static inline unsigned char *
Expand Down
5 changes: 5 additions & 0 deletions Include/internal/pycore_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,18 @@ struct _is {
_PyThreadStateImpl _initial_thread;
// _initial_thread should be the last field of PyInterpreterState.
// See https://github.com/python/cpython/issues/127117.

PyBinaryOpSpecializationDescr* binary_op_specialization_list;
};


/* other API */

extern void _PyInterpreterState_Clear(PyThreadState *tstate);

extern PyBinaryOpSpecializationDescr* _Py_Specialize_NewBinaryOpSpecializationDescr(void);
extern void _Py_Specialize_FreeBinaryOpSpecializationDescr(PyBinaryOpSpecializationDescr* descr);
extern void _Py_Specialize_FreeAllSpecializationDescrs(PyInterpreterState *interp);

static inline PyThreadState*
_PyInterpreterState_GetFinalizing(PyInterpreterState *interp) {
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_magic_number.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ PC/launcher.c must also be updated.
*/

#define PYC_MAGIC_NUMBER 3609
#define PYC_MAGIC_NUMBER 3611
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
(little-endian) and then appending b'\r\n'. */
#define PYC_MAGIC_NUMBER_TOKEN \
Expand Down
45 changes: 29 additions & 16 deletions Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bd44a02

Please sign in to comment.