public inbox for jit@gcc.gnu.org
 help / color / mirror / Atom feed
From: Basile Starynkevitch <basile@starynkevitch.net>
To: jit@gcc.gnu.org, David Malcolm <dmalcolm@redhat.com>
Subject: Re: wish: gcc_jit_type_get_atomic
Date: Fri, 01 Jan 2016 00:00:00 -0000	[thread overview]
Message-ID: <573EF903.2050007@starynkevitch.net> (raw)
In-Reply-To: <5734193A.2040903@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;
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} ***

  reply	other threads:[~2016-05-20 11:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-01  0:00 Basile Starynkevitch
2016-01-01  0:00 ` Basile Starynkevitch [this message]
2016-01-01  0:00   ` Basile Starynkevitch
2019-01-01  0:00   ` Marc Nieper-Wißkirchen
2016-01-01  0:00 ` David Malcolm
2016-01-01  0:00   ` Basile Starynkevitch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=573EF903.2050007@starynkevitch.net \
    --to=basile@starynkevitch.net \
    --cc=dmalcolm@redhat.com \
    --cc=jit@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).