11.1Scherry/*
21.1Scherry * Copyright (c) 2003 Marcel Moolenaar
31.1Scherry * All rights reserved.
41.1Scherry *
51.1Scherry * Redistribution and use in source and binary forms, with or without
61.1Scherry * modification, are permitted provided that the following conditions
71.1Scherry * are met:
81.1Scherry *
91.1Scherry * 1. Redistributions of source code must retain the above copyright
101.1Scherry *    notice, this list of conditions and the following disclaimer.
111.1Scherry * 2. Redistributions in binary form must reproduce the above copyright
121.1Scherry *    notice, this list of conditions and the following disclaimer in the
131.1Scherry *    documentation and/or other materials provided with the distribution.
141.1Scherry *
151.1Scherry * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
161.1Scherry * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
171.1Scherry * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
181.1Scherry * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
191.1Scherry * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
201.1Scherry * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
211.1Scherry * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
221.1Scherry * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
231.1Scherry * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
241.1Scherry * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
251.1Scherry *
261.1Scherry * $FreeBSD: src/lib/libc/ia64/gen/fpsetround.c,v 1.1 2003/01/11 07:24:54 marcel Exp $
271.1Scherry */
281.1Scherry
291.1Scherry#include <sys/types.h>
301.1Scherry#include <ieeefp.h>
311.1Scherry
321.1Scherryfp_rnd
331.1Scherryfpsetround(fp_rnd rnd)
341.1Scherry{
351.1Scherry	uint64_t fpsr;
361.1Scherry	fp_rnd prev;
371.1Scherry
381.1Scherry	__asm __volatile("mov %0=ar.fpsr" : "=r"(fpsr));
391.1Scherry	prev = (fp_rnd)((fpsr >> 10) & 3);
401.1Scherry	fpsr = (fpsr & ~0xC00ULL) | ((unsigned int)rnd << 10);
411.1Scherry	__asm __volatile("mov ar.fpsr=%0" :: "r"(fpsr));
421.1Scherry	return (prev);
431.1Scherry}
44