wish: gcc_jit_type_get_atomic

Marc Nieper-Wißkirchen marc@nieper-wisskirchen.de
Tue Jan 1 00:00:00 GMT 2019


)Am Fr., 20. Mai 2016 um 13:46 Uhr schrieb Basile Starynkevitch
<basile@starynkevitch.net>:
>
> 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;

Is this well-defined by the standard? Or do we have to declare `a' as
an atomic int? (I know that this is currently impossible with
libgccjit, but implementing this is the easier part of the original
wish stated in this thread.)

> 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.

This is also one of my wishes. As soon as Andrea's patch
(https://gcc.gnu.org/ml/jit/2019-q1/msg00040.html), as a workaround,
one could write a simple C file defining `put_atomic_a' and
`get_atomic_a' and link its object file with LTO to the code generated
by libgccjit.

-- Marc

[...]

> 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} ***
>


-- 
Prof. Dr. Marc Nieper-Wißkirchen

Universität Augsburg
Institut für Mathematik
Universitätsstraße 14
86159 Augsburg

Tel: 0821/598-2146
Fax: 0821/598-2090

E-Mail: marc.nieper-wisskirchen@math.uni-augsburg.de
Web: www.math.uni-augsburg.de/alg/mitarbeiter/mnieper/



More information about the Jit mailing list