public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/88101] Implement P0528R3, C++20 cmpxchg and padding bits
       [not found] <bug-88101-4@http.gcc.gnu.org/bugzilla/>
@ 2020-09-15 20:03 ` rodgertq at gcc dot gnu.org
  2020-11-15 17:30 ` jakub at gcc dot gnu.org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: rodgertq at gcc dot gnu.org @ 2020-09-15 20:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88101

--- Comment #4 from Thomas Rodgers <rodgertq at gcc dot gnu.org> ---
(In reply to andysem from comment #2)
> Another use case is C++20 atomic_ref, which may be bound to an object whose
> padding bits are in indeterminate state. An intrinsic to clear padding bits
> without altering the object value could be useful.

Having now implemented atomic<T>::wait for libstdc++, I think the intrinsic to
clear padding bits before calling __builtin_memcmp for generic (trivially
copyable) T's is the right approach.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/88101] Implement P0528R3, C++20 cmpxchg and padding bits
       [not found] <bug-88101-4@http.gcc.gnu.org/bugzilla/>
  2020-09-15 20:03 ` [Bug libstdc++/88101] Implement P0528R3, C++20 cmpxchg and padding bits rodgertq at gcc dot gnu.org
@ 2020-11-15 17:30 ` jakub at gcc dot gnu.org
  2020-11-15 18:56 ` jakub at gcc dot gnu.org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-11-15 17:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88101

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 49563
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49563&action=edit
gcc11-pr88101-wip.patch

Here is completely untested WIP of __builtin_clear_padding builtin, so far
doesn't handle bit-fields, unions, VLAs and has a couple of other FIXMEs.
I'll try to complete this virtually from Baker Island (AoE timezone) tonight
before stage1 closes there.  Also I'll probably need to remember the originally
passed pointer type in e.g. second artificial argument of the builtin (NULL),
in case already before or during lower pass something would forward propagate
the argument.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/88101] Implement P0528R3, C++20 cmpxchg and padding bits
       [not found] <bug-88101-4@http.gcc.gnu.org/bugzilla/>
  2020-09-15 20:03 ` [Bug libstdc++/88101] Implement P0528R3, C++20 cmpxchg and padding bits rodgertq at gcc dot gnu.org
  2020-11-15 17:30 ` jakub at gcc dot gnu.org
@ 2020-11-15 18:56 ` jakub at gcc dot gnu.org
  2020-11-16  9:37 ` jakub at gcc dot gnu.org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-11-15 18:56 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88101

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 49565
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49565&action=edit
gcc11-pr88101-wip.patch

Fixed/updated patch that includes first testcase and passes it.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/88101] Implement P0528R3, C++20 cmpxchg and padding bits
       [not found] <bug-88101-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2020-11-15 18:56 ` jakub at gcc dot gnu.org
@ 2020-11-16  9:37 ` jakub at gcc dot gnu.org
  2020-11-16 11:05 ` jakub at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-11-16  9:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88101

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #49563|0                           |1
        is obsolete|                            |
  Attachment #49565|0                           |1
        is obsolete|                            |
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 49567
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49567&action=edit
gcc11-pr88101-wip.patch

Updated patch that canhandle bit-fields on both little end big endian and can
handle also skipping of large paddings.  Next task unions.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/88101] Implement P0528R3, C++20 cmpxchg and padding bits
       [not found] <bug-88101-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2020-11-16  9:37 ` jakub at gcc dot gnu.org
@ 2020-11-16 11:05 ` jakub at gcc dot gnu.org
  2020-11-20 11:31 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-11-16 11:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88101

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #49567|0                           |1
        is obsolete|                            |

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 49569
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49569&action=edit
gcc11-pr88101-wip.patch

Updated patch to handle unions.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/88101] Implement P0528R3, C++20 cmpxchg and padding bits
       [not found] <bug-88101-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2020-11-16 11:05 ` jakub at gcc dot gnu.org
@ 2020-11-20 11:31 ` cvs-commit at gcc dot gnu.org
  2020-11-27 10:25 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-11-20 11:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88101

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:1bea0d0aa5936cb36b6f86f721ca03c1a1bb601d

