Jeroen Demeyer schrieb am 26.06.19 um 17:08:
On 2019-06-23 08:45, Stefan Behnel wrote:
For internal use in CPython, we could also add a generic inline function
_PyObject_CallObjectPosArgs(PyObject *func, int nargs, ...)
and special-case its implementation with a switch statement for nargs in (0,1,2). The C-compiler should be more than happy to generate the expected code for us.
I tested this on simple proof-of-concept code and the generated code is far from optimal. So unfortunately this isn't a good solution.
GCC never inlines a varargs function. But it's still reasonable: it doesn't generate code for va_start() and va_arg() if it doesn't need to. In particular, if all va_arg() calls are in a predicable order, then the function behaves as if the arguments were passed normally and it doesn't generate code for va_start() and va_arg().
Clang is much worse: it doesn't seem to apply any optimizations, it always fully executes va_start().
Thanks for trying out the idea, Jeroen.
Stefan