xref: /openbsd-src/lib/libc/arch/powerpc/gen/fpsetsticky.c (revision 476bc7b6c28b4ce91f25c4ca0780b71923ecea86)
1*476bc7b6Sguenther /*	$OpenBSD: fpsetsticky.c,v 1.5 2014/04/17 09:01:25 guenther Exp $	*/
2ba1778b3Srahnds /*	$NetBSD: fpsetsticky.c,v 1.1 1999/07/07 01:55:08 danw Exp $	*/
3ba1778b3Srahnds 
4ba1778b3Srahnds /*
5ba1778b3Srahnds  * Copyright (c) 1999 The NetBSD Foundation, Inc.
6ba1778b3Srahnds  * All rights reserved.
7ba1778b3Srahnds  *
8ba1778b3Srahnds  * This code is derived from software contributed to The NetBSD Foundation
9ba1778b3Srahnds  * by Dan Winship.
10ba1778b3Srahnds  *
11ba1778b3Srahnds  * Redistribution and use in source and binary forms, with or without
12ba1778b3Srahnds  * modification, are permitted provided that the following conditions
13ba1778b3Srahnds  * are met:
14ba1778b3Srahnds  * 1. Redistributions of source code must retain the above copyright
15ba1778b3Srahnds  *    notice, this list of conditions and the following disclaimer.
16ba1778b3Srahnds  * 2. Redistributions in binary form must reproduce the above copyright
17ba1778b3Srahnds  *    notice, this list of conditions and the following disclaimer in the
18ba1778b3Srahnds  *    documentation and/or other materials provided with the distribution.
19ba1778b3Srahnds  *
20ba1778b3Srahnds  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21ba1778b3Srahnds  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22ba1778b3Srahnds  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23ba1778b3Srahnds  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24ba1778b3Srahnds  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25ba1778b3Srahnds  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26ba1778b3Srahnds  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27ba1778b3Srahnds  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28ba1778b3Srahnds  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29ba1778b3Srahnds  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30ba1778b3Srahnds  * POSSIBILITY OF SUCH DAMAGE.
31ba1778b3Srahnds  */
32ba1778b3Srahnds 
33ba1778b3Srahnds #include <sys/types.h>
34ba1778b3Srahnds #include <ieeefp.h>
35ba1778b3Srahnds 
36ba1778b3Srahnds fp_except
fpsetsticky(mask)37ba1778b3Srahnds fpsetsticky(mask)
38ba1778b3Srahnds 	fp_except mask;
39ba1778b3Srahnds {
40ba1778b3Srahnds 	u_int64_t fpscr;
41ba1778b3Srahnds 	fp_rnd old;
42ba1778b3Srahnds 
43*476bc7b6Sguenther 	__asm__ volatile("mffs %0" : "=f"(fpscr));
44ba1778b3Srahnds 	old = (fpscr >> 25) & 0x1f;
4566e02d3fSmartynas 	fpscr = (fpscr & 0xe1ffffffULL) | ((mask & 0xf) << 25);
4666e02d3fSmartynas 	if (mask & FP_X_INV)
4766e02d3fSmartynas 		fpscr |= 0x400;
4866e02d3fSmartynas 	else
4966e02d3fSmartynas 		fpscr &= 0xfe07f8ffULL;
50*476bc7b6Sguenther 	__asm__ volatile("mtfsf 0xff,%0" :: "f"(fpscr));
51ba1778b3Srahnds 	return (old);
52ba1778b3Srahnds }
53