mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-10 03:40:29 +00:00
Added _Py_HOT_FUNCTION macro
This commit is contained in:
parent
281e84da03
commit
c95ce3a31b
6 changed files with 32 additions and 10 deletions
22
third_party/python/Include/pyport.h
vendored
22
third_party/python/Include/pyport.h
vendored
|
@ -235,6 +235,28 @@ typedef int Py_ssize_clean_t;
|
||||||
#define Py_DEPRECATED(VERSION_UNUSED)
|
#define Py_DEPRECATED(VERSION_UNUSED)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* _Py_HOT_FUNCTION
|
||||||
|
* The hot attribute on a function is used to inform the compiler that the
|
||||||
|
* function is a hot spot of the compiled program. The function is optimized
|
||||||
|
* more aggressively and on many target it is placed into special subsection of
|
||||||
|
* the text section so all hot functions appears close together improving
|
||||||
|
* locality.
|
||||||
|
*
|
||||||
|
* Usage:
|
||||||
|
* int _Py_HOT_FUNCTION x(void) { return 3; }
|
||||||
|
*
|
||||||
|
* Issue #28618: This attribute must not be abused, otherwise it can have a
|
||||||
|
* negative effect on performance. Only the functions were Python spend most of
|
||||||
|
* its time must use it. Use a profiler when running performance benchmark
|
||||||
|
* suite to find these functions.
|
||||||
|
*/
|
||||||
|
#if !IsModeDbg() && defined(__GNUC__) \
|
||||||
|
&& ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 3))
|
||||||
|
#define _Py_HOT_FUNCTION __attribute__((hot))
|
||||||
|
#else
|
||||||
|
#define _Py_HOT_FUNCTION
|
||||||
|
#endif
|
||||||
|
|
||||||
#define RTYPE RTYPE
|
#define RTYPE RTYPE
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#define PyMODINIT_FUNC extern "C" PyObject *
|
#define PyMODINIT_FUNC extern "C" PyObject *
|
||||||
|
|
2
third_party/python/Objects/call.c
vendored
2
third_party/python/Objects/call.c
vendored
|
@ -279,7 +279,7 @@ PyObject_Call(PyObject *callable, PyObject *args, PyObject *kwargs)
|
||||||
|
|
||||||
/* --- PyFunction call functions ---------------------------------- */
|
/* --- PyFunction call functions ---------------------------------- */
|
||||||
|
|
||||||
static PyObject*
|
static PyObject* _Py_HOT_FUNCTION
|
||||||
function_code_fastcall(PyCodeObject *co, PyObject **args, Py_ssize_t nargs,
|
function_code_fastcall(PyCodeObject *co, PyObject **args, Py_ssize_t nargs,
|
||||||
PyObject *globals)
|
PyObject *globals)
|
||||||
{
|
{
|
||||||
|
|
8
third_party/python/Objects/dictobject.c
vendored
8
third_party/python/Objects/dictobject.c
vendored
|
@ -748,7 +748,7 @@ the <dummy> value.
|
||||||
For both, when the key isn't found a DKIX_EMPTY is returned. hashpos returns
|
For both, when the key isn't found a DKIX_EMPTY is returned. hashpos returns
|
||||||
where the key index should be inserted.
|
where the key index should be inserted.
|
||||||
*/
|
*/
|
||||||
static Py_ssize_t
|
static Py_ssize_t _Py_HOT_FUNCTION
|
||||||
lookdict(PyDictObject *mp, PyObject *key,
|
lookdict(PyDictObject *mp, PyObject *key,
|
||||||
Py_hash_t hash, PyObject ***value_addr, Py_ssize_t *hashpos)
|
Py_hash_t hash, PyObject ***value_addr, Py_ssize_t *hashpos)
|
||||||
{
|
{
|
||||||
|
@ -862,7 +862,7 @@ top:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Specialized version for string-only keys */
|
/* Specialized version for string-only keys */
|
||||||
static Py_ssize_t
|
static Py_ssize_t _Py_HOT_FUNCTION
|
||||||
lookdict_unicode(PyDictObject *mp, PyObject *key,
|
lookdict_unicode(PyDictObject *mp, PyObject *key,
|
||||||
Py_hash_t hash, PyObject ***value_addr, Py_ssize_t *hashpos)
|
Py_hash_t hash, PyObject ***value_addr, Py_ssize_t *hashpos)
|
||||||
{
|
{
|
||||||
|
@ -936,7 +936,7 @@ lookdict_unicode(PyDictObject *mp, PyObject *key,
|
||||||
|
|
||||||
/* Faster version of lookdict_unicode when it is known that no <dummy> keys
|
/* Faster version of lookdict_unicode when it is known that no <dummy> keys
|
||||||
* will be present. */
|
* will be present. */
|
||||||
static Py_ssize_t
|
static Py_ssize_t _Py_HOT_FUNCTION
|
||||||
lookdict_unicode_nodummy(PyDictObject *restrict mp, PyObject *restrict key,
|
lookdict_unicode_nodummy(PyDictObject *restrict mp, PyObject *restrict key,
|
||||||
Py_hash_t hash, PyObject ***value_addr,
|
Py_hash_t hash, PyObject ***value_addr,
|
||||||
Py_ssize_t *hashpos)
|
Py_ssize_t *hashpos)
|
||||||
|
@ -1003,7 +1003,7 @@ lookdict_unicode_nodummy(PyDictObject *restrict mp, PyObject *restrict key,
|
||||||
* Split tables only contain unicode keys and no dummy keys,
|
* Split tables only contain unicode keys and no dummy keys,
|
||||||
* so algorithm is the same as lookdict_unicode_nodummy.
|
* so algorithm is the same as lookdict_unicode_nodummy.
|
||||||
*/
|
*/
|
||||||
static Py_ssize_t
|
static Py_ssize_t _Py_HOT_FUNCTION
|
||||||
lookdict_split(PyDictObject *mp, PyObject *key,
|
lookdict_split(PyDictObject *mp, PyObject *key,
|
||||||
Py_hash_t hash, PyObject ***value_addr, Py_ssize_t *hashpos)
|
Py_hash_t hash, PyObject ***value_addr, Py_ssize_t *hashpos)
|
||||||
{
|
{
|
||||||
|
|
4
third_party/python/Objects/frameobject.c
vendored
4
third_party/python/Objects/frameobject.c
vendored
|
@ -461,7 +461,7 @@ static int numfree;
|
||||||
static PyFrameObject *free_list;
|
static PyFrameObject *free_list;
|
||||||
#define PyFrame_MAXFREELIST 200
|
#define PyFrame_MAXFREELIST 200
|
||||||
|
|
||||||
static void
|
static void _Py_HOT_FUNCTION
|
||||||
frame_dealloc(PyFrameObject *restrict f)
|
frame_dealloc(PyFrameObject *restrict f)
|
||||||
{
|
{
|
||||||
PyObject **p, **valuestack;
|
PyObject **p, **valuestack;
|
||||||
|
@ -660,7 +660,7 @@ int _PyFrame_Init()
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyFrameObject*
|
PyFrameObject* _Py_HOT_FUNCTION
|
||||||
_PyFrame_New_NoTrack(PyThreadState *tstate, PyCodeObject *code,
|
_PyFrame_New_NoTrack(PyThreadState *tstate, PyCodeObject *code,
|
||||||
PyObject *globals, PyObject *locals)
|
PyObject *globals, PyObject *locals)
|
||||||
{
|
{
|
||||||
|
|
4
third_party/python/Python/ceval.c
vendored
4
third_party/python/Python/ceval.c
vendored
|
@ -732,7 +732,7 @@ PyObject *
|
||||||
return tstate->interp->eval_frame(f, throwflag);
|
return tstate->interp->eval_frame(f, throwflag);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *
|
PyObject * _Py_HOT_FUNCTION
|
||||||
_PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
|
_PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
|
||||||
{
|
{
|
||||||
#ifdef DXPAIRS
|
#ifdef DXPAIRS
|
||||||
|
@ -4813,7 +4813,7 @@ if (tstate->use_tracing && tstate->c_profilefunc) { \
|
||||||
x = call; \
|
x = call; \
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
forceinline PyObject * _Py_HOT_FUNCTION
|
||||||
call_function(PyObject ***pp_stack, Py_ssize_t oparg, PyObject *kwnames)
|
call_function(PyObject ***pp_stack, Py_ssize_t oparg, PyObject *kwnames)
|
||||||
{
|
{
|
||||||
PyObject **pfunc = (*pp_stack) - oparg - 1;
|
PyObject **pfunc = (*pp_stack) - oparg - 1;
|
||||||
|
|
2
third_party/python/Python/errors.c
vendored
2
third_party/python/Python/errors.c
vendored
|
@ -153,7 +153,7 @@ PyErr_SetString(PyObject *exception, const char *string)
|
||||||
Py_XDECREF(value);
|
Py_XDECREF(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *
|
PyObject * _Py_HOT_FUNCTION
|
||||||
PyErr_Occurred(void)
|
PyErr_Occurred(void)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = _PyThreadState_UncheckedGet();
|
PyThreadState *tstate = _PyThreadState_UncheckedGet();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue