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 compiler macros for endianness #2688

Merged
merged 1 commit into from
Jul 12, 2023
Merged

Use compiler macros for endianness #2688

merged 1 commit into from
Jul 12, 2023

Conversation

kmilos
Copy link
Collaborator

@kmilos kmilos commented Jul 11, 2023

Supersedes #2668 as not fully portable.

Using the same form as in include/config.h

@ghost
Copy link

ghost commented Jul 11, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

Comment on lines +187 to +193
#ifdef __LITTLE_ENDIAN__
return true;
#else
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this macro (__LITTLE_ENDIAN__) sometimes defined when __BYTE_ORDER__ isn't? If so, maybe this logic should be moved to isBigEndianPlatform. I.e. add this to the beginning of isBigEndianPlatform:

#if defined(__BIG_ENDIAN__)
  return true;
#elif defined(__LITTLE_ENDIAN__)
  return false;
#elif ...

Copy link
Collaborator Author

@kmilos kmilos Jul 11, 2023

Choose a reason for hiding this comment

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

__LITTLE_ENDIAN__ is our own macro (potentially) defined in config.h.

Everything else comes from the compiler. AFAICT, there is no definition of __BIG_ENDIAN__.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is this macro (__LITTLE_ENDIAN__) sometimes defined when __BYTE_ORDER__ isn't?

Potentially on WIN32 and MSVC (which AFAIK does not define __BYTE_ORDER__):

#if defined(_WIN32) || defined(__CYGWIN__)

Copy link
Collaborator Author

@kmilos kmilos Jul 11, 2023

Choose a reason for hiding this comment

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

@kevinbackhouse I'm now leveraging these as well.

@codecov
Copy link

codecov bot commented Jul 11, 2023

Codecov Report

Merging #2688 (64fe778) into main (50648dd) will not change coverage.
The diff coverage is 100.00%.

❗ Current head 64fe778 differs from pull request most recent head 7930039. Consider uploading reports for the commit 7930039 to get more accurate results

@@           Coverage Diff           @@
##             main    #2688   +/-   ##
=======================================
  Coverage   63.90%   63.90%           
=======================================
  Files         103      103           
  Lines       22313    22313           
  Branches    10799    10799           
=======================================
  Hits        14260    14260           
  Misses       5828     5828           
  Partials     2225     2225           
Impacted Files Coverage Δ
src/image.cpp 70.19% <100.00%> (ø)

@kmilos kmilos force-pushed the kmilos/fix_endianness branch 3 times, most recently from 082a87d to 936cc01 Compare July 11, 2023 14:13
@neheb
Copy link
Collaborator

neheb commented Jul 11, 2023

For Windows, it's always little endian AFAIK.

@kmilos
Copy link
Collaborator Author

kmilos commented Jul 11, 2023

For Windows, it's always little endian AFAIK.

Yes, and we set __LITTLE_ENDIAN__ in config.h in that case, as I linked above.

@neheb
Copy link
Collaborator

neheb commented Jul 11, 2023

Anyway, a lot of work for this function. Would be nice to just use 84e45a3

Requires GCC9 though.

@kmilos
Copy link
Collaborator Author

kmilos commented Jul 12, 2023

Requires GCC9 though.

I've been fine with this all along. 😉

@kmilos
Copy link
Collaborator Author

kmilos commented Jul 12, 2023

@neheb I'm going to merge this for now as I believe it is more portable, so please rebase your change for eventual GCC 9 (and Clang 9/10?) bump...

@kmilos kmilos merged commit c686bed into main Jul 12, 2023
109 checks passed
@mergify mergify bot deleted the kmilos/fix_endianness branch July 12, 2023 10:28
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.

None yet

3 participants