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

Re: wish: gcc_jit_type_get_atomic



Hello All,

In message https://gcc.gnu.org/ml/jit/2016-q2/msg00013.html David Malcolm nicely explained that

Client code might be able to implement it without explicit libgccjit support
by generating calls to the relevant builtins "by hand".


But I am not sure to understand exactly how that can be done in (more or less portable) C code calling libgccjit-6. In particular I am thinking of coding in C some code which would use libgccjit-6 but would not be compiled by gcc-6 (but some other C compiler, perhaps a future gcc-7, or clang, or tinycc, etc...)

What I am understanding is that I should construct with GCCJIT an AST similar to the following C code:

extern int a;
extern void show_int(int);

int
get_atomic_a ()
{
  return __atomic_load_n (&a, __ATOMIC_SEQ_CST);
}

void
put_atomic_a(int x)
{
  __atomic_store_n(&a, x,  __ATOMIC_SEQ_CST);
}

void
show_atomic_seq_cst(void)
{
  show_int(__ATOMIC_SEQ_CST);
}

Please notice that AFAIU, the __ATOMIC_SEQ_CST name is not standardized in C99 (or C11) -but I could be very wrong-. Also, there is no #include in the above code. On my Debian/Linux/x86-64 machine, __ATOMIC_SEQ_CST (I don't know how magic it is in GCC; is it a preprocessor symbol or some magic enum?) happens to be 5 (I examined the assembler code generated by gcc-6 -O1 -fverbose-asm -S on above C code). But can I be sure that it would be defined, and defined to the same value, with other C compilers.

My feeling (but I might be wrong) is that GCCJIT should give some way to retrieve that __ATOMIC_SEQ_CST. Apparently it is a magic preprocessor symbol (perhaps GCC specific!) implemented in gcc/cppbuiltin.c (near line 68, defined as MEMMODEL_SEQ_CST); but if I understand correctly GCCJIT does not give access to the compiler's magic preprocessor symbols.

I feel that GCCJIT might want to have a function like
int gccjit_atomic_seq_cst_value(); // value of __ATOMIC_SEQ_CST in the GCC used by GCCJIT
or perhaps a more general function
int gccjit_compiler_magic_int(const char*);
that I would call as gccjit_compiler_magic_int("__ATOMIC_SEQ_CST");

Perhaps I am misunderstanding something obvious (I have a cold right now because of allergy, so my thinking is not the best), but I cannot understand today how exactly should I build in GCCJIT6 the gcc_jit_function-s equivalent to my get_atomic_a & put_atomic_a.... So please explain if you can!

Regards.

--
Basile STARYNKEVITCHhttp://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mine, sont seulement les miennes} ***