Blame sysdeps/powerpc/fpu_control.h

Packit 6c4009
/* FPU control word definitions.  PowerPC version.
Packit 6c4009
   Copyright (C) 1996-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef _FPU_CONTROL_H
Packit 6c4009
#define _FPU_CONTROL_H
Packit 6c4009
Packit 6c4009
#ifdef _SOFT_FLOAT
Packit 6c4009
Packit 6c4009
# define _FPU_RESERVED 0xffffffff
Packit 6c4009
# define _FPU_DEFAULT  0x00000000 /* Default value.  */
Packit 6c4009
typedef unsigned int fpu_control_t;
Packit 6c4009
# define _FPU_GETCW(cw) (cw) = 0
Packit 6c4009
# define _FPU_SETCW(cw) (void) (cw)
Packit 6c4009
extern fpu_control_t __fpu_control;
Packit 6c4009
Packit 6c4009
#elif defined __NO_FPRS__ /* e500 */
Packit 6c4009
Packit 6c4009
/* rounding control */
Packit 6c4009
# define _FPU_RC_NEAREST 0x00   /* RECOMMENDED */
Packit 6c4009
# define _FPU_RC_DOWN    0x03
Packit 6c4009
# define _FPU_RC_UP      0x02
Packit 6c4009
# define _FPU_RC_ZERO    0x01
Packit 6c4009
Packit 6c4009
/* masking of interrupts */
Packit 6c4009
# define _FPU_MASK_ZM  0x10 /* zero divide */
Packit 6c4009
# define _FPU_MASK_OM  0x04 /* overflow */
Packit 6c4009
# define _FPU_MASK_UM  0x08 /* underflow */
Packit 6c4009
# define _FPU_MASK_XM  0x40 /* inexact */
Packit 6c4009
# define _FPU_MASK_IM  0x20 /* invalid operation */
Packit 6c4009
Packit 6c4009
# define _FPU_RESERVED 0x00c10080 /* These bits are reserved and not changed. */
Packit 6c4009
Packit 6c4009
/* Correct IEEE semantics require traps to be enabled at the hardware
Packit 6c4009
   level; the kernel then does the emulation and determines whether
Packit 6c4009
   generation of signals from those traps was enabled using prctl.  */
Packit 6c4009
# define _FPU_DEFAULT  0x0000003c /* Default value.  */
Packit 6c4009
# define _FPU_IEEE     _FPU_DEFAULT
Packit 6c4009
Packit 6c4009
/* Type of the control word.  */
Packit 6c4009
typedef unsigned int fpu_control_t;
Packit 6c4009
Packit 6c4009
/* Macros for accessing the hardware control word.  */
Packit 6c4009
# define _FPU_GETCW(cw) \
Packit 6c4009
  __asm__ volatile ("mfspefscr %0" : "=r" (cw))
Packit 6c4009
# define _FPU_SETCW(cw) \
Packit 6c4009
  __asm__ volatile ("mtspefscr %0" : : "r" (cw))
Packit 6c4009
Packit 6c4009
/* Default control word set at startup.  */
Packit 6c4009
extern fpu_control_t __fpu_control;
Packit 6c4009
Packit 6c4009
#else /* PowerPC 6xx floating-point.  */
Packit 6c4009
Packit 6c4009
/* rounding control */
Packit 6c4009
# define _FPU_RC_NEAREST 0x00   /* RECOMMENDED */
Packit 6c4009
# define _FPU_RC_DOWN    0x03
Packit 6c4009
# define _FPU_RC_UP      0x02
Packit 6c4009
# define _FPU_RC_ZERO    0x01
Packit 6c4009
Packit Service 390399
# define _FPU_MASK_RC (_FPU_RC_NEAREST|_FPU_RC_DOWN|_FPU_RC_UP|_FPU_RC_ZERO)
Packit Service 390399
Packit 6c4009
# define _FPU_MASK_NI  0x04 /* non-ieee mode */
Packit 6c4009
Packit 6c4009
/* masking of interrupts */
Packit 6c4009
# define _FPU_MASK_ZM  0x10 /* zero divide */
Packit 6c4009
# define _FPU_MASK_OM  0x40 /* overflow */
Packit 6c4009
# define _FPU_MASK_UM  0x20 /* underflow */
Packit 6c4009
# define _FPU_MASK_XM  0x08 /* inexact */
Packit 6c4009
# define _FPU_MASK_IM  0x80 /* invalid operation */
Packit 6c4009
Packit 6c4009
# define _FPU_RESERVED 0xffffff00 /* These bits are reserved are not changed. */
Packit 6c4009
Packit 6c4009
/* The fdlibm code requires no interrupts for exceptions.  */
Packit 6c4009
# define _FPU_DEFAULT  0x00000000 /* Default value.  */
Packit 6c4009
Packit 6c4009
/* IEEE:  same as above, but (some) exceptions;
Packit 6c4009
   we leave the 'inexact' exception off.
Packit 6c4009
 */
