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 jtckdint.h for checked integer operations #217

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

tcbrindle
Copy link
Owner

The jtckdint.h library uses

  • C11 ckd_add() etc when available
  • Otherwise, GNU compiler builtins (__builtin_add_overflow() etc) when available
  • Otherwise, a high-quality fallback implementation

In particular, the fallback implementations look to be rather better than our own fallback impls, and will hopefully lead to better codegen on MSVC where the builtins are not available.

This is a single header implementation of C11's `stdckdint.h` (using the GCC/Clang builtins where possible) which looks like it does a better job than our fallback functions.
* All functions are constexpr
* #include <stdbool.h> to define the `_Bool` type to avoid an error with GCC in C++ mode
* Use GNU builtins (__builtin_add_overflow etc) even when __STRICT_ANSI__ is defined (if upstream GCC and Clang are happy to do use the builtins in strict ANSI mode then so am I)
The jtckdint.h library uses
 * C11 `ckd_add()` etc when available
 * Otherwise, GNU compiler builtins (`__builtin_add_overflow()` etc) when available
 * Otherwise, a high-quality fallback implementation

The fallback implementation looks to be rather better than our own fallback impls, and will hopefully lead to better codegen on MSVC where the builtins are not available.
Copy link

codecov bot commented Nov 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.60%. Comparing base (465d55f) to head (68abce0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #217      +/-   ##
==========================================
- Coverage   98.62%   98.60%   -0.02%     
==========================================
  Files          69       69              
  Lines        2614     2578      -36     
==========================================
- Hits         2578     2542      -36     
  Misses         36       36              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

This is "unreferenced formal parameter", which as of MSVC 19.40 is getting triggered even when the parameter *is* referenced by a different `if constexpr` path.

 https://developercommunity.visualstudio.com/t/Bogus-C4100-unreferenced-formal-paramet/10720820
C4146 unary minus applied to unsigned type
After some experimentation on Compiler Explorer, it seems like we can use FLUX_ALWAYS_INLINE on the one hand and manually "flattening" calls on the other to (hopefully) improve the unoptimised codegen and the debugger experience
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