commit r11-5196-g1bea0d0aa5936cb36b6f86f721ca03c1a1bb601d
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Nov 20 12:28:34 2020 +0100

    c++: Add __builtin_clear_padding builtin - C++20 P0528R3 compiler side
[PR88101]

    The following patch implements __builtin_clear_padding builtin that clears
    the padding bits in object representation (but preserves value
    representation).  Inside of unions it clears only those padding bits that
    are padding for all the union members (so that it never alters value
    representation).

    It handles trailing padding, padding in the middle of structs including
    bitfields (PDP11 unhandled, I've never figured out how those bitfields
    work), VLAs (doesn't handle variable length structures, but I think almost
    nobody uses them and it isn't worth the extra complexity).  For VLAs and
    sufficiently large arrays it uses runtime clearing loop instead of emitting
    straight-line code (unless arrays are inside of a union).

    The way I think this can be used for atomics is e.g. if the structures
    are power of two sized and small enough that we use the hw atomics
    for say compare_exchange __builtin_clear_padding could be called first on
    the address of expected and desired arguments (for desired only if we want
    to ensure that most of the time the atomic memory will have padding bits
    cleared), then perform the weak cmpxchg and if that fails, we got the
    value from the atomic memory; we can call __builtin_clear_padding on a copy
    of that and then compare it with expected, and if it is the same with the
    padding bits masked off, we can use the original with whatever random
    padding bits in it as the new expected for next cmpxchg.
    __builtin_clear_padding itself is not atomic and therefore it shouldn't
    be called on the atomic memory itself, but compare_exchange*'s expected
    argument is a reference and normally the implementation may store there
    the current value from memory, so padding bits can be cleared in that,
    and desired is passed by value rather than reference, so clearing is fine
    too.
    When using libatomic, we can use it either that way, or add new libatomic
    APIs that accept another argument, pointer to the padding bit bitmask,
    and construct that in the template as
      alignas (_T) unsigned char _mask[sizeof (_T)];
      std::memset (_mask, ~0, sizeof (_mask));
      __builtin_clear_padding ((_T *) _mask);
    which will have bits cleared for padding bits and set for bits taking part
    in the value representation.  Then libatomic could internally instead
    of using memcmp compare
    for (i = 0; i < N; i++) if ((val1[i] & mask[i]) != (val2[i] & mask[i]))

    2020-11-20  Jakub Jelinek  <jakub@redhat.com>

            PR libstdc++/88101
    gcc/
            * builtins.def (BUILT_IN_CLEAR_PADDING): New built-in function.
            * gimplify.c (gimplify_call_expr): Rewrite single argument
            BUILT_IN_CLEAR_PADDING into two-argument variant.
            * gimple-fold.c (clear_padding_unit, clear_padding_buf_size): New
            const variables.
            (struct clear_padding_struct): New type.
            (clear_padding_flush, clear_padding_add_padding,
            clear_padding_emit_loop, clear_padding_type,
            clear_padding_union, clear_padding_real_needs_padding_p,
            clear_padding_type_may_have_padding_p,
            gimple_fold_builtin_clear_padding): New functions.
            (gimple_fold_builtin): Handle BUILT_IN_CLEAR_PADDING.
            * doc/extend.texi (__builtin_clear_padding): Document.
    gcc/c-family/
            * c-common.c (check_builtin_function_arguments): Handle
            BUILT_IN_CLEAR_PADDING.
    gcc/testsuite/
            * c-c++-common/builtin-clear-padding-1.c: New test.
            * c-c++-common/torture/builtin-clear-padding-1.c: New test.
            * c-c++-common/torture/builtin-clear-padding-2.c: New test.
            * c-c++-common/torture/builtin-clear-padding-3.c: New test.
            * c-c++-common/torture/builtin-clear-padding-4.c: New test.
            * c-c++-common/torture/builtin-clear-padding-5.c: New test.
            * g++.dg/torture/builtin-clear-padding-1.C: New test.
            * g++.dg/torture/builtin-clear-padding-2.C: New test.
            * gcc.dg/builtin-clear-padding-1.c: New test.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/88101] Implement P0528R3, C++20 cmpxchg and padding bits
       [not found] <bug-88101-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2020-11-20 11:31 ` cvs-commit at gcc dot gnu.org
@ 2020-11-27 10:25 ` cvs-commit at gcc dot gnu.org
  2021-02-02 19:45 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-11-27 10:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88101

