fpsetmask.c revision 85974
185974Sdfr/*-
285974Sdfr * Copyright (c) 2001 Doug Rabson
385974Sdfr * All rights reserved.
485974Sdfr *
585974Sdfr * Redistribution and use in source and binary forms, with or without
685974Sdfr * modification, are permitted provided that the following conditions
785974Sdfr * are met:
885974Sdfr * 1. Redistributions of source code must retain the above copyright
985974Sdfr *    notice, this list of conditions and the following disclaimer.
1085974Sdfr * 2. Redistributions in binary form must reproduce the above copyright
1185974Sdfr *    notice, this list of conditions and the following disclaimer in the
1285974Sdfr *    documentation and/or other materials provided with the distribution.
1385974Sdfr *
1485974Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1585974Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1685974Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1785974Sdfr * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1885974Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1985974Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2085974Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2185974Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2285974Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2385974Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2485974Sdfr * SUCH DAMAGE.
2585974Sdfr *
2685974Sdfr * $FreeBSD: head/lib/libc/ia64/gen/fpsetmask.c 85974 2001-11-03 15:52:18Z dfr $
2785974Sdfr */
2885974Sdfr
2985974Sdfr#include <sys/types.h>
3085974Sdfr#include <ieeefp.h>
3185974Sdfr
3285974Sdfrfp_except_t
3385974Sdfrfpsetmask(fp_except_t mask)
3485974Sdfr{
3585974Sdfr	u_int64_t fpsr;
3685974Sdfr	u_int64_t oldmask;
3785974Sdfr
3885974Sdfr	__asm __volatile("mov %0=ar.fpsr" : "=r" (fpsr));
3985974Sdfr	oldmask = (fpsr & 0x1f) ^ 0x1f;
4085974Sdfr	fpsr = (fpsr & ~0x1f) | (mask ^ 0x1f);
4185974Sdfr	__asm __volatile("mov ar.fpsr=%0" :: "r" (fpsr));
4285974Sdfr	return oldmask;
4385974Sdfr}
44