summaryrefslogtreecommitdiff
path: root/usr/src/lib/libc/amd64/fp/fpstart.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/lib/libc/amd64/fp/fpstart.c')
-rw-r--r--usr/src/lib/libc/amd64/fp/fpstart.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/usr/src/lib/libc/amd64/fp/fpstart.c b/usr/src/lib/libc/amd64/fp/fpstart.c
new file mode 100644
index 0000000000..e8ab8159eb
--- /dev/null
+++ b/usr/src/lib/libc/amd64/fp/fpstart.c
@@ -0,0 +1,85 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright (c) 1990, 1991 UNIX System Laboratories, Inc.
+ * Copyright (c) 1988 AT&T
+ * All Rights Reserved
+ */
+
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+/*
+ * Establish the default settings for the floating-point state for a C language
+ * program:
+ * rounding mode -- round to nearest default by OS,
+ * exceptions enabled -- all masked
+ * sticky bits -- all clear by default by OS.
+ * precision control -- double extended
+ */
+
+#pragma weak _fpstart = __fpstart
+
+#include "synonyms.h"
+#include <sys/types.h>
+#include <sys/sysi86.h> /* for SI86FPHW/SI86FPSTART definitions */
+#include <sys/fp.h> /* for FPU_CW_INIT and SSE_MXCSR_INIT */
+
+extern int _private_sysi86();
+
+int __flt_rounds; /* ANSI rounding mode */
+
+void
+__fpstart()
+{
+ int _fp_hw; /* default: bss: 0 == no hardware */
+
+ /*
+ * query OS for HW status and ensure the x87 and (optional)
+ * SSE control words are (will be) set correctly.
+ * This "cannot fail".
+ */
+ (void) _private_sysi86(SI86FPSTART,
+ &_fp_hw, FPU_CW_INIT, SSE_MXCSR_INIT);
+
+ /*
+ * At this point the x87 fp environment that has been (or more
+ * hopefully, will be) established by the kernel is:
+ *
+ * affine infinity 0x1000
+ * round to nearest 0x0000
+ * 64-bit doubles 0x0300
+ * precision, underflow, overflow, zero-divide, denorm, invalid masked
+ * 0x003f
+ *
+ * which conforms to the 4th edition i386 ABI definition.
+ *
+ * Additionally, if we have SSE hardware, we've also masked all
+ * the same traps, and have round to nearest.
+ */
+
+ __flt_rounds = 1; /* ANSI way of saying round-to-nearest */
+}