1109096Smarcel/* 2109096Smarcel * Copyright (c) 2003 Marcel Moolenaar 3109096Smarcel * All rights reserved. 4109096Smarcel * 5109096Smarcel * Redistribution and use in source and binary forms, with or without 6109096Smarcel * modification, are permitted provided that the following conditions 7109096Smarcel * are met: 8109096Smarcel * 9109096Smarcel * 1. Redistributions of source code must retain the above copyright 10109096Smarcel * notice, this list of conditions and the following disclaimer. 11109096Smarcel * 2. Redistributions in binary form must reproduce the above copyright 12109096Smarcel * notice, this list of conditions and the following disclaimer in the 13109096Smarcel * documentation and/or other materials provided with the distribution. 14109096Smarcel * 15109096Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16109096Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17109096Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18109096Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19109096Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20109096Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21109096Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22109096Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23109096Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24109096Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25109096Smarcel * 26109096Smarcel * $FreeBSD$ 27109096Smarcel */ 28109096Smarcel 29109096Smarcel#include <sys/types.h> 30109096Smarcel#include <ieeefp.h> 31109096Smarcel 32109096Smarcelfp_rnd_t 33109096Smarcelfpsetround(fp_rnd_t rnd) 34109096Smarcel{ 35109096Smarcel uint64_t fpsr; 36109096Smarcel fp_rnd_t prev; 37109096Smarcel 38109096Smarcel __asm __volatile("mov %0=ar.fpsr" : "=r"(fpsr)); 39109096Smarcel prev = (fp_rnd_t)((fpsr >> 10) & 3); 40109096Smarcel fpsr = (fpsr & ~0xC00ULL) | ((unsigned int)rnd << 10); 41109096Smarcel __asm __volatile("mov ar.fpsr=%0" :: "r"(fpsr)); 42109096Smarcel return (prev); 43109096Smarcel} 44