10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 56515Sraf * Common Development and Distribution License (the "License"). 66515Sraf * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 216515Sraf 226515Sraf /* 236515Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 246515Sraf * Use is subject to license terms. 256515Sraf */ 266515Sraf 270Sstevel@tonic-gate /* 280Sstevel@tonic-gate * Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. 290Sstevel@tonic-gate * Copyright (c) 1988 AT&T 300Sstevel@tonic-gate * All Rights Reserved 310Sstevel@tonic-gate */ 320Sstevel@tonic-gate 330Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 340Sstevel@tonic-gate 350Sstevel@tonic-gate /* 360Sstevel@tonic-gate * Establish the default settings for the floating-point state for a C language 370Sstevel@tonic-gate * program: 380Sstevel@tonic-gate * rounding mode -- round to nearest default by OS, 390Sstevel@tonic-gate * exceptions enabled -- all masked 400Sstevel@tonic-gate * sticky bits -- all clear by default by OS. 410Sstevel@tonic-gate * precision control -- double extended 420Sstevel@tonic-gate * Set _fp_hw according to what floating-point hardware is available. 430Sstevel@tonic-gate * Set _sse_hw according to what SSE hardware is available. 440Sstevel@tonic-gate * Set __flt_rounds according to the rounding mode. 450Sstevel@tonic-gate */ 460Sstevel@tonic-gate 470Sstevel@tonic-gate #pragma weak _fpstart = __fpstart 480Sstevel@tonic-gate 49*6812Sraf #include "lint.h" 500Sstevel@tonic-gate #include <sys/types.h> 510Sstevel@tonic-gate #include <sys/sysi86.h> /* for SI86FPHW/SI86FPSTART definitions */ 520Sstevel@tonic-gate #include <sys/fp.h> /* for FPU_CW_INIT and SSE_MXCSR_INIT */ 530Sstevel@tonic-gate 540Sstevel@tonic-gate extern int __fltrounds(); 550Sstevel@tonic-gate 560Sstevel@tonic-gate int _fp_hw; /* default: bss: 0 == no hardware */ 570Sstevel@tonic-gate int _sse_hw; /* default: bss: 0 == no sse */ 580Sstevel@tonic-gate int __flt_rounds; /* ANSI rounding mode */ 590Sstevel@tonic-gate 600Sstevel@tonic-gate void 610Sstevel@tonic-gate __fpstart() 620Sstevel@tonic-gate { 630Sstevel@tonic-gate /* 640Sstevel@tonic-gate * query OS for HW status and ensure the x87 and (optional) 650Sstevel@tonic-gate * SSE control words are (will be) set correctly. 660Sstevel@tonic-gate */ 676515Sraf if ((_sse_hw = sysi86(SI86FPSTART, 680Sstevel@tonic-gate &_fp_hw, FPU_CW_INIT, SSE_MXCSR_INIT)) == -1) { 690Sstevel@tonic-gate extern void _putcw(); 700Sstevel@tonic-gate 710Sstevel@tonic-gate /* 720Sstevel@tonic-gate * (fallback to old syscall on old kernels) 730Sstevel@tonic-gate */ 740Sstevel@tonic-gate _sse_hw = 0; 756515Sraf (void) sysi86(SI86FPHW, &_fp_hw); 760Sstevel@tonic-gate _putcw(0x133f); 770Sstevel@tonic-gate } 780Sstevel@tonic-gate 790Sstevel@tonic-gate /* 800Sstevel@tonic-gate * At this point the x87 fp environment that has been (or more 810Sstevel@tonic-gate * hopefully, will be) established by the kernel is: 820Sstevel@tonic-gate * 830Sstevel@tonic-gate * affine infinity 0x1000 840Sstevel@tonic-gate * round to nearest 0x0000 850Sstevel@tonic-gate * 64-bit doubles 0x0300 860Sstevel@tonic-gate * precision, underflow, overflow, zero-divide, denorm, invalid masked 870Sstevel@tonic-gate * 0x003f 880Sstevel@tonic-gate * 890Sstevel@tonic-gate * which conforms to the 4th edition i386 ABI definition. 900Sstevel@tonic-gate * 910Sstevel@tonic-gate * Additionally, if we have SSE hardware, we've also masked all 920Sstevel@tonic-gate * the same traps, and have round to nearest. 930Sstevel@tonic-gate */ 940Sstevel@tonic-gate 950Sstevel@tonic-gate __flt_rounds = 1; /* ANSI way of saying round-to-nearest */ 960Sstevel@tonic-gate } 97