https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53513

--- Comment #32 from Oleg Endo <olegendo at gcc dot gnu.org> ---
As a next step, I'd like to add built-in functions to get/set the FPSCR on SH.

We have the old __get_fpscr and __set_fpscr functions in libgcc which modify
the __fpscr_values array and the FPSCR.

One idea would be to make __get_fpscr and __set_fpscr built-in functions, so
that new code never generates the respective library calls.  I don't know how
expected/unexpected that would be for users and their existing code.
For example, the current glibc does this in sysdeps/sh/sh4/fpu/fpu_control.h:

#if defined __GNUC__
__BEGIN_DECLS

/* GCC provides this function.  */
extern void __set_fpscr (unsigned long);
#define _FPU_SETCW(cw) __set_fpscr ((cw))
#else
#define _FPU_SETCW(cw) __asm__ ("lds %0,fpscr" : : "r" (cw))
#endif

By making __set_fpscr a builtin it would automagically work, but would never
update the __fpscr_values.  I'm not sure what kind of other fpscr related work
arounds build on top of that.

Alternatively, we could name the built-in functions differently.  I've briefly
checked the docs of other targets, this is what I've found:

aarch64:
     unsigned int __builtin_aarch64_get_fpcr ()
     void __builtin_aarch64_set_fpcr (unsigned int)
     unsigned int __builtin_aarch64_get_fpsr ()
     void __builtin_aarch64_set_fpsr (unsigned int)

ARM:
    unsigned int __builtin_arm_get_fpscr ()
     void __builtin_arm_set_fpscr (unsigned int)

MIPS:
    unsigned int __builtin_mips_get_fcsr (void)
    void __builtin_mips_set_fcsr (unsigned int value)

I'd propose the following for SH:

    unsigned int __builtin_sh_get_fpscr ()
    void __builtin_sh_set_fpscr (unsigned int)

Any opinions or feedback regarding the matter?

Reply via email to