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

Use union to bitcast int to float #275

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zeux
Copy link
Contributor

@zeux zeux commented Dec 28, 2021

This fixes GCC's strict-aliasing warning when building basisu with gcc
9.3 in release:

/mnt/c/work/basis_universal/encoder/cppspmd_sse.h: In function ‘float cppspmd_sse41::extractf_ps_x(const __m128&)’:
/mnt/c/work/basis_universal/encoder/cppspmd_sse.h:219:98: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  219 | CPPSPMD_FORCE_INLINE float extractf_ps_x(const __m128& vec) { int v = extract_ps_x(vec); return *(const float*)&v; }
      |                                                                                                  ^~~~~~~~~~~~~~~~

While technically union bitcast still violates strict aliasing,
both clang and gcc support this as an unofficial extension.

This fixes GCC's strict-aliasing warning when building basisu with gcc
9.3 in release. While technically union bitcast still violates strict aliasing,
both clang and gcc support this as an unofficial extension.
@zeux
Copy link
Contributor Author

zeux commented Aug 6, 2022

@richgel999 Let me know if this needs any revisions to be considered for merging

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.

1 participant