1*af3276d5Sguenther /* $OpenBSD: flt_rounds.c,v 1.6 2015/10/27 05:54:49 guenther Exp $ */ 24451fc0fSmiod 34451fc0fSmiod /* 44451fc0fSmiod * Written by Miodrag Vallat. Public domain. 54451fc0fSmiod */ 6c9d6e9aeSmiod 7c9d6e9aeSmiod #include <sys/types.h> 8fba30992Sderaadt #include <float.h> 9c9d6e9aeSmiod 10c9d6e9aeSmiod static const int map[] = { 11c9d6e9aeSmiod 1, /* round to nearest */ 12c9d6e9aeSmiod 0, /* round to zero */ 13c9d6e9aeSmiod 2, /* round to positive infinity */ 14c9d6e9aeSmiod 3 /* round to negative infinity */ 15c9d6e9aeSmiod }; 16c9d6e9aeSmiod 17c9d6e9aeSmiod int __flt_rounds()18c9d6e9aeSmiod__flt_rounds() 19c9d6e9aeSmiod { 208524f5e4Smickey u_int64_t fpsr; 21c9d6e9aeSmiod 22b5aa3b33Sguenther __asm__ volatile("fstd %%fr0,0(%1)" : "=m" (fpsr) : "r" (&fpsr)); 238524f5e4Smickey return map[(fpsr >> 41) & 0x03]; 24c9d6e9aeSmiod } 25*af3276d5Sguenther DEF_STRONG(__flt_rounds); 26