Skip to content

Mark Py_EnterRecursiveCall as unlikely#3322

Merged
scoder merged 1 commit intocython:masterfrom
alexhenrie:unlikely
Jan 23, 2020
Merged

Mark Py_EnterRecursiveCall as unlikely#3322
scoder merged 1 commit intocython:masterfrom
alexhenrie:unlikely

Conversation

@alexhenrie
Copy link
Contributor

This allows the compiler to reorganize the code to minimize jumps.

@scoder
Copy link
Contributor

scoder commented Jan 22, 2020

Thanks. Did you see an actual difference for any compiler that you tried? Did you look at the generated assembly, for example?

@alexhenrie
Copy link
Contributor Author

I haven't looked at the assembly output for Py_EnterRecursiveCall specifically, but I did see assembly differences when I removed __builtin_expect from the following very similar test program:

#include <stdio.h>

int main(int argc, char *argv)
{
    if (__builtin_expect(argc < 2, 0)) return -1;
    printf("%s\n", argv[1]);
    return 0;
}

@scoder
Copy link
Contributor

scoder commented Jan 23, 2020

That's ok. I just wanted to know if you saw an actual improvement in any way, because C compilers should be able to guess correctly here even without the unlikely(). The program you showed might look similar, but is actually very different when it comes to C compiler heuristics.

It's not wrong to add the unikely(), just in case.

@scoder scoder merged commit ca5d90e into cython:master Jan 23, 2020
@scoder scoder added this to the 3.0 milestone Jan 23, 2020
@alexhenrie
Copy link
Contributor Author

Thanks!

@alexhenrie alexhenrie deleted the unlikely branch February 10, 2020 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants