/* $OpenBSD: s_round.c,v 1.7 2015/01/20 04:41:01 krw Exp $ */ /* * Written by Michael Shalayeff. Public Domain */ #include #include #include "math.h" double round(double x) { u_int64_t ofpsr, fpsr; __asm__ volatile("fstds %%fr0,0(%0)" :: "r" (&ofpsr) : "memory"); fpsr = (ofpsr & ~((u_int64_t)FP_RM << (9 + 32))) | ((u_int64_t)FP_RN << (9 + 32)); __asm__ volatile("fldds 0(%0), %%fr0" :: "r" (&fpsr) : "memory"); __asm__ volatile("frnd,dbl %0,%0" : "+f" (x)); __asm__ volatile("fldds 0(%0), %%fr0" :: "r" (&ofpsr) : "memory"); return (x); } __strong_alias(roundl, round);