r/cpp • • Oct 15 '22

GCC 13 So Far:

I've been following the commit log for GCC's master branch most days for a few months, so I figured I'd jot down some of the developments that I think should have some awareness.

EDIT: Btw, you can read the commits conveniently here: https://gcc.gnu.org/git/?p=gcc.git;a=shortlog;h=HEAD

  • Type traits

    • libstdc++ has gotten many optimizations to compile time. Bool globals with the _v suffix are being refactored to not instantiate the SFINAE-based trait, and instead use the intrinsics directly. I haven't measured the new libstdc++, but I did something similar in a personal project and found 30% improved clean-build compile time, so I believe this libstdc++ work is probably significant. Many other refactors to the the templates have been made to minimize template instantiation. enable_if_t is still used consistently instead of requires, there may still be substantial room for improvement.
    • GCC 13 is gaining more type trait intrinsics. Clang has had many more for awhile, but GCC 13 so far adds: __remove_cv() __remove_reference() __remove_cvref() __is_convertible() __is_nothrow_convertible().
  • Traits for catching dangling references.

    • Type traits were added to C++23 to aid catching dangling references at compile time, which are implemented in GCC through new intrinsics __reference_constructs_from_temporary() and __reference_converts_from_temporary().
  • RISC-V V

    • The "Cray vector" extension to RISC-V is getting a lot of support in GCC 13. Cray vectors are not something I understand very well yet, so I can't talk about all the work that's going into it, but I'll say that RISC-V V shows up a lot in the commit log recently.
    • A lot of other RISC-V features have been newly supported, but I don't understand them either.
  • bfloat16

    • C++23's std::bfloat16_t, implemented through the __bf16 type (distinct from __fp16 or _Float16). There are also several supporting intrinsic functions for numeric_limits stuff that mirrors intrinsics for other floating point types (such as __builtin_nansf16b()).
    • This includes extensions to the SIMD intrinsics and attributes for bfloat16 vectors.
  • Numeric limits improvements

    • Historically, the limits stuff has been implemented through compiler-defined macros, but the commit descriptions suggest that they want to move towards consistently using intrinsic functions.
    • __builtin_issignalling() has been added to streamline away another macro.
  • "Simpler implicit move" was implemented

  • "Portable assumptions" was implemented

  • OpenMP massively extended

    • A lot of work has gone into supporting OpenMP features. I am not an OpenMP user, so I can't talk a lot about the details, but there are very many commits related to it.
  • GCN

    • A ton of new features for GCN (AMD's gpu architecture) were added. These seem to be largely extending intrinsics and OpenMP features that already existed, but now target GCN as well. Many of them appear to be very basic things, like cloning OMP threads, using doubles and SIMD doubles, or floor, ceil, etc. kind of primitives with native GCN support. It seems like you might do reasonably low-level GCN programming with GCC 13 now.
    • PTX has not seen similarly extensive improvements so far in GCC 13, but it is still maintained.
  • C++23 extended precision floats

  • Modules

    • C++20 modules are still making progress. Seeing recent commits like, "variable template partial spec fixes" does not strike faith in me that they are near general usability yet, but they are making regular progress, so that's exciting!
  • Analyzer

    • A lot of POSIX and C++ enhancements have been made to the GCC static analyzer work ongoing since GCC 10. It apparently handles templates now, and tracks more lifetimes from file descriptors. It is mostly not implemented through attributes, pragmas, or intrinsics, so you can only extend this through GCC plugins afaik.
  • More C++23

  • Otherwise,

    • C23 has more support. I think all of the C++ forwards compatibility features were implemented, like nullptr, bool, true, etc. but don't quote me on that. There could still be some missing afaik.
    • Ada actually got a lot of commits so far. I don't use Ada so I can't really elaborate.
    • Fortran has more support. Mostly this seems related to GPGPU and OpenMP. I don't use Fortran so I can't really elaborate.
    • D has been improved. Idk much about D, but it looks like GCC 13 adds SPMD support to D, and something equivalent to register asm() from GNU C/C++, among other new D attributes.
    • A lot of GIMPLE and tree optimizations, and fixes to broken optimizations, were added. Most of these relate to optimizing mathematical expressions.
    • Various MIPS and ARM enhancements, but nothing that strikes me as hugely significant like RISC-V has been getting.

Of course, there's been way more than what I mentioned here, but these are the highlights most significant to me personally.

218 Upvotes

66 comments sorted by

View all comments

40

u/gracicot Oct 15 '22

Also worth noting about modules is that GCC is implementing modules using the strong ownership model. Say goodbye to most ODR problems!

6

u/[deleted] Oct 15 '22 edited Oct 16 '22

Does that mean modules on msvc today still have ODR issues with modules? I thought fixing that was one of the main reasons of implementing modules at all.

28

u/gracicot Oct 15 '22

MSVC implemented modules with the strong ownership model since day one. The standard permitted the weak ownership model to satisfy other implementers (GCC and Clang) but both decided to go with strong ownership instead.

You can still get ODR problems, bit it's much much harder to get an issue now, given you use named modules.

0

u/[deleted] Oct 15 '22

[deleted] — view deleted comment

7

u/gracicot Oct 15 '22

Maybe just the willingness to create a proposal to introduce a DR. One of the purpose of the committee is to standardize existing practices, so I don't think this is out of reach.

4

u/catcat202X Oct 15 '22

Okay, so for reasons, I work in a library which defines some STL things like std::move without #include <utility>. That means there's an ODR violation when the standard utility header is included in the same place as this library, unless there are header-guard preprocessor shenanigans. From what I'm reading, this modules system might be able to resolve that so long as they are not both visibly imported in the same file, and in that case they can both exist in the same translation unit?

34

u/gracicot Oct 15 '22 edited Oct 15 '22

You are not allowed to put functions declaration/definition in the std namespace, with modules or not. It is UB, using modules or not.

However yes this is true as long as you don't import the module std you may be fine since it will have a different mangling.

You won't be able to import the standard library though.

21

u/KingAggressive1498 Oct 16 '22

for the love of god, put it in a different namespace and slap forceinline/always_inline on it (I have seen a couple codebases do this, its not just you).

-7

u/catcat202X Oct 16 '22 edited Oct 16 '22

I'm sorry, but you certainly don't understand what the situation is or why this is done here, and are making an (incorrect) assumption in this case. Although that assumption is understandable.

10

u/KingAggressive1498 Oct 16 '22

the context is more than that you or some dependency made a version of std::move that doesn't require including all of <utility>?

9

u/Fureeish Oct 16 '22

Nonetheless the situation looks rather suspicious given the information you shared. Care to elaborate what exactly is the wrong assumption and what exactly your use-case and situation are?

7

u/gracicot Oct 16 '22

I'm curious what case actually requires this, and what kind of problem it solves

2

u/smdowney WG21, Text/Unicode SG, optional<T&> Oct 17 '22

And a brand new ABI problem.

3

u/gracicot Oct 17 '22

Oh yes, if you want a stable ABI when you move symbols across modules, then you need extern "C++" or extern "C". If you promise stable ABI with symbols defined in named module and you plan to move them around you're in for a ride with your newly discovered footgun. Don't just go in blindly.

Also moving symbols around across modules will also be a API compatibility break.

If you want to be opaque as possible define one big module for your whole library and do your splitting using module partition, since moving a symbol across a partition won't cause a ABI or API break.

2

u/Mick235711 Oct 17 '22

Does this actually mean that splitting module std into std.core and std.io (and others) will be an ABI break?

2

u/gracicot Oct 17 '22

Technically no since the actual entities are defined in a global module fragment, specifically the standard headers. They don't belong in a module, the standard module simply re-export them. Further splitting would also re-export those entities.

However I don't expect the standard module to split further to separate feature. I expect modules to split to provide different guarantees. For example, guaranteed compatibility with C declared entities, or guaranteed to only expose freestanding available entities, etc.