]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/doc/gcc/extensions-to-the-c-language-family/target-builtins/sh-built-in-functions.rst
sphinx: copy files from texi2rst-generated repository
[thirdparty/gcc.git] / gcc / doc / gcc / extensions-to-the-c-language-family / target-builtins / sh-built-in-functions.rst
1 ..
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.
5
6 .. _sh-built-in-functions:
7
8 SH Built-in Functions
9 ^^^^^^^^^^^^^^^^^^^^^
10
11 The following built-in functions are supported on the SH1, SH2, SH3 and SH4
12 families of processors:
13
14 .. function:: void __builtin_set_thread_pointer (void *ptr)
15
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.
22
23 .. function:: void * __builtin_thread_pointer (void)
24
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.
28 For example:
29
30 .. code-block:: c++
31
32 struct my_tcb
33 {
34 int a, b, c, d, e;
35 };
36
37 int get_tcb_value (void)
38 {
39 // Generate mov.l @(8,gbr),r0 instruction
40 return ((my_tcb*)__builtin_thread_pointer ())->c;
41 }
42
43 .. function:: unsigned int __builtin_sh_get_fpscr (void)
44
45 Returns the value that is currently set in the :samp:`FPSCR` register.
46
47 .. function:: void __builtin_sh_set_fpscr (unsigned int val)
48
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.