2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
6 .. _sh-built-in-functions:
11 The following built-in functions are supported on the SH1, SH2, SH3 and SH4
12 families of processors:
14 .. function:: void __builtin_set_thread_pointer (void *ptr)
16 Sets the :samp:`GBR` register to the specified value :samp:`{ptr}`. This is usually
17 used by system code that manages threads and execution contexts. The compiler
18 normally does not generate code that modifies the contents of :samp:`GBR` and
19 thus the value is preserved across function calls. Changing the :samp:`GBR`
20 value in user code must be done with caution, since the compiler might use
21 :samp:`GBR` in order to access thread local variables.
23 .. function:: void * __builtin_thread_pointer (void)
25 Returns the value that is currently set in the :samp:`GBR` register.
26 Memory loads and stores that use the thread pointer as a base address are
27 turned into :samp:`GBR` based displacement loads and stores, if possible.
37 int get_tcb_value (void)
39 // Generate mov.l @(8,gbr),r0 instruction
40 return ((my_tcb*)__builtin_thread_pointer ())->c;
43 .. function:: unsigned int __builtin_sh_get_fpscr (void)
45 Returns the value that is currently set in the :samp:`FPSCR` register.
47 .. function:: void __builtin_sh_set_fpscr (unsigned int val)
49 Sets the :samp:`FPSCR` register to the specified value :samp:`{val}`, while
50 preserving the current values of the FR, SZ and PR bits.