1*64f11261Scherry /*
2*64f11261Scherry * Copyright (c) 2003 Marcel Moolenaar
3*64f11261Scherry * All rights reserved.
4*64f11261Scherry *
5*64f11261Scherry * Redistribution and use in source and binary forms, with or without
6*64f11261Scherry * modification, are permitted provided that the following conditions
7*64f11261Scherry * are met:
8*64f11261Scherry *
9*64f11261Scherry * 1. Redistributions of source code must retain the above copyright
10*64f11261Scherry * notice, this list of conditions and the following disclaimer.
11*64f11261Scherry * 2. Redistributions in binary form must reproduce the above copyright
12*64f11261Scherry * notice, this list of conditions and the following disclaimer in the
13*64f11261Scherry * documentation and/or other materials provided with the distribution.
14*64f11261Scherry *
15*64f11261Scherry * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16*64f11261Scherry * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17*64f11261Scherry * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18*64f11261Scherry * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19*64f11261Scherry * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20*64f11261Scherry * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21*64f11261Scherry * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22*64f11261Scherry * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23*64f11261Scherry * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24*64f11261Scherry * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*64f11261Scherry *
26*64f11261Scherry * $FreeBSD: src/lib/libc/ia64/gen/fpsetround.c,v 1.1 2003/01/11 07:24:54 marcel Exp $
27*64f11261Scherry */
28*64f11261Scherry
29*64f11261Scherry #include <sys/types.h>
30*64f11261Scherry #include <ieeefp.h>
31*64f11261Scherry
32*64f11261Scherry fp_rnd
fpsetround(fp_rnd rnd)33*64f11261Scherry fpsetround(fp_rnd rnd)
34*64f11261Scherry {
35*64f11261Scherry uint64_t fpsr;
36*64f11261Scherry fp_rnd prev;
37*64f11261Scherry
38*64f11261Scherry __asm __volatile("mov %0=ar.fpsr" : "=r"(fpsr));
39*64f11261Scherry prev = (fp_rnd)((fpsr >> 10) & 3);
40*64f11261Scherry fpsr = (fpsr & ~0xC00ULL) | ((unsigned int)rnd << 10);
41*64f11261Scherry __asm __volatile("mov ar.fpsr=%0" :: "r"(fpsr));
42*64f11261Scherry return (prev);
43*64f11261Scherry }
44