xref: /netbsd-src/lib/libc/arch/aarch64/gen/fpsetsticky.c (revision 177f6a3a056b5723f04e7a10a33fd37d81b14dbc)
1cee94c5eSmatt /*-
2cee94c5eSmatt  * Copyright (c) 2015 The NetBSD Foundation, Inc.
3cee94c5eSmatt  * All rights reserved.
4cee94c5eSmatt  *
5cee94c5eSmatt  * This code is derived from software contributed to The NetBSD Foundation
6cee94c5eSmatt  * by Matt Thomas of 3am Software Foundry.
7cee94c5eSmatt  *
8cee94c5eSmatt  * Redistribution and use in source and binary forms, with or without
9cee94c5eSmatt  * modification, are permitted provided that the following conditions
10cee94c5eSmatt  * are met:
11cee94c5eSmatt  * 1. Redistributions of source code must retain the above copyright
12cee94c5eSmatt  *    notice, this list of conditions and the following disclaimer.
13cee94c5eSmatt  * 2. Redistributions in binary form must reproduce the above copyright
14cee94c5eSmatt  *    notice, this list of conditions and the following disclaimer in the
15cee94c5eSmatt  *    documentation and/or other materials provided with the distribution.
16cee94c5eSmatt  *
17cee94c5eSmatt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18cee94c5eSmatt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19cee94c5eSmatt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20cee94c5eSmatt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21cee94c5eSmatt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22cee94c5eSmatt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23cee94c5eSmatt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24cee94c5eSmatt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25cee94c5eSmatt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26cee94c5eSmatt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27cee94c5eSmatt  * POSSIBILITY OF SUCH DAMAGE.
28cee94c5eSmatt  */
29cee94c5eSmatt 
30cee94c5eSmatt #include <sys/cdefs.h>
31cee94c5eSmatt 
32*177f6a3aSmaya __RCSID("$NetBSD: fpsetsticky.c,v 1.2 2016/12/24 15:23:06 maya Exp $");
33cee94c5eSmatt 
34cee94c5eSmatt #include <sys/param.h>
35cee94c5eSmatt #include <sys/bitops.h>
36cee94c5eSmatt 
37cee94c5eSmatt #include "namespace.h"
38cee94c5eSmatt 
39cee94c5eSmatt #include <ieeefp.h>
40cee94c5eSmatt 
41cee94c5eSmatt #include <aarch64/armreg.h>
42cee94c5eSmatt 
__weak_alias(fpsetsticky,_fpsetsticky)43cee94c5eSmatt __weak_alias(fpsetsticky,_fpsetsticky)
44cee94c5eSmatt 
45cee94c5eSmatt fp_except_t
46cee94c5eSmatt fpsetsticky(fp_except_t sticky)
47cee94c5eSmatt {
48cee94c5eSmatt 	const uint32_t old_fpsr = reg_fpsr_read();
49cee94c5eSmatt 	const uint32_t new_fpsr = (old_fpsr & ~FPSR_CSUM)
50cee94c5eSmatt 	   | __SHIFTIN(sticky, FPSR_CSUM);
51cee94c5eSmatt 	reg_fpsr_write(new_fpsr);
52cee94c5eSmatt 	return __SHIFTOUT(old_fpsr, FPSR_CSUM);
53cee94c5eSmatt }
54