/* $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 */

/*	Copyright (c) 1984 AT&T	*/
/*	  All Rights Reserved  	*/

/*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
/*	The copyright notice above does not evidence any   	*/
/*	actual or intended publication of such source code.	*/

#ident  "@(#)$Header: fp.h 1.3 89/10/10 $"

#if !i387
/* Useful asm routines and data types for grungy 1167 hacking */

#define EXCPMASK (FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP|FP_X_UO|FP_X_DC)

/* Get current 1167 process context register */
asm
_getpcr(prc)
/* struct _prc1167 prc;	*/
{
%mem prc;
	wstctx	%eax
	movl	prc,%edx
	movl	%eax,(%edx)
}

/* Load a new 1167 process context register */
asm
_putpcr(prc)
/* struct _prc1167 prc;     */
{
%mem prc;
	movl    prc,%edx
	movl	(%edx),%eax
	wldctx	%eax
}

#else
/* Useful asm routines and data types for grungy 87 hacking */

#define EXCPMASK (FP_X_INV|FP_X_DNML|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP)

typedef short _envbuf87[7]; /* buffer for f{ld,st}env instruction       */
#define _swoff   1          /* status word index in _envbuf87           */
#define _swboff  2          /* status word BYTE offset in _envbuf87     */


/* Get current fp control word */
asm
_getcw(cw)
/* struct _cw87 cw;     */
{
%reg cw;
	fstcw   (cw)
%mem cw;
	movl    cw,%eax
	fstcw   (%eax)
}

/* Load a new fp control word */
asm
_putcw(cw)
/* struct _cw87 cw;     */
{
%reg cw;
	fldcw   (cw)
%mem cw;
	movl    cw,%eax
	fldcw   (%eax)
}


/* Get current fp status word */
asm
_getsw(sw)
/* struct _sw87 sw;     */
{
%reg sw;
	fstsw   (sw)
%mem sw;
	movl    sw,%eax
	fstsw   (%eax)
}

/* Load a new fp status word.  This is tricky because there is no direct
 * way to do this.  However, we store the environment, change the stored
 * status field, and reload the environment.  A bit expensive, but...
 */
asm
_putsw(sw,buf)
/* struct _cw87 sw;     */
/* _envbuf87 buf;       */
{
%reg sw,buf;
	data16
	fnstenv (buf)
	movw    (sw),sw
	movw    sw,_swboff(buf)
	data16
	fldenv (buf)
%reg sw; mem buf;
	movl    buf,%eax
	data16
	fnstenv (%eax)
	movw    (sw),sw
	movw    sw,_swboff(%eax)
	data16
	fldenv (%eax)
%mem sw; reg buf;
	movl    sw,%eax
	data16
	fnstenv (buf)
	movw    (%eax),%ax
	movw    %ax,_swboff(buf)
	data16
	fldenv (buf)
%mem sw,buf;
	movl    sw,%ecx
	movl    buf,%eax
	data16
	fnstenv (%eax)
	movw    (%ecx),%cx
	movw    %cx,_swboff(%eax)
	data16
	fldenv (%eax)
}
#endif
