Back to index

glibc  2.9
fpu_control.h
Go to the documentation of this file.
00001 /* 68k FPU control word definitions.
00002    Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef _FPU_CONTROL_H
00021 #define _FPU_CONTROL_H
00022 
00023 /*
00024  * Motorola floating point control register bits.
00025  *
00026  * 31-16  -> reserved (read as 0, ignored on write)
00027  * 15     -> enable trap for BSUN exception
00028  * 14     -> enable trap for SNAN exception
00029  * 13     -> enable trap for OPERR exception
00030  * 12     -> enable trap for OVFL exception
00031  * 11     -> enable trap for UNFL exception
00032  * 10     -> enable trap for DZ exception
00033  *  9     -> enable trap for INEX2 exception (INEX on Coldfire)
00034  *  8     -> enable trap for INEX1 exception (IDE on Coldfire)
00035  *  7-6   -> Precision Control (only bit 6 is used on Coldfire)
00036  *  5-4   -> Rounding Control
00037  *  3-0   -> zero (read as 0, write as 0)
00038  *
00039  *
00040  * Precision Control:
00041  * 00 - round to extended precision
00042  * 01 - round to single precision
00043  * 10 - round to double precision
00044  * 11 - undefined
00045  *
00046  * Rounding Control:
00047  * 00 - rounding to nearest (RN)
00048  * 01 - rounding toward zero (RZ)
00049  * 10 - rounding (down)toward minus infinity (RM)
00050  * 11 - rounding (up) toward plus infinity (RP)
00051  *
00052  * The hardware default is 0x0000. I choose 0x5400.
00053  */
00054 
00055 #include <features.h>
00056 
00057 /* masking of interrupts */
00058 #define _FPU_MASK_BSUN  0x8000
00059 #define _FPU_MASK_SNAN  0x4000
00060 #define _FPU_MASK_OPERR 0x2000
00061 #define _FPU_MASK_OVFL  0x1000
00062 #define _FPU_MASK_UNFL  0x0800
00063 #define _FPU_MASK_DZ    0x0400
00064 #define _FPU_MASK_INEX1 0x0200
00065 #define _FPU_MASK_INEX2 0x0100
00066 
00067 /* precision control */
00068 #ifdef __mcoldfire__
00069 #define _FPU_DOUBLE   0x00
00070 #else
00071 #define _FPU_EXTENDED 0x00   /* RECOMMENDED */
00072 #define _FPU_DOUBLE   0x80
00073 #endif
00074 #define _FPU_SINGLE   0x40     /* DO NOT USE */
00075 
00076 /* rounding control */
00077 #define _FPU_RC_NEAREST 0x00    /* RECOMMENDED */
00078 #define _FPU_RC_ZERO    0x10
00079 #define _FPU_RC_DOWN    0x20
00080 #define _FPU_RC_UP      0x30
00081 
00082 #ifdef __mcoldfire__
00083 #define _FPU_RESERVED 0xFFFF800F
00084 #else
00085 #define _FPU_RESERVED 0xFFFF000F  /* Reserved bits in fpucr */
00086 #endif
00087 
00088 
00089 /* Now two recommended fpucr */
00090 
00091 /* The fdlibm code requires no interrupts for exceptions.  Don't
00092    change the rounding mode, it would break long double I/O!  */
00093 #define _FPU_DEFAULT  0x00000000
00094 
00095 /* IEEE:  same as above, but exceptions.  We must make it non-zero so
00096    that __setfpucw works.  This bit will be ignored.  */
00097 #define _FPU_IEEE     0x00000001
00098 
00099 /* Type of the control word.  */
00100 typedef unsigned int fpu_control_t __attribute__ ((__mode__ (__SI__)));
00101 
00102 /* Macros for accessing the hardware control word.  */
00103 #define _FPU_GETCW(cw) __asm__ ("fmove%.l %!, %0" : "=dm" (cw))
00104 #define _FPU_SETCW(cw) __asm__ volatile ("fmove%.l %0, %!" : : "dm" (cw))
00105 
00106 /* Default control word set at startup.  */
00107 extern fpu_control_t __fpu_control;
00108 
00109 #endif /* _M68K_FPU_CONTROL_H */