Skip to content

bpo-41617: Fix pycore_bitutils.h to support clang 3.0#21949

Closed
vstinner wants to merge 1 commit into
python:masterfrom
vstinner:bswap16
Closed

bpo-41617: Fix pycore_bitutils.h to support clang 3.0#21949
vstinner wants to merge 1 commit into
python:masterfrom
vstinner:bswap16

Conversation

@vstinner

@vstinner vstinner commented Aug 24, 2020

Copy link
Copy Markdown
Member

__builtin_bswap16() is not available in LLVM clang 3.0.

https://bugs.python.org/issue41617

@corona10

Copy link
Copy Markdown
Member

Please fix compile errors :)

@corona10 corona10 self-requested a review August 25, 2020 14:39
@vstinner

Copy link
Copy Markdown
Member Author

Oh, __has_builtin() was added to GCC 10 and so it works on Fedora 32, but not on Ubuntu 18.04 which uses GCC 7.5.0.

@jmroot

jmroot commented Aug 29, 2020

Copy link
Copy Markdown
Contributor

Yeah, that's why the approach of defining a null __has_builtin is commonly used. Otherwise you have to be more verbose, with nested preprocessor conditionals like:

#ifdef __has_builtin
#if __has_builtin(__builtin_bswap16)
// do thing using __builtin_bswap16
#endif
#endif

@vstinner

Copy link
Copy Markdown
Member Author

Oh oh, the doc job failed because of setuptools 50.0 ...

@vstinner

vstinner commented Sep 1, 2020

Copy link
Copy Markdown
Member Author

@jmroot: Would you mind to review my updated PR? I abandoned my first idea and my PR now defines _Py_has_builtin() which is defined as #define _Py_has_builtin(x) 0 when __has_builtin macro is not defined.

@vstinner

vstinner commented Sep 1, 2020

Copy link
Copy Markdown
Member Author

My PR is very similar to PR #21942, but I want to define the macro in pymacro.h, so _Py_has_builtin() can be used in any Python header file, not only in the internal pycore_bitutils.h header.

__builtin_bswap16() is not available in LLVM clang 3.0.

Add a private _Py_has_builtin() macro: use __has_builtin() if
available, otherwise always return 0.
@vstinner

vstinner commented Sep 1, 2020

Copy link
Copy Markdown
Member Author

PR rebased to retrieve https://bugs.python.org/issue41685 CI fix.

_Py_bswap32(uint32_t word)
{
#ifdef _PY_HAVE_BUILTIN_BSWAP
#if _Py_has_builtin(__builtin_bswap32) || defined(_PY_HAVE_BUILTIN_BSWAP)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the feeling that _Py_has_builtin(__builtin_bswap32) should be used to correctly position _PY_HAVE_BUILTIN_BSWAP instead of being used here. That way if _PY_HAVE_BUILTIN_BSWAP is mentioned elsewhere, it will have the correct value.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_PY_HAVE_BUILTIN_BSWAP is used to get the optimization on GCC older than GCC 10. __has_feature() was added very recently in GCC: in GCC 10.

@vstinner

vstinner commented Sep 1, 2020

Copy link
Copy Markdown
Member Author

_Py_has_builtin() may be more future-proof and more flexible to test the availability of compiler features.

But I also proposed a dummy fix without _Py_has_builtin(): PR #22042.

I have a preference for _Py_has_builtin().

@vstinner

vstinner commented Sep 1, 2020

Copy link
Copy Markdown
Member Author

I merged the simple PR #22042 instead.

@vstinner vstinner closed this Sep 1, 2020
@vstinner vstinner deleted the bswap16 branch September 1, 2020 16:29
@jmroot

jmroot commented Sep 19, 2020

Copy link
Copy Markdown
Contributor

@jmroot: Would you mind to review my updated PR?

Apologies, I never received an email notification for this comment for some reason, so I only saw it just now.

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.

6 participants