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: Michael Matz
Subject: Re: [Tinycc-devel] [PATCH] stdatomic: ld/st/xchg/cmpxchg on simple types
Date: Mon, 22 Mar 2021 18:03:03 +0100 (CET)
User-agent: Alpine 2.21 (LSU 202 2017-01-01)

Hello,

On Mon, 22 Mar 2021, Dmitry Selyutin wrote:

Is the above atomic_load supposed to be similar to the GCC __atomic_load
intrinsic?
No, it's supposed to be similar to __atomic_load_N.

I see. Those return integer types and hence aren't convertible to struct types either (not even with a cast). This doesn't (and shouldn't) compile:

% cat x.c
struct S { short a, b; };
struct S load(struct S *mem)
{
  struct S s;
  s = __atomic_load_4(mem, __ATOMIC_SEQ_CST);
  return s;
}
% gcc -c x.c
x.c: In function ‘load’:
x.c:5:7: error: incompatible types when assigning to type ‘struct S’ from type ‘unsigned int’

hence structs aren't passed around
It depends on the calling convention.

No, it depends on which types the atomic builtins are defined to support. I'm aware that functions that do happen to pass around (or return) structs by value can use registers for this. But the atomic functions don't do that. Are you perhaps talking about the case where the compiler rewrites a generic __atomic_load into a size-specific one, ala:

  __atomic_load(mem, &s, __ATOMIC_SEQ_CST);

into

  <view_convert(struct S)>__atomic_load_4(mem, __ATOMIC_SEQ_CST);

So, are you wanting to do the same for TCC as well? The easier way would rather be to simply not do such rewriting and just keep calling the generic __atomic_load.

So, again, please provide some example code that shows what you want to be compilable (and perhaps also in which way).

For the __atomic_##_N, it seems like we can pass things this way, as
long as pointers are naturally-aligned.
As I mentioned in one of the earlier patches, there's no proper align
check yet, for now we have size check.


Ciao,
Michael.

reply via email to

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