Blame sysdeps/x86/fpu_control.h

Packit 6c4009
/* FPU control word bits.  x86 version.
Packit 6c4009
   Copyright (C) 1993-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Olaf Flebbe.
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	1
Packit 6c4009
Packit 6c4009
/* Note that this file sets on x86-64 only the x87 FPU, it does not
Packit 6c4009
   touch the SSE unit.  */
Packit 6c4009
Packit 6c4009
/* Here is the dirty part. Set up your 387 through the control word
Packit 6c4009
 * (cw) register.
Packit 6c4009
 *
Packit 6c4009
 *     15-13    12  11-10  9-8     7-6     5    4    3    2    1    0
Packit 6c4009
 * | reserved | IC | RC  | PC | reserved | PM | UM | OM | ZM | DM | IM
Packit 6c4009
 *
Packit 6c4009
 * IM: Invalid operation mask
Packit 6c4009
 * DM: Denormalized operand mask
Packit 6c4009
 * ZM: Zero-divide mask
Packit 6c4009
 * OM: Overflow mask
Packit 6c4009
 * UM: Underflow mask
Packit 6c4009
 * PM: Precision (inexact result) mask
Packit 6c4009
 *
Packit 6c4009
 * Mask bit is 1 means no interrupt.
Packit 6c4009
 *
Packit 6c4009
 * PC: Precision control
Packit 6c4009
 * 11 - round to extended precision
Packit 6c4009
 * 10 - round to double precision
Packit 6c4009
 * 00 - round to single precision
Packit 6c4009
 *
Packit 6c4009
 * RC: Rounding control
Packit 6c4009
 * 00 - rounding to nearest
Packit 6c4009
 * 01 - rounding down (toward - infinity)
Packit 6c4009
 * 10 - rounding up (toward + infinity)
Packit 6c4009
 * 11 - rounding toward zero
Packit 6c4009
 *
Packit 6c4009
 * IC: Infinity control
Packit 6c4009
 * That is for 8087 and 80287 only.
Packit 6c4009
 *
Packit 6c4009
 * The hardware default is 0x037f which we use.
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
#include <features.h>
Packit 6c4009
Packit 6c4009
/* masking of interrupts */
Packit 6c4009
#define _FPU_MASK_IM  0x01
Packit 6c4009
#define _FPU_MASK_DM  0x02
Packit 6c4009
#define _FPU_MASK_ZM  0x04
Packit 6c4009
#define _FPU_MASK_OM  0x08
Packit 6c4009
#define _FPU_MASK_UM  0x10
Packit 6c4009
#define _FPU_MASK_PM  0x20
Packit 6c4009
Packit 6c4009
/* precision control */
Packit 6c4009
#define _FPU_EXTENDED 0x300	/* libm requires double extended precision.  */
Packit 6c4009
#define _FPU_DOUBLE   0x200
Packit 6c4009
#define _FPU_SINGLE   0x0
Packit 6c4009
Packit 6c4009
/* rounding control */
Packit 6c4009
#define _FPU_RC_NEAREST 0x0    /* RECOMMENDED */
Packit 6c4009
#define _FPU_RC_DOWN    0x400
Packit 6c4009
#define _FPU_RC_UP      0x800
Packit 6c4009
#define _FPU_RC_ZERO    0xC00
Packit 6c4009
Packit 6c4009
#define _FPU_RESERVED 0xF0C0  /* Reserved bits in cw */
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* The fdlibm code requires strict IEEE double precision arithmetic,
Packit 6c4009
   and no interrupts for exceptions, rounding to nearest.  */
Packit 6c4009
Packit 6c4009
#define _FPU_DEFAULT  0x037f
Packit 6c4009
Packit 6c4009
/* IEEE:  same as above.  */
Packit 6c4009
#define _FPU_IEEE     0x037f
Packit 6c4009
Packit 6c4009
/* Type of the control word.  */
Packit 6c4009
typedef unsigned int fpu_control_t __attribute__ ((__mode__ (__HI__)));
Packit 6c4009
Packit 6c4009
/* Macros for accessing the hardware control word.  "*&" is used to
Packit 6c4009
   work around a bug in older versions of GCC.  __volatile__ is used
Packit 6c4009
   to support combination of writing the control register and reading
Packit 6c4009
   it back.  Without __volatile__, the old value may be used for reading
Packit 6c4009
   back under compiler optimization.
Packit 6c4009
Packit 6c4009
   Note that the use of these macros is not sufficient anymore with
Packit 6c4009
   recent hardware nor on x86-64.  Some floating point operations are
Packit 6c4009
   executed in the SSE/SSE2 engines which have their own control and
Packit 6c4009
   status register.  */
Packit 6c4009
#define _FPU_GETCW(cw) __asm__ __volatile__ ("fnstcw %0" : "=m" (*&cw))
Packit 6c4009
#define _FPU_SETCW(cw) __asm__ __volatile__ ("fldcw %0" : : "m" (*&cw))
Packit 6c4009
Packit 6c4009
/* Default control word set at startup.  */
Packit 6c4009
extern fpu_control_t __fpu_control;
Packit 6c4009
Packit 6c4009
#endif	/* fpu_control.h */