1193323Sed/* $OpenBSD: flt_rounds.c,v 1.6 2015/10/27 05:54:49 guenther Exp $ */ 2193323Sed 3193323Sed/* 4193323Sed * Written by Miodrag Vallat. Public domain. 5193323Sed */ 6193323Sed 7193323Sed#include <sys/types.h> 8193323Sed#include <float.h> 9193323Sed 10193323Sedstatic const int map[] = { 11193323Sed 1, /* round to nearest */ 12193323Sed 0, /* round to zero */ 13193323Sed 2, /* round to positive infinity */ 14193323Sed 3 /* round to negative infinity */ 15193323Sed}; 16193323Sed 17193323Sedint 18193323Sed__flt_rounds() 19193323Sed{ 20193323Sed u_int64_t fpsr; 21193323Sed 22198090Srdivacky __asm__ volatile("fstd %%fr0,0(%1)" : "=m" (fpsr) : "r" (&fpsr)); 23193323Sed return map[(fpsr >> 41) & 0x03]; 24193323Sed} 25193323SedDEF_STRONG(__flt_rounds); 26193323Sed