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

Adds several resolutions around endianess #505

Merged
merged 2 commits into from
Oct 8, 2024

Conversation

Sazerac4
Copy link
Contributor

@Sazerac4 Sazerac4 commented Oct 6, 2024

I dug a little deeper into how endianess works and I propose some modifications, tell me what you think.

Endianess detection at compile time

Concerning endianess, this can be detected in two ways

  • C23 standard
  • Compilers features ( GCC, clang, ...)
    • check it : echo | gcc -dM -E - | grep ENDIAN or echo | clang -dM -E - | grep ENDIAN

We can see example to check endianess here:

If not detected, throw an error to force the user to set it. The user will therefore be able to control the endianess depending on the unsupported compiler or standard he use.

Use build-in "swap" function when available

I added a way to detect the header byteswap.h with __has_include. It is maybe not used by all compilers, it is worth it ?
TriceReverse16 and TriceReverse32 can use the appropiate build-in when available and use C implementation if not found. More implementation can be done.
The user can stil defined custom TRICE_HTOTS, TRICE_HTOTL and TRICE_TTOHS if no option at all

Notes:

I removed macros swap option. When using "static inline" functions, the compiler will do the same job as a macros. I do some tests on godbolt. Of course, optimisation level change the behavior but user can set it and use other compiler option to force inlining if needed with TRICE_INLINE.

When searching to support endianess, i found this information that give some compilers names used for embedded systems. Supported compilers and tools:

  • Clang ( Clang is considered to be a production quality C )
  • GNU Compiler Collection (GCC): Open-source and widely used for various architectures.
  • ARM Compiler: Specifically designed for ARM architecture.
  • IAR Embedded Workbench: Offers optimization features and real-time debugging.
  • Keil MDK: Integrated development environment for ARM-based microcontrollers.
  • TI Code Composer Studio: Integrated environment for Texas Instruments' microcontrollers.
  • Microchip XC Compiler: Used for PIC microcontrollers.
  • Green Hills Software Compiler: Known for high-performance embedded systems.

I didn't found if all of them are supported "BYTE_ORDER" variants but it can be a good to check if possible and add the support if it is possible. Otherwise the user need to defined what is needed.

-Add byte orders detection, remove default TRICE_MCU_IS_BIG_ENDIAN. User need to set it if not detected
-Add Detection on <byteswap.h> libc include to use it
-Remove full macros byteswap option, use always "TriceReverse" inline function (same effect)
-Remove endianess configurations options
-Add compilers buid-in when available to swap endianess (GCC and clang supported)
-Add C23 endianess detection resolution
- Correction on error message
- Format: find ./src  -name '*.c' -o  -name '*.h'| xargs clang-format-18 -style=file -i
Copy link
Owner

@rokath rokath left a comment

Choose a reason for hiding this comment

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

Good work!

@rokath rokath merged commit ddeb703 into rokath:master Oct 8, 2024
1 check passed
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