--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:bf0a63a1f47525d1c466dbb84616dcb72010affa

commit r11-5490-gbf0a63a1f47525d1c466dbb84616dcb72010affa
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Nov 27 11:23:45 2020 +0100

    gimple-fold: Fix another __builtin_clear_padding ICE

    When playing with __builtin_bit_cast, I have noticed
__builtin_clear_padding
    ICE on the G class below.  The artificial field with D type has offset 0
    and size 8 bytes, but the following artificial field with E type has offset
    0 and size 0, so it triggers the asserts that we don't move current
position
    backwards.  Fixed by ignoring is_empty_type (TREE_TYPE (field)) fields, all
    of their bits are padding which is what is added when skipping over to next
    field anyway.

    2020-11-27  Jakub Jelinek  <jakub@redhat.com>

            PR libstdc++/88101
            * gimple-fold.c (clear_padding_type): Ignore fields with
is_empty_type
            types.

            * g++.dg/torture/builtin-clear-padding-3.C: New test.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/88101] Implement P0528R3, C++20 cmpxchg and padding bits
       [not found] <bug-88101-4@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2020-11-27 10:25 ` cvs-commit at gcc dot gnu.org
@ 2021-02-02 19:45 ` mpolacek at gcc dot gnu.org
  2021-02-02 19:48 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-02-02 19:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88101

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #11 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Any remaining work here?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/88101] Implement P0528R3, C++20 cmpxchg and padding bits
       [not found] <bug-88101-4@http.gcc.gnu.org/bugzilla/>
                   ` (7 preceding siblings ...)
  2021-02-02 19:45 ` mpolacek at gcc dot gnu.org
@ 2021-02-02 19:48 ` jakub at gcc dot gnu.org
  2022-09-07 12:22 ` redi at gcc dot gnu.org
  2022-09-08 18:37 ` redi at gcc dot gnu.org
  10 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-02-02 19:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88101

--- Comment #12 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The compiler side is done, but the libstdc++-v3 side is not on the trunk yet.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/88101] Implement P0528R3, C++20 cmpxchg and padding bits
       [not found] <bug-88101-4@http.gcc.gnu.org/bugzilla/>
                   ` (8 preceding siblings ...)
  2021-02-02 19:48 ` jakub at gcc dot gnu.org
@ 2022-09-07 12:22 ` redi at gcc dot gnu.org
  2022-09-08 18:37 ` redi at gcc dot gnu.org
  10 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2022-09-07 12:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88101

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch

--- Comment #13 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Library patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2022-September/601218.html

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug libstdc++/88101] Implement P0528R3, C++20 cmpxchg and padding bits
       [not found] <bug-88101-4@http.gcc.gnu.org/bugzilla/>
                   ` (9 preceding siblings ...)
  2022-09-07 12:22 ` redi at gcc dot gnu.org
@ 2022-09-08 18:37 ` redi at gcc dot gnu.org
  10 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2022-09-08 18:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88101

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |13.0
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #14 from Jonathan Wakely <redi at gcc dot gnu.org> ---
With r13-2548-g157236dbd62164 the library side is done, so this is complete.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-09-08 18:37 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-88101-4@http.gcc.gnu.org/bugzilla/>
2020-09-15 20:03 ` [Bug libstdc++/88101] Implement P0528R3, C++20 cmpxchg and padding bits rodgertq at gcc dot gnu.org
2020-11-15 17:30 ` jakub at gcc dot gnu.org
2020-11-15 18:56 ` jakub at gcc dot gnu.org
2020-11-16  9:37 ` jakub at gcc dot gnu.org
2020-11-16 11:05 ` jakub at gcc dot gnu.org
2020-11-20 11:31 ` cvs-commit at gcc dot gnu.org
2020-11-27 10:25 ` cvs-commit at gcc dot gnu.org
2021-02-02 19:45 ` mpolacek at gcc dot gnu.org
2021-02-02 19:48 ` jakub at gcc dot gnu.org
2022-09-07 12:22 ` redi at gcc dot gnu.org
2022-09-08 18:37 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).