kamlesh kumar via llvm-dev
2020-Mar-25 12:34 UTC
[llvm-dev] __builtin_thread_pointer for RISC-V
Hi Devs, since risc-v has a register $tp which is thread pointer. is it possible to have __builtin_thread_pointer for RISC-V? I am not sure what could be corresponding instructions? ./kamlesh
Sam Elliott via llvm-dev
2020-Mar-25 15:36 UTC
[llvm-dev] __builtin_thread_pointer for RISC-V
Hi kamlesh,
Does GCC provide such a builtin?
At the moment, you can write inline assembly to access the `tp` register if you
need to read it directly, like so (you can directly inline this if you need to):
void* read_thread_pointer(void) {
void* thread_pointer;
asm("mov %0, tp" : "=r"(thread_pointer) : );
return thread_pointer;
}
I am not entirely sure how where `tp` points to in the different thread local
models. There is more information on these models in the RISC-V ELF psABI
document:
https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#thread-local-storage
Sam
> On 25 Mar 2020, at 12:34 pm, kamlesh kumar via llvm-dev <llvm-dev at
lists.llvm.org> wrote:
>
> Hi Devs,
> since risc-v has a register $tp which is thread pointer.
> is it possible to have __builtin_thread_pointer for RISC-V?
> I am not sure what could be corresponding instructions?
>
> ./kamlesh
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
--
Sam Elliott
Software Developer - LLVM and OpenTitan
lowRISC CIC
kamlesh kumar via llvm-dev
2020-Mar-25 16:05 UTC
[llvm-dev] __builtin_thread_pointer for RISC-V
Thanks for your reply Sam, GCC rejects the builtin but clang crashes. On Wed, Mar 25, 2020, 9:06 PM Sam Elliott <selliott at lowrisc.org> wrote:> Hi kamlesh, > > Does GCC provide such a builtin? > > At the moment, you can write inline assembly to access the `tp` register > if you need to read it directly, like so (you can directly inline this if > you need to): > > void* read_thread_pointer(void) { > void* thread_pointer; > asm("mov %0, tp" : "=r"(thread_pointer) : ); > return thread_pointer; > } > > I am not entirely sure how where `tp` points to in the different thread > local models. There is more information on these models in the RISC-V ELF > psABI document: > https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#thread-local-storage > > Sam > > > On 25 Mar 2020, at 12:34 pm, kamlesh kumar via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > > > > Hi Devs, > > since risc-v has a register $tp which is thread pointer. > > is it possible to have __builtin_thread_pointer for RISC-V? > > I am not sure what could be corresponding instructions? > > > > ./kamlesh > > _______________________________________________ > > LLVM Developers mailing list > > llvm-dev at lists.llvm.org > > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > > -- > Sam Elliott > Software Developer - LLVM and OpenTitan > lowRISC CIC > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200325/a3bd8ec0/attachment.html>