tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] [PATCH] stdatomic: ld/st/xchg/cmpxchg on simple types


From: Dmitry Selyutin
Subject: Re: [Tinycc-devel] [PATCH] stdatomic: ld/st/xchg/cmpxchg on simple types
Date: Mon, 22 Mar 2021 21:11:17 +0300

"is it really the same type?"
A bit ambiguous wording. What I mean is that, for a naturally-aligned type N, the corresponding call can be generated to routine __atomic_X_N. The code generator doesn't need to care whether types in the _implementation_ of __atomic_X_N must literally match those passed; if the semantics match, this is enough. And, indeed, the code below...

    #include <stdatomic.h>
    #include <stdint.h>

    struct combo {
        uint16_t lo;
        uint16_t hi;
    };

    struct combo xchg(_Atomic(struct combo) *atom, struct combo value)
    {
        return atomic_exchange(atom, value);
    }

...causes the compiler to generate the same code as if it operated on uint32_t.
gcc and clang for x86 inline this code, and this is explicitly allowed by the documentation, with some additional remarks.
It appears to me that the documentation speaks of code generation. We could have emitted a call, and this also would have been OK.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]