Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__Pyx_PyInt_TrueDivideObjC: switch comparison order #494

Merged
merged 1 commit into from
Feb 29, 2016
Merged

__Pyx_PyInt_TrueDivideObjC: switch comparison order #494

merged 1 commit into from
Feb 29, 2016

Conversation

Nikratio
Copy link
Contributor

The current order results in compiler warnings on 32 bit machines, e.g.

src/llfuse.c: In function '__Pyx_PyInt_TrueDivideObjC':
src/llfuse.c:43980:17: warning: left shift count >= width of type
if (8 * sizeof(long) <= 53 || (__Pyx_sst_abs(size) <= 52 / PyLong_SHIFT) || likely(labs(a) <= (1L << 53))) {

Switching the order so that the left shift is closer to the sizeof test
avoids the warning, presumably because it makes it easier for the
compiler to see that the left shift is only executed on 64 bit.

Thanks to Christian Neukirchen for doing most of the work!

The current order results in compiler warnings on 32 bit machines, e.g.

src/llfuse.c: In function '__Pyx_PyInt_TrueDivideObjC':
src/llfuse.c:43980:17: warning: left shift count >= width of type
                 if (8 * sizeof(long) <= 53 || (__Pyx_sst_abs(size) <= 52 / PyLong_SHIFT) || likely(labs(a) <= (1L << 53))) {

Switching the order so that the left shift is closer to the sizeof test
avoids the warning, presumably because it makes it easier for the
compiler to see that the left shift is only executed on 64 bit.

Thanks to Christian Neukirchen for doing most of the work!
@Nikratio
Copy link
Contributor Author

@scoder
Copy link
Contributor

scoder commented Feb 29, 2016

I'm not opposed to this, but the problem is, warnings that go away with one C compiler when moving around code may not go away (or may even appear) with another. gcc and clang tend to be unequal competitors here, for example.

I faintly recall there being some (CPython?) preprocessor macros that could hide that code entirely on 32bit-long platforms. They might provide a better fix.

@scoder
Copy link
Contributor

scoder commented Feb 29, 2016

Hmm, actually, reading through the comments in the ticket makes this appear quite reasonable. Thanks to Christian and you for figuring this out.

scoder added a commit that referenced this pull request Feb 29, 2016
__Pyx_PyInt_TrueDivideObjC: switch comparison order
@scoder scoder merged commit 812cd06 into cython:master Feb 29, 2016
@Nikratio Nikratio deleted the bugfix2 branch February 29, 2016 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants