1 1.6 skrll /* $NetBSD: fpsetsticky.c,v 1.6 2012/03/23 09:34:09 skrll Exp $ */ 2 1.1 chs 3 1.1 chs /* $OpenBSD: fpsetsticky.c,v 1.4 2004/01/05 06:06:16 otto Exp $ */ 4 1.1 chs 5 1.1 chs /* 6 1.1 chs * Written by Miodrag Vallat. Public domain 7 1.1 chs */ 8 1.1 chs 9 1.2 lukem #include <sys/cdefs.h> 10 1.2 lukem #if defined(LIBC_SCCS) && !defined(lint) 11 1.6 skrll __RCSID("$NetBSD: fpsetsticky.c,v 1.6 2012/03/23 09:34:09 skrll Exp $"); 12 1.2 lukem #endif /* LIBC_SCCS and not lint */ 13 1.2 lukem 14 1.1 chs #include <sys/types.h> 15 1.1 chs #include <ieeefp.h> 16 1.1 chs 17 1.1 chs fp_except 18 1.1 chs fpsetsticky(fp_except mask) 19 1.1 chs { 20 1.1 chs uint64_t fpsr; 21 1.1 chs fp_except old; 22 1.1 chs 23 1.5 skrll __asm volatile("fstd %%fr0,0(%1)" : "=m" (fpsr) : "r" (&fpsr) : "memory"); 24 1.6 skrll old = (fp_except)(fpsr >> 59) & 0x1f; 25 1.1 chs fpsr = (fpsr & 0x07ffffff00000000LL) | ((uint64_t)(mask & 0x1f) << 59); 26 1.5 skrll __asm volatile("fldd 0(%0),%%fr0" : : "r" (&fpsr) : "memory"); 27 1.5 skrll 28 1.1 chs return (old); 29 1.1 chs } 30