Can I ask GCC not to emit atomic instructions for a specific address range?

37 views
Skip to first unread message

Jerry Ho

unread,
Oct 25, 2023, 5:30:50 AM10/25/23
to RISC-V SW Dev
If I compile a C program using -march=rv32imac, it will generate atomic operations for any address range, even though some address range of my SOC configuration just does not support atomic operations.
Therefore, is there a way to tell gcc only generate atomic inst for only the address ranges I specify? 
Any help will be appreciated, Thanks

Christoph Müllner

unread,
Oct 25, 2023, 7:22:44 AM10/25/23
to Jerry Ho, RISC-V SW Dev
Compilers don't generate atomic instructions without explicitly being
told to do so.
E.g. by using built-ins like type __atomic_add_fetch (type *ptr, type
val, int memorder).
Further, you provide a pointer (i.e., a register containing an
address), so the compiler does
not even know the address at compile time and can therefore not
enforce restrictions.
And the same compiled code can run (and should) run on multiple systems,
so any address range with some properties on one system has different
properties on
another system.

It is very unusual to directly use atomic builtins or inline assembly
in application code
(for portability reasons). Instead they are typically hidden behind a
thin abstraction layer
(e.g. macros or static-inline functions). If this is also the case in
your code base, then you
could implement the range checks there.

BR
Christoph



>
> --
> You received this message because you are subscribed to the Google Groups "RISC-V SW Dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sw-dev+un...@groups.riscv.org.
> To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/sw-dev/db75421e-4de4-4807-8327-cb147c5924ccn%40groups.riscv.org.
Reply all
Reply to author
Forward
0 new messages