diff options
author | marcel <marcel@FreeBSD.org> | 2003-01-19 06:01:33 +0000 |
---|---|---|
committer | marcel <marcel@FreeBSD.org> | 2003-01-19 06:01:33 +0000 |
commit | b2cf4b9bc050c2dc60962f9eccf13ce480fa8aee (patch) | |
tree | 8166c756e10c0bb505e7352042246b630b69280d /sys/amd64/include/ieeefp.h | |
parent | e03de9709309a4f23e08f65f30d18b14df152919 (diff) | |
download | FreeBSD-src-b2cf4b9bc050c2dc60962f9eccf13ce480fa8aee.zip FreeBSD-src-b2cf4b9bc050c2dc60962f9eccf13ce480fa8aee.tar.gz |
o Move the contents of <machine/floatingpoint.h> over to
<machine/ieeefp.h> where it belongs.
o Remove the i386 specific inclusion of <machine/floatingpoint.h>
from <ieeefp.h>, now that including <machine/ieeefp.h> is enough
for all architectures.
o Allow <machine/ieeefp.h> to inline the functions exposed by the
headers by checking for _IEEEFP_INLINED_ in the MI header. When
defined, prototypes are not given and it is assumed that the MD
headers, when inlining only a subset of the functions provide
prototypes for the functions not being inlined.
Based on patch from: Terry Lambert <tlambert2@mindspring.com>
Tested with: make release.
Diffstat (limited to 'sys/amd64/include/ieeefp.h')
-rw-r--r-- | sys/amd64/include/ieeefp.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/sys/amd64/include/ieeefp.h b/sys/amd64/include/ieeefp.h index 3c9c49d..ac67be1 100644 --- a/sys/amd64/include/ieeefp.h +++ b/sys/amd64/include/ieeefp.h @@ -98,4 +98,84 @@ typedef enum { #define FP_RND_OFF 10 /* round control offset */ #define FP_STKY_OFF 0 /* sticky flags offset */ +#ifdef __GNUC__ + +#define __fldenv(addr) __asm __volatile("fldenv %0" : : "m" (*(addr))) +#define __fnstenv(addr) __asm __volatile("fnstenv %0" : "=m" (*(addr))) +#define __fnstcw(addr) __asm __volatile("fnstcw %0" : "=m" (*(addr))) +#define __fnstsw(addr) __asm __volatile("fnstsw %0" : "=m" (*(addr))) + +/* + * return the contents of a FP register + */ +static __inline__ int +__fpgetreg(int _reg) +{ + unsigned short _mem; + + /*- + * This is more efficient than it looks. The switch gets optimized + * away if _reg is constant. + * + * The default case only supports _reg == 0. We could handle more + * registers (e.g., tags) using fnstenv, but the interface doesn't + * support more. + */ + switch(_reg) { + default: + __fnstcw(&_mem); + break; + case FP_STKY_REG: + __fnstsw(&_mem); + break; + } + return _mem; +} + +/* + * set a FP mode; return previous mode + */ +static __inline__ int +__fpsetreg(int _m, int _reg, int _fld, int _off) +{ + unsigned _env[7]; + unsigned _p; + + /* + * _reg == 0 could be handled better using fnstcw/fldcw. + */ + __fnstenv(_env); + _p = (_env[_reg] & _fld) >> _off; + _env[_reg] = (_env[_reg] & ~_fld) | (_m << _off & _fld); + __fldenv(_env); + return _p; +} + +#endif /* __GNUC__ */ + +/* + * SysV/386 FP control interface + */ +#define fpgetround() ((fp_rnd_t) \ + ((__fpgetreg(FP_RND_REG) & FP_RND_FLD) >> FP_RND_OFF)) +#define fpsetround(m) ((fp_rnd_t) \ + __fpsetreg((m), FP_RND_REG, FP_RND_FLD, FP_RND_OFF)) +#define fpgetprec() ((fp_prec_t) \ + ((__fpgetreg(FP_PRC_REG) & FP_PRC_FLD) >> FP_PRC_OFF)) +#define fpsetprec(m) ((fp_prec_t) \ + __fpsetreg((m), FP_PRC_REG, FP_PRC_FLD, FP_PRC_OFF)) +#define fpgetmask() ((fp_except_t) \ + ((~__fpgetreg(FP_MSKS_REG) & FP_MSKS_FLD) >> FP_MSKS_OFF)) +#define fpsetmask(m) ((fp_except_t) \ + (~__fpsetreg(~(m), FP_MSKS_REG, FP_MSKS_FLD, FP_MSKS_OFF)) & \ + (FP_MSKS_FLD >> FP_MSKS_OFF)) +#define fpgetsticky() ((fp_except_t) \ + ((__fpgetreg(FP_STKY_REG) & FP_STKY_FLD) >> FP_STKY_OFF)) +#define fpresetsticky(m) ((fp_except_t) \ + __fpsetreg(0, FP_STKY_REG, (m), FP_STKY_OFF)) +#define fpsetsticky(m) fpresetsticky(m) + +/* Suppress prototypes in the MI header. */ +#define _IEEEFP_INLINED_ 1 + #endif /* !_MACHINE_IEEEFP_H_ */ |