Packit 6c4009
# define _FPU_IEEE     0x000000f0
Packit 6c4009
Packit 6c4009
/* Type of the control word.  */
Packit 6c4009
typedef unsigned int fpu_control_t;
Packit 6c4009
Packit 6c4009
/* Macros for accessing the hardware control word.  */
Packit 6c4009
# define _FPU_GETCW(cw)						\
Packit 6c4009
  ({union { double __d; unsigned long long __ll; } __u;		\
Packit Service c25693
    __asm__ __volatile__("mffs %0" : "=f" (__u.__d));		\
Packit 6c4009
    (cw) = (fpu_control_t) __u.__ll;				\
Packit 6c4009
    (fpu_control_t) __u.__ll;					\
Packit 6c4009
  })
Packit 6c4009
Packit Service c25693
# define _FPU_GET_RC_ISA300()						\
Packit Service c25693
  ({union { double __d; unsigned long long __ll; } __u;			\
Packit Service c25693
    __asm__ __volatile__(						\
Packit Service c25693
      ".machine push; .machine \"power9\"; mffsl %0; .machine pop" 	\
Packit Service c25693
      : "=f" (__u.__d));						\
Packit Service c25693
    (fpu_control_t) (__u.__ll & _FPU_MASK_RC);				\
Packit Service 390399
  })
Packit Service c25693
Packit Service c25693
# ifdef _ARCH_PWR9
Packit Service c25693
#  define _FPU_GET_RC() _FPU_GET_RC_ISA300()
Packit Service c25693
# elif defined __BUILTIN_CPU_SUPPORTS__
Packit Service c25693
#  define _FPU_GET_RC()							\
Packit Service c25693
  ({fpu_control_t __rc;							\
Packit Service c25693
    __rc = __glibc_likely (__builtin_cpu_supports ("arch_3_00"))	\
Packit Service c25693
      ? _FPU_GET_RC_ISA300 ()						\
Packit Service c25693
      : _FPU_GETCW (__rc) & _FPU_MASK_RC;				\
Packit Service c25693
    __rc;								\
Packit Service c25693
  })
Packit Service c25693
# else
Packit Service c25693
#  define _FPU_GET_RC()						\
Packit Service c25693
  ({fpu_control_t __rc = _FPU_GETCW (__rc) & _FPU_MASK_RC;	\
Packit Service c25693
    __rc;							\
Packit Service 390399
  })
Packit Service c25693
# endif
Packit Service 390399
Packit 6c4009
# define _FPU_SETCW(cw)						\
Packit 6c4009
  { union { double __d; unsigned long long __ll; } __u;		\
Packit 6c4009
    register double __fr;					\
Packit 6c4009
    __u.__ll = 0xfff80000LL << 32; /* This is a QNaN.  */	\
Packit 6c4009
    __u.__ll |= (cw) & 0xffffffffLL;				\
Packit 6c4009
    __fr = __u.__d;						\
Packit Service 5c13a8
    __asm__ __volatile__("mtfsf 255,%0" : : "f" (__fr));	\
Packit 6c4009
  }
Packit 6c4009
Packit 6c4009
/* Default control word set at startup.  */
Packit 6c4009
extern fpu_control_t __fpu_control;
Packit 6c4009
Packit 6c4009
#endif /* PowerPC 6xx floating-point.  */
Packit 6c4009
Packit 6c4009
#endif /* _FPU_CONTROL_H */