[clang] [libcxx] [libc++] Add builtin to clear padding bytes (prework for P0528R3) (PR #75371)

via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 14 07:16:26 PDT 2024


BukeBeyond wrote:

We have fast AVX256 scanners that detect data change and generate a hash in a united pass.  When this code is inlined, it further optimizes to just a few instructions with constant size structures.

There is a lot of optimization potential for these flat data structures.   We can we use vector instructions to process them in large chunks.  However, padding bytes with random data is a problem.  Detecting padding locations, especially with multiple inheritance is not trivial.  __builtin_clear_padding() solves this problem.

Now we can simply mark a flat structure with;
```
struct F1 : Flat<F1> 
{ 
  int i;
  bool b; 
};
```
where Flat<> simply calls __builtin_clear_padding((F1*) this); at construction.  LLVM unites any redundant writes from further inheritance.  LLVM also combines clear padding and initializated field bytes into larger writes.

These flat objects can be detected with a concept, and now have special powers, like fast comparison and/or hashing, implemented generically outside of these objects.

This is made possible by this work here. 

Thank you!







https://github.com/llvm/llvm-project/pull/75371


More information about the cfe-commits mailing list