diff options
Diffstat (limited to 'usr/src/lib/libm/i386')
97 files changed, 8750 insertions, 0 deletions
diff --git a/usr/src/lib/libm/i386/Makefile b/usr/src/lib/libm/i386/Makefile new file mode 100644 index 0000000000..0a710fb63a --- /dev/null +++ b/usr/src/lib/libm/i386/Makefile @@ -0,0 +1,28 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2011 Nexenta Systems, Inc. All rights reserved. +# + +TARGET_ARCH= i386 +include ../Makefile.com + +# +# Without this option GCC will place floats into x87 (or wider) floating point +# registers, ending up with better-than-ieee precision. +# +CFLAGS += -_gcc=-ffloat-store +$(OBJS_M9XSSE) := CFLAGS += -xarch=sse2 + +install: all $(ROOTLIBS) $(ROOTLINKS) $(ROOTLINT) + +include ../Makefile.targ diff --git a/usr/src/lib/libm/i386/src/__reduction.s b/usr/src/lib/libm/i386/src/__reduction.s new file mode 100644 index 0000000000..8c1e9f2334 --- /dev/null +++ b/usr/src/lib/libm/i386/src/__reduction.s @@ -0,0 +1,90 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "__reduction.s" + +/ +/ After argument reduction which returns n: +/ n mod 4 sin(x) cos(x) tan(x) +/ ---------------------------------------------------------- +/ 0 S C S/C +/ 1 C -S -C/S +/ 2 -S -C S/C +/ 3 -C S -C/S +/ ---------------------------------------------------------- + +#include "libm.h" +#include "libm_synonyms.h" +#include "libm_protos.h" +#undef fabs + + ENTRY(__reduction) +#ifndef PIC + movl 12(%esp),%eax / load the high part of arg +#else + movl 16(%esp),%eax / load the high part of arg +#endif + andl $0x7fffffff,%eax / clear sign + cmpl $0x3fe921fb,%eax / Is |x| < pi/4 (= 0x3fe921fb54...) ? + jbe .L0 + cmpl $0x7ff00000,%eax / Is arg a NaN or an Inf ? + jb .L1 +.L0: +#ifndef PIC + fldl 8(%esp) / push arg +#else + fldl 12(%esp) / push arg +#endif + fwait + movl $0,%eax / set n = 0 + ret +.L1: + pushl %ebp + movl %esp,%ebp + subl $16,%esp + PIC_SETUP(1) + leal -16(%ebp),%eax / address of y[0] + pushl %eax +#ifndef PIC + pushl 16(%ebp) + pushl 12(%ebp) +#else + pushl 20(%ebp) + pushl 16(%ebp) +#endif + call PIC_F(__rem_pio2) / call __rem_pio2(x,&y) + fldl -8(%ebp) / y[1] + fldl -16(%ebp) / y[0], y[1] + faddp %st,%st(1) / y[0]+y[1] round-to-extended + addl $28,%esp / 16+4*3 + andl $3,%eax + PIC_WRAPUP + leave + ret + .align 4 + SET_SIZE(__reduction) diff --git a/usr/src/lib/libm/i386/src/acos.s b/usr/src/lib/libm/i386/src/acos.s new file mode 100644 index 0000000000..7305bd7e63 --- /dev/null +++ b/usr/src/lib/libm/i386/src/acos.s @@ -0,0 +1,88 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "acos.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(acos,function) +#include "libm_synonyms.h" +#include "libm_protos.h" + +#undef fabs + + ENTRY(acos) + fldl 4(%esp) / push x + fld1 / push 1 + fld %st(1) / x , 1 , x + fabs / |x| , 1 , x + fucomp + fstsw %ax + sahf + ja .ERR + fadd %st(1),%st / 1+x,x + fldz + fucomp + fstsw %ax + sahf + jp .L1 + jne .L1 + / x is -1 + fstp %st(0) / -1 + fstp %st(0) / empty NPX stack + fldpi + ret +.L1: + fxch %st(1) / x,1+x + fld1 / 1,x,1+x + fsubp %st,%st(1) / 1-x,1+x + fdivp %st,%st(1) / (1-x)/(1+x) + fsqrt + fld1 / 1,sqrt((1-x)/(1+x)) + fpatan + fadd %st(0),%st + ret + +.ERR: + / |x| > 1 + pushl %ebp + movl %esp,%ebp + PIC_SETUP(1) + fstp %st(0) / x + fstp %st(0) / empty NPX stack + pushl $1 + pushl 12(%ebp) / high x + pushl 8(%ebp) / low x + pushl 12(%ebp) / high x + pushl 8(%ebp) / low x + call PIC_F(_SVID_libm_err) / report SVID result/error + addl $20,%esp + PIC_WRAPUP + leave + ret + .align 4 + SET_SIZE(acos) diff --git a/usr/src/lib/libm/i386/src/acosf.s b/usr/src/lib/libm/i386/src/acosf.s new file mode 100644 index 0000000000..58b4328262 --- /dev/null +++ b/usr/src/lib/libm/i386/src/acosf.s @@ -0,0 +1,78 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "acosf.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(acosf,function) +#include "libm_synonyms.h" +#include "libm_protos.h" + +#undef fabs + + ENTRY(acosf) + flds 4(%esp) / push x + fld1 / push 1 + fld %st(1) / x , 1 , x + fabs / |x| , 1 , x + fucomp + fstsw %ax + sahf + ja .ERR + fadd %st(1),%st / 1+x,x + fldz + fucomp + fstsw %ax + sahf + jp .L1 + jne .L1 + / x is -1 + fstp %st(0) / x + fstp %st(0) / empty NPX stack + fldpi + ret +.L1: + fxch %st(1) / x,1+x + fld1 / 1,x,1+x + fsubp %st,%st(1) / 1-x,1+x + fdivp %st,%st(1) / (1-x)/(1+x) + fsqrt + fld1 / 1,sqrt((1-x)/(1+x)) + fpatan + fadd %st(0),%st + ret + +.ERR: + / |x| > 1 + fstp %st(0) / x + fstp %st(0) / empty NPX stack + fldz + fdiv %st(0),%st / 0/0 + ret + .align 4 + SET_SIZE(acosf) diff --git a/usr/src/lib/libm/i386/src/acosl.s b/usr/src/lib/libm/i386/src/acosl.s new file mode 100644 index 0000000000..e552f645fb --- /dev/null +++ b/usr/src/lib/libm/i386/src/acosl.s @@ -0,0 +1,75 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "acosl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(acosl,function) +#include "libm_synonyms.h" + +#undef fabs + + ENTRY(acosl) + fldt 4(%esp) / push x + fld1 / push 1 + fld %st(1) / x , 1 , x + fabs / |x| , 1 , x + fucomp + fstsw %ax + sahf + ja 9f + fadd %st(1),%st / 1+x,x + fldz + fucomp + fstsw %ax + sahf + jp .L1 + jne .L1 + / x is -1 + fstp %st(0) / -1 + fstp %st(0) / empty NPX stack + fldpi + ret +.L1: + fxch %st(1) / x,1+x + fld1 / 1,x,1+x + fsubp %st,%st(1) / 1-x,1+x + fdivp %st,%st(1) / (1-x)/(1+x) + fsqrt + fld1 / 1,sqrt((1-x)/(1+x)) + fpatan + fadd %st(0),%st + ret +9: + / |x| > 1 + fstp %st(0) / x + fsub %st,%st(0) / +/-0 or NaN+invalid + fdiv %st,%st(0) / NaN+invalid or NaN + ret + .align 4 + SET_SIZE(acosl) diff --git a/usr/src/lib/libm/i386/src/asin.s b/usr/src/lib/libm/i386/src/asin.s new file mode 100644 index 0000000000..0db6b45e41 --- /dev/null +++ b/usr/src/lib/libm/i386/src/asin.s @@ -0,0 +1,73 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "asin.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(asin,function) +#include "libm_synonyms.h" +#include "libm_protos.h" + +#undef fabs + + ENTRY(asin) + fldl 4(%esp) / push x + fld1 / push 1 + fld %st(1) / x , 1 , x + fabs / |x| , 1 , x + fucomp + fstsw %ax + sahf + ja .ERR + fadd %st(1),%st / 1+x,x + fld1 / 1,1+x,x + fsub %st(2),%st / 1-x,1+x,x + fmulp %st,%st(1) / (1-x)*(1+x),x + fsqrt / sqrt((1-x)/(1+x)),x + fpatan / atan(x/sqrt((1-x)/(1+x))) + ret + +.ERR: + / |x| > 1 + pushl %ebp + movl %esp,%ebp + PIC_SETUP(1) + fstp %st(0) / x + fstp %st(0) / empty NPX stack + pushl $2 + pushl 12(%ebp) / high x + pushl 8(%ebp) / low x + pushl 12(%ebp) / high x + pushl 8(%ebp) / low x + call PIC_F(_SVID_libm_err) / report SVID result/error + addl $20,%esp + PIC_WRAPUP + leave + ret + .align 4 + SET_SIZE(asin) diff --git a/usr/src/lib/libm/i386/src/asinf.s b/usr/src/lib/libm/i386/src/asinf.s new file mode 100644 index 0000000000..a2a7c2c0ee --- /dev/null +++ b/usr/src/lib/libm/i386/src/asinf.s @@ -0,0 +1,63 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "asinf.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(asinf,function) +#include "libm_synonyms.h" +#include "libm_protos.h" + +#undef fabs + + ENTRY(asinf) + flds 4(%esp) / push x + fld1 / push 1 + fld %st(1) / x , 1 , x + fabs / |x| , 1 , x + fucomp + fstsw %ax + sahf + ja .ERR + fadd %st(1),%st / 1+x,x + fld1 / 1,1+x,x + fsub %st(2),%st / 1-x,1+x,x + fmulp %st,%st(1) / (1-x)*(1+x),x + fsqrt / sqrt((1-x)*(1+x)),x + fpatan / atan(x/sqrt((1-x)*(1+x))) + ret + +.ERR: + / |x| > 1 + fstp %st(0) / x + fstp %st(0) / empty NPX stack + fldz + fdiv %st(0),%st / 0/0 + ret + .align 4 + SET_SIZE(asinf) diff --git a/usr/src/lib/libm/i386/src/asinl.s b/usr/src/lib/libm/i386/src/asinl.s new file mode 100644 index 0000000000..96d2047fcb --- /dev/null +++ b/usr/src/lib/libm/i386/src/asinl.s @@ -0,0 +1,60 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "asinl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(asinl,function) +#include "libm_synonyms.h" + +#undef fabs + + ENTRY(asinl) + fldt 4(%esp) / push x + fld1 / push 1 + fld %st(1) / x , 1 , x + fabs / |x| , 1 , x + fucomp + fstsw %ax + sahf + ja 9f + fadd %st(1),%st / 1+x,x + fld1 / 1,1+x,x + fsub %st(2),%st / 1-x,1+x,x + fmulp %st,%st(1) / (1-x)*(1+x),x + fsqrt / sqrt((1-x)*(1+x)),x + fpatan / atan(x/sqrt((1-x)*(1+x))) + ret +9: + / |x| > 1 + fstp %st(0) / x + fsub %st,%st(0) / +/-0 or NaN+invalid + fdiv %st,%st(0) / NaN+invalid or NaN + ret + .align 4 + SET_SIZE(asinl) diff --git a/usr/src/lib/libm/i386/src/atan.s b/usr/src/lib/libm/i386/src/atan.s new file mode 100644 index 0000000000..a48c5c75a0 --- /dev/null +++ b/usr/src/lib/libm/i386/src/atan.s @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "atan.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(atan,function) +#include "libm_synonyms.h" + + ENTRY(atan) + fldl 4(%esp) / push arg + fld1 / push 1.0 + fpatan / atan(arg/1.0) + ret + .align 4 + SET_SIZE(atan) diff --git a/usr/src/lib/libm/i386/src/atan2.s b/usr/src/lib/libm/i386/src/atan2.s new file mode 100644 index 0000000000..6287f13537 --- /dev/null +++ b/usr/src/lib/libm/i386/src/atan2.s @@ -0,0 +1,70 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "atan2.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(atan2,function) +#include "libm_synonyms.h" +#include "libm_protos.h" + + ENTRY(atan2) + movl 4(%esp),%eax / low part of y + movl 12(%esp),%ecx / low part of x + orl %eax,%ecx + jz .maybe_0s + + / not both x and y are 0's +1: + fldl 4(%esp) / push y + fldl 12(%esp) / push x + fpatan / return atan2(y,x) + ret + +.maybe_0s: + movl 8(%esp),%eax / high part of y + movl 16(%esp),%ecx / high part of x + orl %eax,%ecx + andl $0x7fffffff,%ecx / clear sign + jnz 1b + / both x and y are 0's + pushl %ebp + movl %esp,%ebp + PIC_SETUP(1) + pushl $3 + pushl 12(%ebp) / high y + pushl 8(%ebp) / low y + pushl 20(%ebp) / high x + pushl 16(%ebp) / low x + call PIC_F(_SVID_libm_err) / report SVID result/error + addl $20,%esp + PIC_WRAPUP + leave + ret + .align 4 + SET_SIZE(atan2) diff --git a/usr/src/lib/libm/i386/src/atan2f.s b/usr/src/lib/libm/i386/src/atan2f.s new file mode 100644 index 0000000000..e45afcc264 --- /dev/null +++ b/usr/src/lib/libm/i386/src/atan2f.s @@ -0,0 +1,42 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "atan2f.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(atan2f,function) +#include "libm_synonyms.h" +#include "libm_protos.h" + + ENTRY(atan2f) + flds 4(%esp) / push y + flds 8(%esp) / push x + fpatan / return atan2(y,x) + ret + .align 4 + SET_SIZE(atan2f) diff --git a/usr/src/lib/libm/i386/src/atan2l.s b/usr/src/lib/libm/i386/src/atan2l.s new file mode 100644 index 0000000000..7720ddedef --- /dev/null +++ b/usr/src/lib/libm/i386/src/atan2l.s @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "atan2l.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(atan2l,function) +#include "libm_synonyms.h" + + ENTRY(atan2l) + fldt 4(%esp) / push y + fldt 16(%esp) / push x + fpatan / return atan2(y,x) + ret + .align 4 + SET_SIZE(atan2l) diff --git a/usr/src/lib/libm/i386/src/atanl.s b/usr/src/lib/libm/i386/src/atanl.s new file mode 100644 index 0000000000..f4712344f3 --- /dev/null +++ b/usr/src/lib/libm/i386/src/atanl.s @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "atanl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(atanl,function) +#include "libm_synonyms.h" + + ENTRY(atanl) + fldt 4(%esp) / push arg + fld1 / push 1.0 + fpatan / atan(arg/1.0) + ret + .align 4 + SET_SIZE(atanl) diff --git a/usr/src/lib/libm/i386/src/ceil.s b/usr/src/lib/libm/i386/src/ceil.s new file mode 100644 index 0000000000..12a0c6b125 --- /dev/null +++ b/usr/src/lib/libm/i386/src/ceil.s @@ -0,0 +1,56 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "ceil.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(ceil,function) +#include "libm_synonyms.h" + + ENTRY(ceil) + subl $8,%esp + fstcw (%esp) + fldl 12(%esp) + movw (%esp),%cx + orw $0x0c00,%cx + xorw $0x0400,%cx + movw %cx,4(%esp) + fldcw 4(%esp) / set RD = up + frndint + fstcw 4(%esp) / restore RD + movw 4(%esp),%dx + andw $0xf3ff,%dx + movw (%esp),%cx + andw $0x0c00,%cx + orw %dx,%cx + movw %cx,(%esp) + fldcw (%esp) / restore RD + addl $8,%esp + ret + .align 4 + SET_SIZE(ceil) diff --git a/usr/src/lib/libm/i386/src/copysign.s b/usr/src/lib/libm/i386/src/copysign.s new file mode 100644 index 0000000000..933eaaafe1 --- /dev/null +++ b/usr/src/lib/libm/i386/src/copysign.s @@ -0,0 +1,51 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "copysign.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(copysign,function) +#include "libm_synonyms.h" + + ENTRY(copysign) + movl 8(%esp),%eax / eax <-- hi_32(x) + movl 16(%esp),%ecx / ecx <-- hi_32(y) + andl $0x7fffffff,%eax / eax <-- hi_32(abs(x)) + andl $0x80000000,%ecx / ecx[31] <-- sign_bit(y) + orl %ecx,%eax / eax <-- hi_32(copysign(x,y)) + movl 4(%esp),%ecx / ecx <-- lo_32(x) + / = lo_32(copysign(x,y)) + subl $8,%esp / set up loading dock for result + movl %ecx,(%esp) / copy lo_32(result) to loading dock + movl %eax,4(%esp) / copy hi_32(result) to loading dock + fldl (%esp) / load copysign(x,y) + fwait / in case fldl causes exception + addl $8,%esp / restore stack-pointer for return + ret + .align 4 + SET_SIZE(copysign) diff --git a/usr/src/lib/libm/i386/src/copysignf.s b/usr/src/lib/libm/i386/src/copysignf.s new file mode 100644 index 0000000000..e3a217beeb --- /dev/null +++ b/usr/src/lib/libm/i386/src/copysignf.s @@ -0,0 +1,48 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "copysignf.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(copysignf,function) +#include "libm_synonyms.h" + + ENTRY(copysignf) + movl 4(%esp),%eax / eax <-- x + movl 8(%esp),%ecx / ecx <-- y + andl $0x7fffffff,%eax / eax <-- abs(x) + andl $0x80000000,%ecx / ecx[31] <-- sign_bit(y) + orl %ecx,%eax / eax <-- copysign(x,y) + subl $4,%esp / set up loading dock for result + movl %eax,(%esp) / copy result to loading dock + flds (%esp) / load copysign(x,y) + fwait / in case fldl causes exception + addl $4,%esp / restore stack-pointer for return + ret + .align 4 + SET_SIZE(copysignf) diff --git a/usr/src/lib/libm/i386/src/copysignl.s b/usr/src/lib/libm/i386/src/copysignl.s new file mode 100644 index 0000000000..944117ee41 --- /dev/null +++ b/usr/src/lib/libm/i386/src/copysignl.s @@ -0,0 +1,54 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "copysignl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(copysignl,function) +#include "libm_synonyms.h" + + ENTRY(copysignl) + movl 12(%esp),%eax / sign and bexp of x + movl 24(%esp),%ecx / sign and bexp of y + andl $0x00007fff,%eax / eax <-- bexp(x) + andl $0x00008000,%ecx / ecx <-- sign(y) + orl %ecx,%eax / eax <-- bexp(x) with sign(y) + movl 8(%esp),%ecx / ecx <-- hi_32(sgnfcnd(x)) + movl 4(%esp),%edx / edx <-- lo_32(sgnfcnd(x)) + subl $12,%esp / set up loading dock for result + movl %edx,(%esp) / copy lo_32(result's sgnfcnd) + / to loading dock + movl %ecx,4(%esp) / copy hi_32(result's sgnfcnd) + / to loading dock + movl %eax,8(%esp) / copy sign&bexp(result) + / to loading dock + fldt (%esp) / load copysign(x,y) + addl $12,%esp / restore stack-pointer for return + ret + .align 4 + SET_SIZE(copysignl) diff --git a/usr/src/lib/libm/i386/src/cos.s b/usr/src/lib/libm/i386/src/cos.s new file mode 100644 index 0000000000..44862f2bc9 --- /dev/null +++ b/usr/src/lib/libm/i386/src/cos.s @@ -0,0 +1,59 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "cos.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(cos,function) +#include "libm_synonyms.h" +#include "libm_protos.h" + + ENTRY(cos) + PIC_SETUP(1) + call PIC_F(__reduction) + PIC_WRAPUP + cmpl $1,%eax + jl .cos0 + je .cos1 + cmpl $2,%eax + je .cos2 + fsin + ret +.cos2: + fcos + fchs + ret +.cos1: + fsin + fchs + ret +.cos0: + fcos + ret + .align 4 + SET_SIZE(cos) diff --git a/usr/src/lib/libm/i386/src/exp.s b/usr/src/lib/libm/i386/src/exp.s new file mode 100644 index 0000000000..f901f511e6 --- /dev/null +++ b/usr/src/lib/libm/i386/src/exp.s @@ -0,0 +1,156 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "exp.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(exp,function) +#include "libm_synonyms.h" +#include "libm_protos.h" + + ENTRY(exp) + movl 8(%esp),%ecx / ecx <-- hi_32(x) + andl $0x7fffffff,%ecx / ecx <-- hi_32(|x|) + cmpl $0x3fe62e42,%ecx / Is |x| < ln(2)? + jb .shortcut / If so, take a shortcut. + je .check_tail / |x| may be only slightly < ln(2) + cmpl $0x7ff00000,%ecx / hi_32(|x|) >= hi_32(INF)? + jae .not_finite / if so, x is not finite +.finite_non_special: / Here, ln(2) < |x| < INF + fldl 4(%esp) / push x + subl $8,%esp + /// overhead of RP save/restore; 63/15 + fstcw (%esp) /// ; 15/3 + movw (%esp),%ax /// ; 4/1 + movw %ax,4(%esp) /// save old RP; 2/1 + orw $0x0300,%ax /// force 64-bit RP; 2/1 + movw %ax,(%esp) /// ; 2/1 + fldcw (%esp) /// ; 19/4 + fldl2e / push log2e }not for xtndd_dbl + fmulp %st,%st(1) / z = x*log2e }not for xtndd_dbl + fld %st(0) / duplicate stack top + frndint / [z],z + fucom / This and the next 3 instructions + fstsw %ax / add 10 clocks to runtime of the + sahf / main branch, but save about 265 + je .z_integral / upon detection of integral z. + / [z] != z, compute exp(x) + fxch / z,[z] + fsub %st(1),%st / z-[z],[z] + f2xm1 / 2**(z-[z])-1,[z] + fld1 / 1,2**(z-[z])-1,[z] + faddp %st,%st(1) / 2**(z-[z]) ,[z] +.merge: + fscale / exp(x) ,[z] + fstp %st(1) + fstcw (%esp) / restore RD + movw (%esp),%dx + andw $0xfcff,%dx + movw 4(%esp),%cx + andw $0x0300,%cx + orw %dx,%cx + movw %cx,(%esp) + fldcw (%esp) /// restore old RP; 19/4 + fstpl (%esp) / round to double + fldl (%esp) / exp(x) rounded to double + fxam / determine class of exp(x) + add $8,%esp + fstsw %ax / store status in ax + andw $0x4500,%ax + cmpw $0x0500,%ax + je .overflow + cmpw $0x4000,%ax + je .underflow + ret + +.overflow: + fstp %st(0) / stack empty + push %ebp + mov %esp,%ebp + PIC_SETUP(1) + pushl $6 + jmp .error + +.underflow: + fstp %st(0) / stack empty + push %ebp + mov %esp,%ebp + PIC_SETUP(2) + pushl $7 + +.error: + pushl 12(%ebp) / high x + pushl 8(%ebp) / low x + pushl 12(%ebp) / high x + pushl 8(%ebp) / low x + call PIC_F(_SVID_libm_err) + addl $20,%esp + PIC_WRAPUP + leave + ret + +.z_integral: / here, z is integral + fstp %st(0) / ,z + fld1 / 1,z + jmp .merge + +.check_tail: + movl 4(%esp),%edx / edx <-- lo_32(x) + cmpl $0xfefa39ef,%edx / Is |x| slightly < ln(2)? + ja .finite_non_special / branch if |x| slightly > ln(2) +.shortcut: + / Here, |x| < ln(2), so |z| = |x*log2(e)| < 1, + / whence z is in f2xm1's domain. + fldl 4(%esp) / push x + fldl2e / push log2e }not for xtndd_dbl + fmulp %st,%st(1) / z = x*log2e }not for xtndd_dbl + f2xm1 / 2**(x*log2(e))-1 = e**x - 1 + fld1 / 1,2**(z)-1 + faddp %st,%st(1) / 2**(z) = e**x + ret + +.not_finite: + / Here, flags still have settings from execution of + / cmpl $0x7ff00000,%ecx / hi_32(|x|) > hi_32(INF)? + ja .NaN_or_pinf / if not, x may be +/- INF + movl 4(%esp),%edx / edx <-- lo_32(x) + cmpl $0,%edx / lo_32(x) = 0? + jne .NaN_or_pinf / if not, x is NaN + movl 8(%esp),%eax / eax <-- hi_32(x) + andl $0x80000000,%eax / here, x is infinite, but +/-? + jz .NaN_or_pinf / branch if x = +INF + fldz / Here, x = -inf, so return 0 + ret + +.NaN_or_pinf: + / Here, x = NaN or +inf, so load x and return immediately. + fldl 4(%esp) + fwait + ret + .align 4 + SET_SIZE(exp) diff --git a/usr/src/lib/libm/i386/src/exp10.s b/usr/src/lib/libm/i386/src/exp10.s new file mode 100644 index 0000000000..28fe4b48f7 --- /dev/null +++ b/usr/src/lib/libm/i386/src/exp10.s @@ -0,0 +1,133 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "exp10.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(exp10,function) +#include "libm_synonyms.h" + + ENTRY(exp10) + movl 8(%esp),%ecx / ecx <-- hi_32(x) + andl $0x7fffffff,%ecx / ecx <-- hi_32(|x|) + cmpl $0x3fd34413,%ecx / Is |x| < log10(2)? + jb .shortcut / If so, take a shortcut. + je .check_tail / maybe |x| only slightly < log10(2) + cmpl $0x7ff00000,%ecx / hi_32(|x|) >= hi_32(INF)? + jae .not_finite / if so, x is not finite +.finite_non_special: / Here, log10(2) < |x| < INF + fldl 4(%esp) / push x (=arg) + + subl $8,%esp / save RP and set round-to-64-bits + fstcw (%esp) + movw (%esp),%ax + movw %ax,4(%esp) + orw $0x0300,%ax + movw %ax,(%esp) + fldcw (%esp) + + fldl2t / push log2(10) }NOT for xtndd_dbl + fmulp %st,%st(1) / z = x*log2(10) }NOT for xtndd_dbl + fld %st(0) / duplicate stack top + frndint / [z],z + fucom / z integral? + fstsw %ax + sahf + je .z_integral / branch if z integral + fxch / z, [z] + fsub %st(1),%st / z-[z], [z] + f2xm1 / 2**(z-[z])-1, [z] + fld1 / 1,2**(z-[z])-1, [z] + faddp %st,%st(1) / 2**(z-[z]), [z] + fscale / 2**z = 10**(arg), [z] + fstp %st(1) + + fstcw (%esp) / restore old RP + movw (%esp),%dx + andw $0xfcff,%dx + movw 4(%esp),%cx + andw $0x0300,%cx + orw %dx,%cx + movw %cx,(%esp) + fldcw (%esp) + add $8,%esp + + ret + +.z_integral: / here, z is integral + fstp %st(0) / ,z + fld1 / 1 = 2**0, z + fscale / 2**(0 + z) = 2**z = 10**(arg), z + fstp %st(1) / 10**(arg) + + fstcw (%esp) / restore old RP + movw (%esp),%dx + andw $0xfcff,%dx + movw 4(%esp),%cx + andw $0x0300,%cx + orw %dx,%cx + movw %cx,(%esp) + fldcw (%esp) + add $8,%esp + + ret + +.check_tail: + movl 4(%esp),%edx / edx <-- lo_32(x) + cmpl $0x509f79fe,%edx / Is |x| slightly > log10(2)? + ja .finite_non_special / branch if |x| slightly > log10(2) +.shortcut: + / Here, |x| < log10(2), so |z| = |x*log2(10)| < 1 + / whence z is in f2xm1's domain. + fldl 4(%esp) / push x (=arg) + fldl2t / push log2(10) }NOT for xtndd_dbl + fmulp %st,%st(1) / z = x*log2(10) }NOT for xtndd_dbl + f2xm1 / 2**z - 1 + fld1 / 1,2**z - 1 + faddp %st,%st(1) / 2**z = 10**x + ret + +.not_finite: + cmpl $0x7ff00000,%ecx / hi_32(|x|) > hi_32(INF)? + ja .NaN_or_pinf / if so, x is NaN + movl 4(%esp),%edx / edx <-- lo_32(x) + cmpl $0,%edx / lo_32(x) = 0? + jne .NaN_or_pinf / if not, x is NaN + movl 8(%esp),%eax / eax <-- hi_32(x) + andl $0x80000000,%eax / here, x is infinite, but +/-? + jz .NaN_or_pinf / branch if x = +INF + fldz / Here, x = -inf, so return 0 + ret + +.NaN_or_pinf: + / Here, x = NaN or +inf, so load x and return immediately. + fldl 4(%esp) + fwait + ret + .align 4 + SET_SIZE(exp10) diff --git a/usr/src/lib/libm/i386/src/exp10f.s b/usr/src/lib/libm/i386/src/exp10f.s new file mode 100644 index 0000000000..7c2fba095b --- /dev/null +++ b/usr/src/lib/libm/i386/src/exp10f.s @@ -0,0 +1,123 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "exp10f.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(exp10f,function) +#include "libm_synonyms.h" + + ENTRY(exp10f) + movl 4(%esp),%ecx / ecx <-- x + andl $0x7fffffff,%ecx / ecx <-- |x| + cmpl $0x3e9a209a,%ecx / Is |x| < log10(2)? + jbe .shortcut / If so, take a shortcut. + cmpl $0x7f800000,%ecx / |x| >= INF? + jae .not_finite / if so, x is not finite + flds 4(%esp) / push x (=arg) + + subl $8,%esp / save RP and set round-to-64-bits + fstcw (%esp) + movw (%esp),%ax + movw %ax,4(%esp) + orw $0x0300,%ax + movw %ax,(%esp) + fldcw (%esp) + + fldl2t / push log2(10) }NOT for xtndd_dbl + fmulp %st,%st(1) / z = x*log2(10) }NOT for xtndd_dbl + fld %st(0) / duplicate stack top + frndint / [z],z + fucom / z integral? + fstsw %ax + sahf + je .z_integral / branch if z integral + fxch / z, [z] + fsub %st(1),%st / z-[z], [z] + f2xm1 / 2**(z-[z])-1, [z] + fld1 / 1,2**(z-[z])-1, [z] + faddp %st,%st(1) / 2**(z-[z]), [z] + fscale / 2**z = 10**(arg), [z] + fstp %st(1) + + fstcw (%esp) / restore old RP + movw (%esp),%dx + andw $0xfcff,%dx + movw 4(%esp),%cx + andw $0x0300,%cx + orw %dx,%cx + movw %cx,(%esp) + fldcw (%esp) + add $8,%esp + + ret + +.z_integral: / here, z is integral + fstp %st(0) / ,z + fld1 / 1 = 2**0, z + fscale / 2**(0 + z) = 2**z = 10**(arg), z + fstp %st(1) / 10**(arg) + + fstcw (%esp) / restore old RP + movw (%esp),%dx + andw $0xfcff,%dx + movw 4(%esp),%cx + andw $0x0300,%cx + orw %dx,%cx + movw %cx,(%esp) + fldcw (%esp) + add $8,%esp + + ret + +.shortcut: + / Here, |x| < log10(2), so |z| = |x*log2(10)| < 1 + / whence z is in f2xm1's domain. + flds 4(%esp) / push x (=arg) + fldl2t / push log2(10) }NOT for xtndd_dbl + fmulp %st,%st(1) / z = x*log2(10) }NOT for xtndd_dbl + f2xm1 / 2**z - 1 + fld1 / 1,2**z - 1 + faddp %st,%st(1) / 2**z = 10**x + ret + +.not_finite: + ja .NaN_or_pinf / branch if x is NaN + movl 4(%esp),%eax / eax <-- x + andl $0x80000000,%eax / here, x is infinite, but +/-? + jz .NaN_or_pinf / branch if x = +INF + fldz / Here, x = -inf, so return 0 + ret + +.NaN_or_pinf: + / Here, x = NaN or +inf, so load x and return immediately. + flds 4(%esp) + fwait + ret + .align 4 + SET_SIZE(exp10f) diff --git a/usr/src/lib/libm/i386/src/exp10l.s b/usr/src/lib/libm/i386/src/exp10l.s new file mode 100644 index 0000000000..228652b89c --- /dev/null +++ b/usr/src/lib/libm/i386/src/exp10l.s @@ -0,0 +1,115 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "exp10l.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(exp10l,function) +#include "libm_synonyms.h" + + .data + .align 4 +lt2_hi: .long 0xfbd00000, 0x9a209a84, 0x00003ffd +lt2_lo: .long 0x653f4837, 0x8677076a, 0x0000bfc9 + + ENTRY(exp10l) + movl 12(%esp),%ecx / cx <--sign&bexp(x) + andl $0x00007fff,%ecx / ecx <-- zero_xtnd(bexp(x)) + cmpl $0x00003ffd,%ecx / Is |x| < log10(2)? + jb .shortcut / If so, take a shortcut. + je .check_tail / maybe |x| only slightly < log10(2) + cmpl $0x00007fff,%ecx / bexp(|x|) = bexp(INF)? + je .not_finite / if so, x is not finite + cmpl $0x0000400e,%ecx / |x| < 32768 = 2^15? + jb .finite_non_special / if so, proceed with argument reduction + fldt 4(%esp) / x + fld1 / 1, x + jmp 1f +.finite_non_special: / Here, log10(2) < |x| < 2^15 + fldt 4(%esp) / x + fld %st(0) / x, x + fldl2t / log2(10), x, x + fmulp / z := x*log2(10), x + frndint / [z], x + fst %st(2) / [z], x, [z] + PIC_SETUP(1) + fldt PIC_L(lt2_hi) / lt2_hi, [z], x, [z] + fmulp / [z]*lt2_hi, x, [z] + fsubrp %st,%st(1) / x-[z]*lt2_hi, [z] + fldt PIC_L(lt2_lo) / lt2_lo, x-[z]*lt2_hi, [z] + PIC_WRAPUP + fmul %st(2),%st / [z]*lt2_lo, x-[z]*lt2_hi, [z] + fsubrp %st,%st(1) / r := x-[z]*log10(2), [z] + fldl2t / log2(10), r, [z] + fmulp / f := r*log2(10), [z] + f2xm1 / 2^f-1,[z] + fld1 / 1, 2^f-1, [z] + faddp %st,%st(1) / 2^f, [z] +1: + fscale / 10^x, [z] + fstp %st(1) + ret + +.check_tail: + movl 8(%esp),%ecx / ecx <-- hi_32(sgnfcnd(x)) + cmpl $0x9a209a84,%ecx / Is |x| < log10(2)? + ja .finite_non_special + jb .shortcut + movl 4(%esp),%edx / edx <-- lo_32(sgnfcnd(x)) + cmpl $0xfbcff798,%edx / Is |x| slightly > log10(2)? + ja .finite_non_special / branch if |x| slightly > log10(2) +.shortcut: + / Here, |x| < log10(2), so |z| = |x/log10(2)| < 1 + / whence z is in f2xm1's domain. + fldt 4(%esp) / x + fldl2t / log2(10), x + fmulp / z := x*log2(10) + f2xm1 / 2^z-1 + fld1 / 1, 2^z-1 + faddp %st,%st(1) / 10^x + ret + +.not_finite: + movl 8(%esp),%ecx / ecx <-- hi_32(sgnfcnd(x)) + cmpl $0x80000000,%ecx / hi_32(sgnfcnd(x)) = hi_32(sgnfcnd(INF))? + jne .NaN_or_pinf / if not, x is NaN or unsupp. + movl 4(%esp),%edx / edx <-- lo_32(sgnfcnd(x)) + cmpl $0,%edx / lo_32(sgnfcnd(x)) = 0? + jne .NaN_or_pinf / if not, x is NaN + movl 12(%esp),%eax / ax <-- sign&bexp((x)) + andl $0x00008000,%eax / here, x is infinite, but +/-? + jz .NaN_or_pinf / branch if x = +INF + fldz / Here, x = -inf, so return 0 + ret + +.NaN_or_pinf: + / Here, x = NaN or +inf, so load x and return immediately. + fldt 4(%esp) + ret + .align 4 + SET_SIZE(exp10l) diff --git a/usr/src/lib/libm/i386/src/exp2.s b/usr/src/lib/libm/i386/src/exp2.s new file mode 100644 index 0000000000..7d0bc8f85d --- /dev/null +++ b/usr/src/lib/libm/i386/src/exp2.s @@ -0,0 +1,98 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "exp2.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(exp2,function) +#include "libm_synonyms.h" + + ENTRY(exp2) + movl 8(%esp),%ecx / ecx <-- hi_32(x) + andl $0x7fffffff,%ecx / ecx <-- hi_32(|x|) + cmpl $0x3ff00000,%ecx / Is |x| < 1? + jb .shortcut / If so, take a shortcut. + je .check_tail / |x| may be only slightly < ln(2) + cmpl $0x7ff00000,%ecx / hi_32(|x|) >= hi_32(INF)? + jae .not_finite / if so, x is not finite +.finite_non_special: / Here, 1 < |x| < INF + fldl 4(%esp) / push arg + fld %st(0) / duplicate stack top + frndint / [x],x + fucom / x integral? + fstsw %ax + sahf + je .x_integral / branch if x integral + fxch / x, [x] + fsub %st(1),%st / x-[x], [x] + f2xm1 / 2**(x-[x])-1, [x] + fld1 / 1,2**(x-[x])-1, [x] + faddp %st,%st(1) / 2**(x-[x]), [x] + fscale / 2**x = 2**(arg), [x] + fstp %st(1) + ret + +.x_integral: + fstp %st(0) / ,x + fld1 / 1 = 2**0, x + fscale / 2**(0 + x) = 2**x, x + fstp %st(1) / 2**x + ret + +.check_tail: + movl 4(%esp),%edx / edx <-- lo_32(x) + cmpl $0x00000000,%edx / Is |x| slightly > 1? + ja .finite_non_special / branch if |x| slightly > 1 +.shortcut: + / Here, |x| <= 1, + / whence x is in f2xm1's domain. + fldl 4(%esp) / push x + f2xm1 / 2**x - 1 + fld1 / 1,2**x - 1 + faddp %st,%st(1) / 2**x + ret + +.not_finite: + cmpl $0x7ff00000,%ecx / hi_32(|x|) > hi_32(INF)? + ja .NaN_or_pinf / if so, x is NaN + movl 4(%esp),%edx / edx <-- lo_32(x) + cmpl $0,%edx / lo_32(x) = 0? + jne .NaN_or_pinf / if not, x is NaN + movl 8(%esp),%eax / eax <-- hi_32(x) + andl $0x80000000,%eax / here, x is infinite, but +/-? + jz .NaN_or_pinf / branch if x = +INF + fldz / Here, x = -inf, so return 0 + ret + +.NaN_or_pinf: + / Here, x = NaN or +inf, so load x and return immediately. + fldl 4(%esp) + fwait + ret + .align 4 + SET_SIZE(exp2) diff --git a/usr/src/lib/libm/i386/src/exp2f.s b/usr/src/lib/libm/i386/src/exp2f.s new file mode 100644 index 0000000000..34b3d7fb8a --- /dev/null +++ b/usr/src/lib/libm/i386/src/exp2f.s @@ -0,0 +1,88 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "exp2f.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(exp2f,function) +#include "libm_synonyms.h" + + ENTRY(exp2f) + movl 4(%esp),%ecx / ecx <-- x + andl $0x7fffffff,%ecx / ecx <-- |x| + cmpl $0x3f800000,%ecx / Is |x| <= 1? + jbe .shortcut / If so, take a shortcut. + cmpl $0x7f800000,%ecx / |x| >= INF? + jae .not_finite / if so, x is not finite + flds 4(%esp) / push arg + fld %st(0) / duplicate stack top + frndint / [x],x + fucom / x integral? + fstsw %ax + sahf + je .x_integral / branch if x integral + fxch / x, [x] + fsub %st(1),%st / x-[x], [x] + f2xm1 / 2**(x-[x])-1, [x] + fld1 / 1,2**(x-[x])-1, [x] + faddp %st,%st(1) / 2**(x-[x]), [x] + fscale / 2**x = 2**(arg), [x] + fstp %st(1) + ret + +.x_integral: / here, x is integral + fstp %st(0) / ,x + fld1 / 1 = 2**0, x + fscale / 2**(0 + x) = 2**x, x + fstp %st(1) / 2**x + ret + +.shortcut: + / Here, |x| <= 1, + / whence x is in f2xm1's domain. + flds 4(%esp) / push x + f2xm1 / 2**x - 1 + fld1 / 1,2**x - 1 + faddp %st,%st(1) / 2**x + ret + +.not_finite: + ja .NaN_or_pinf / branch if x is NaN + movl 4(%esp),%eax / eax <-- x + andl $0x80000000,%eax / here, x is infinite, but +/-? + jz .NaN_or_pinf / branch if x = +INF + fldz / Here, x = -inf, so return 0 + ret + +.NaN_or_pinf: + / Here, x = NaN or +inf, so load x and return immediately. + flds 4(%esp) + fwait + ret + .align 4 + SET_SIZE(exp2f) diff --git a/usr/src/lib/libm/i386/src/exp2l.s b/usr/src/lib/libm/i386/src/exp2l.s new file mode 100644 index 0000000000..b4ba784cbc --- /dev/null +++ b/usr/src/lib/libm/i386/src/exp2l.s @@ -0,0 +1,101 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "exp2l.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(exp2l,function) +#include "libm_synonyms.h" + + ENTRY(exp2l) + movl 12(%esp),%ecx / cx <--sign&bexp(x) + andl $0x00007fff,%ecx / ecx <-- zero_xtnd(bexp(x)) + cmpl $0x00003fff,%ecx / Is |x| <= 1? + jb .shortcut / If so, take a shortcut. + je .check_tail / |x| may be slightly > 1 + cmpl $0x00007fff,%ecx / bexp(|x|) = bexp(INF)? + je .not_finite / if so, x is not finite +.finite_non_special: / Here, 1 < |x| < INF + fldt 4(%esp) / push arg + fld %st(0) / duplicate stack top + frndint / [x],x + fucom / x integral? + fnstsw %ax + sahf + je .x_integral / branch if x integral + fxch / x, [x] + fsub %st(1),%st / x-[x], [x] + f2xm1 / 2**(x-[x])-1, [x] + fld1 / 1,2**(x-[x])-1, [x] + faddp %st,%st(1) / 2**(x-[x]), [x] + fscale / 2**x = 2**(arg), [x] + fstp %st(1) + ret + +.x_integral: + fstp %st(0) / ,x + fld1 / 1 = 2**0, x + fscale / 2**(0 + x) = 2**x, x + fstp %st(1) / 2**x + ret + +.check_tail: + movl 8(%esp),%ecx / ecx <-- hi_32(sgnfcnd(x)) + cmpl $0x80000000,%ecx / Is |x| <= 1? + ja .finite_non_special + movl 4(%esp),%edx / edx <-- lo_32(sgnfcnd(x)) + cmpl $0x00000000,%edx / Is |x| slightly > 1? + ja .finite_non_special / branch if |x| slightly > 1 +.shortcut: + / Here, |x| < 1, + / whence x is in f2xm1's domain. + fldt 4(%esp) / push x + f2xm1 / 2**x - 1 + fld1 / 1,2**x - 1 + faddp %st,%st(1) / 2**x + ret + +.not_finite: + movl 8(%esp),%ecx / ecx <-- hi_32(sgnfcnd(x)) + cmpl $0x80000000,%ecx / hi_32(|x|) = hi_32(INF)? + jne .NaN_or_pinf / if not, x is NaN + movl 4(%esp),%edx / edx <-- lo_32(x) + cmpl $0,%edx / lo_32(x) = 0? + jne .NaN_or_pinf / if not, x is NaN + movl 12(%esp),%eax / ax <-- sign&bexp((x)) + andl $0x00008000,%eax / here, x is infinite, but +/-? + jz .NaN_or_pinf / branch if x = +INF + fldz / Here, x = -inf, so return 0 + ret + +.NaN_or_pinf: + / Here, x = NaN or +inf, so load x and return immediately. + fldt 4(%esp) + ret + .align 4 + SET_SIZE(exp2l) diff --git a/usr/src/lib/libm/i386/src/expl.s b/usr/src/lib/libm/i386/src/expl.s new file mode 100644 index 0000000000..22736b962c --- /dev/null +++ b/usr/src/lib/libm/i386/src/expl.s @@ -0,0 +1,124 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "expl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(expl,function) +#include "libm_synonyms.h" + + .data + .align 4 +ln2_hi: .long 0xd1d00000, 0xb17217f7, 0x00003ffe +ln2_lo: .long 0x4c67fc0d, 0x8654361c, 0x0000bfce + + ENTRY(expl) + movl 12(%esp),%ecx / cx <--sign&bexp(x) + andl $0x7fff,%ecx / ecx <-- zero_xtnd(bexp(x)) + cmpl $0x3ffe,%ecx / Is |x| < 0.5? + jb 2f / If so, see which shortcut to take + je .check_tail / More checking if 0.5 <= |x| < 1 + cmpl $0x00007fff,%ecx / bexp(|x|) = bexp(INF)? + je .not_finite / if so, x is not finite + cmpl $0x0000400e,%ecx / |x| < 32768 = 2^15? + jb .finite_non_special / if so, proceed with argument reduction + fldt 4(%esp) / x + fld1 / 1, x + jmp 1f +.finite_non_special: / Here, ln(2) < |x| < 2^15 + fldt 4(%esp) / x + fld %st(0) / x, x + fldl2e / log2(e), x, x + fmulp / z := x*log2(e), x + frndint / [z], x + fst %st(2) / [z], x, [z] + PIC_SETUP(1) + fldt PIC_L(ln2_hi) / ln2_hi, [z], x, [z] + fmulp / [z]*ln2_hi, x, [z] + fsubrp %st,%st(1) / x-[z]*ln2_hi, [z] + fldt PIC_L(ln2_lo) / ln2_lo, x-[z]*ln2_hi, [z] + PIC_WRAPUP + fmul %st(2),%st / [z]*ln2_lo, x-[z]*ln2_hi, [z] + fsubrp %st,%st(1) / r := x-[z]*ln(2), [z] + fldl2e / log2(e), r, [z] + fmulp / f := r*log2(e), [z] + f2xm1 / 2^f-1,[z] + fld1 / 1, 2^f-1, [z] + faddp %st,%st(1) / 2^f, [z] +1: + fscale / e^x, [z] + fstp %st(1) + ret + +2: / Here, |x| < 0.5 + cmpl $0x3fbe,%ecx / Is |x| >= 2^-65? + jae .shortcut / If so, take a shortcut + fldt 4(%esp) / x + fld1 / 1, x + faddp %st,%st(1) / 1+x (for inexact & directed rounding) + ret + +.check_tail: + movl 8(%esp),%ecx / ecx <-- hi_32(sgnfcnd(x)) + cmpl $0xb17217f7,%ecx / Is |x| < ln(2)? + ja .finite_non_special + jb .shortcut + movl 4(%esp),%edx / edx <-- lo_32(x) + cmpl $0xd1cf79ab,%edx / Is |x| slightly < ln(2)? + ja .finite_non_special / branch if |x| slightly > ln(2) +.shortcut: + / Here, |x| < ln(2), so |z| = |x/ln(2)| < 1, + / whence z is in f2xm1's domain. + fldt 4(%esp) / x + fldl2e / log2(e), x + fmulp / x*log2(e) + f2xm1 / 2^(x*log2(e))-1 = e^x-1 + fld1 / 1, e^x-1 + faddp %st,%st(1) / e^x + ret + +.not_finite: + movl 8(%esp),%ecx / ecx <-- hi_32(sgnfcnd(x)) + cmpl $0x80000000,%ecx / hi_32(|x|) = hi_32(INF)? + jne .NaN_or_pinf / if not, x is NaN + movl 4(%esp),%edx / edx <-- lo_32(x) + cmpl $0,%edx / lo_32(x) = 0? + jne .NaN_or_pinf / if not, x is NaN + movl 12(%esp),%eax / ax <-- sign&bexp((x)) + andl $0x00008000,%eax / here, x is infinite, but +/-? + jz .NaN_or_pinf / branch if x = +INF + fldz / Here, x = -inf, so return 0 + ret + +.NaN_or_pinf: + / Here, x = NaN or +inf, so load x and return immediately. + fldt 4(%esp) + fadd %st(0),%st / quiet SNaN + ret + .align 4 + SET_SIZE(expl) diff --git a/usr/src/lib/libm/i386/src/expm1.s b/usr/src/lib/libm/i386/src/expm1.s new file mode 100644 index 0000000000..bca8dfe46e --- /dev/null +++ b/usr/src/lib/libm/i386/src/expm1.s @@ -0,0 +1,130 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "expm1.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(expm1,function) +#include "libm_synonyms.h" + + .data + .align 4 +.mhundred: .float -100.0 + + ENTRY(expm1) + movl 8(%esp),%ecx / ecx <-- hi_32(x) + andl $0x7fffffff,%ecx / ecx <-- hi_32(|x|) + cmpl $0x3fe62e42,%ecx / Is |x| < ln(2)? + jb .shortcut / If so, take a shortcut. + je .check_tail / |x| may be only slightly < ln(2) + cmpl $0x7ff00000,%ecx / hi_32(|x|) >= hi_32(INF)? + jae .not_finite / if so, x is not finite +.finite_non_special: / Here, ln(2) < |x| < INF + fldl 4(%esp) / push x + + subl $8,%esp / save RP and set round-to-64-bits + fstcw (%esp) + movw (%esp),%ax + movw %ax,4(%esp) + orw $0x0300,%ax + movw %ax,(%esp) + fldcw (%esp) + + fldl2e / push log2e }not for xtndd_dbl + fmulp %st,%st(1) / z = x*log2e }not for xtndd_dbl + fld %st(0) / duplicate stack top + frndint / [z],z + / [z] != 0, compute exp(x) and then subtract one to get expm1(x) + fxch / z,[z] + fsub %st(1),%st / z-[z],[z] + f2xm1 / 2**(z-[z])-1,[z] + / avoid spurious underflow when scaling to compute exp(x) + PIC_SETUP(1) + flds PIC_L(.mhundred) + PIC_WRAPUP + fucom %st(2) / if -100 !< [z], then use -100 + fstsw %ax + sahf + jb .got_int_part + fxch %st(2) +.got_int_part: + fstp %st(0) / 2**(z-[z])-1,max([z],-100) + fld1 / 1,2**(z-[z])-1,max([z],-100) + faddp %st,%st(1) / 2**(z-[z]) ,max([z],-100) + fscale / exp(x) ,max([z],-100) + fld1 / 1,exp(x) ,max([z],-100) + fxch / exp(x),1 ,max([z],-100) + fsubp %st,%st(1) / exp(x)-1 ,max([z],-100) + fstp %st(1) + + fstcw (%esp) / restore old RP + movw (%esp),%dx + andw $0xfcff,%dx + movw 4(%esp),%cx + andw $0x0300,%cx + orw %dx,%cx + movw %cx,(%esp) + fldcw (%esp) + add $8,%esp + + ret + +.check_tail: + movl 4(%esp),%edx / edx <-- lo_32(x) + cmpl $0xfefa39ef,%edx / Is |x| slightly < ln(2)? + ja .finite_non_special / branch if |x| slightly > ln(2) +.shortcut: + / Here, |x| < ln(2), so |z| = |x*log2(e)| < 1, + / whence z is in f2xm1's domain. + fldl 4(%esp) / push x + fldl2e / push log2e }not for xtndd_dbl + fmulp %st,%st(1) / z = x*log2e }not for xtndd_dbl + f2xm1 / 2**(x*log2(e))-1 = e**x - 1 + ret + +.not_finite: + / Here, flags still have settings from execution of + / cmpl $0x7ff00000,%ecx / hi_32(|x|) > hi_32(INF)? + ja .NaN_or_pinf / if not, x may be +/- INF + movl 4(%esp),%edx / edx <-- lo_32(x) + cmpl $0,%edx / lo_32(x) = 0? + jne .NaN_or_pinf / if not, x is NaN + movl 8(%esp),%eax / eax <-- hi_32(x) + andl $0x80000000,%eax / here, x is infinite, but +/-? + jz .NaN_or_pinf / branch if x = +INF + fld1 / Here, x = -inf, so return -1 + fchs + ret + +.NaN_or_pinf: + / Here, x = NaN or +inf, so load x and return immediately. + fldl 4(%esp) + fwait + ret + .align 4 + SET_SIZE(expm1) diff --git a/usr/src/lib/libm/i386/src/expm1f.s b/usr/src/lib/libm/i386/src/expm1f.s new file mode 100644 index 0000000000..08abd37b2c --- /dev/null +++ b/usr/src/lib/libm/i386/src/expm1f.s @@ -0,0 +1,153 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "expm1f.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(expm1f,function) +#include "libm_synonyms.h" + + .data + .align 4 +.mhundred: .float -100.0 + + ENTRY(expm1f) + movl 4(%esp),%ecx / ecx <-- x + andl $0x7fffffff,%ecx / ecx <-- |x| + cmpl $0x3f317217,%ecx / Is |x| < ln(2)? + jbe .shortcut / If so, take a shortcut. + cmpl $0x7f800000,%ecx / |x| >= INF? + jae .not_finite / if so, x is not finite + flds 4(%esp) / push x + + subl $8,%esp / save RP and set round-to-64-bits + fstcw (%esp) + movw (%esp),%ax + movw %ax,4(%esp) + orw $0x0300,%ax + movw %ax,(%esp) + fldcw (%esp) + + fldl2e / push log2e }not for xtndd_dbl + fmulp %st,%st(1) / z = x*log2e }not for xtndd_dbl + fld %st(0) / duplicate stack top + frndint / [z],z + fucom / This and the next 3 instructions + fstsw %ax / add 10 clocks to runtime of the + sahf / main branch, but save about 265 + je .z_integral / upon detection of integral z. + / [z] != 0, compute exp(x) and then subtract one to get expm1(x) + fxch / z,[z] + fsub %st(1),%st / z-[z],[z] + f2xm1 / 2**(z-[z])-1,[z] + / avoid spurious underflow when scaling to compute exp(x) + PIC_SETUP(1) + flds PIC_L(.mhundred) + PIC_WRAPUP + fucom %st(2) / if -100 !< [z], then use -100 + fstsw %ax + sahf + jb .got_int_part + fxch %st(2) +.got_int_part: + fstp %st(0) / 2**(z-[z])-1,max([z],-100) + fld1 / 1,2**(z-[z])-1,max([z],-100) + faddp %st,%st(1) / 2**(z-[z]) ,max([z],-100) + fscale / exp(x) ,max([z],-100) + fld1 / 1,exp(x) ,max([z],-100) + fsubrp %st,%st(1) / exp(x)-1 ,max([z],-100) + fstp %st(1) + + fstcw (%esp) / restore old RP + movw (%esp),%dx + andw $0xfcff,%dx + movw 4(%esp),%cx + andw $0x0300,%cx + orw %dx,%cx + movw %cx,(%esp) + fldcw (%esp) + add $8,%esp + + ret + +.z_integral: / here, z is integral + fstp %st(0) / ,z + / avoid spurious underflow when scaling to compute exp(x) + PIC_SETUP(2) + flds PIC_L(.mhundred) + PIC_WRAPUP + fucom %st(1) / if -100 !< [z], then use -100 + fstsw %ax + sahf + jb .scale_wont_ovfl + fxch %st(1) +.scale_wont_ovfl: + fstp %st(0) / max([z],-100) + fld1 / 1,max([z],-100) + fscale / exp(x) ,max([z],-100) + fld1 / 1,exp(x) ,max([z],-100) + fsubrp %st,%st(1) / exp(x)-1 ,max([z],-100) + fstp %st(1) + + fstcw (%esp) / restore old RP + movw (%esp),%dx + andw $0xfcff,%dx + movw 4(%esp),%cx + andw $0x0300,%cx + orw %dx,%cx + movw %cx,(%esp) + fldcw (%esp) + add $8,%esp + + ret + +.shortcut: + / Here, |x| < ln(2), so |z| = |x*log2(e)| < 1, + / whence z is in f2xm1's domain. + flds 4(%esp) / push x + fldl2e / push log2e }not for xtndd_dbl + fmulp %st,%st(1) / z = x*log2e }not for xtndd_dbl + f2xm1 / 2**(x*log2(e))-1 = e**x - 1 + ret + +.not_finite: + ja .NaN_or_pinf / branch if x is NaN + movl 4(%esp),%eax / eax <-- x + andl $0x80000000,%eax / here, x is infinite, but +/-? + jz .NaN_or_pinf / branch if x = +INF + fld1 / Here, x = -inf, so return -1 + fchs + ret + +.NaN_or_pinf: + / Here, x = NaN or +inf, so load x and return immediately. + flds 4(%esp) + fwait + ret + .align 4 + SET_SIZE(expm1f) diff --git a/usr/src/lib/libm/i386/src/expm1l.s b/usr/src/lib/libm/i386/src/expm1l.s new file mode 100644 index 0000000000..2ece2d59de --- /dev/null +++ b/usr/src/lib/libm/i386/src/expm1l.s @@ -0,0 +1,123 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "expm1l.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(expm1l,function) +#include "libm_synonyms.h" + + .data + .align 4 +ln2_hi: .long 0xd1d00000, 0xb17217f7, 0x00003ffe +ln2_lo: .long 0x4c67fc0d, 0x8654361c, 0x0000bfce + + ENTRY(expm1l) + movl 12(%esp),%ecx / cx <--sign&bexp(x) + movl %ecx,%eax / ax <--sign&bexp(x) + andl $0x00007fff,%ecx / ecx <-- zero_xtnd(bexp(x)) + cmpl $0x00003ffe,%ecx / Is |x| < ln(2)? + jb .shortcut / If so, take a shortcut. + je .check_tail / |x| may be only slightly < ln(2) + cmpl $0x00007fff,%ecx / bexp(|x|) = bexp(INF)? + je .not_finite / if so, x is not finite + andl $0x0000ffff,%eax / eax <-- sign&bexp(x) + cmpl $0x0000c006,%eax / x <= -128? + jae 1f / if so, simply return -1 + cmpl $0x0000400d,%ecx / |x| < 16384 = 2^14? + jb .finite_non_special / if so, proceed with argument reduction + fldt 4(%esp) / x >= 16384; x + fld1 / 1, x + fscale / +Inf, x + fstp %st(1) / +Inf + ret + +.finite_non_special: / -128 < x < -ln(2) || ln(2) < x < 2^14 + fldt 4(%esp) / x + fld %st(0) / x, x + fldl2e / log2(e), x, x + fmulp / z := x*log2(e), x + frndint / [z], x + fst %st(2) / [z], x, [z] + PIC_SETUP(1) + fldt PIC_L(ln2_hi) / ln2_hi, [z], x, [z] + fmulp / [z]*ln2_hi, x, [z] + fsubrp %st,%st(1) / x-[z]*ln2_hi, [z] + fldt PIC_L(ln2_lo) / ln2_lo, x-[z]*ln2_hi, [z] + PIC_WRAPUP + fmul %st(2),%st / [z]*ln2_lo, x-[z]*ln2_hi, [z] + fsubrp %st,%st(1) / r := x-[z]*ln(2), [z] + fldl2e / log2(e), r, [z] + fmulp / f := r*log2(e), [z] + f2xm1 / 2^f-1,[z] + fld1 / 1, 2^f-1, [z] + faddp %st,%st(1) / 2^f, [z] + fscale / e^x, [z] + fstp %st(1) / e^x + fld1 / 1, e^x + fsubrp %st,%st(1) / e^x-1 + ret + +.check_tail: + movl 8(%esp),%ecx / ecx <-- hi_32(sgnfcnd(x)) + cmpl $0xb17217f7,%ecx / Is |x| < ln(2)? + ja .finite_non_special + jb .shortcut + movl 4(%esp),%edx / edx <-- lo_32(x) + cmpl $0xd1cf79ab,%edx / Is |x| slightly < ln(2)? + ja .finite_non_special / branch if |x| slightly > ln(2) +.shortcut: + / Here, |x| < ln(2), so |z| = |x/ln(2)| < 1, + / whence z is in f2xm1's domain. + fldt 4(%esp) / x + fldl2e / log2(e), x + fmulp / z := x*log2(e) + f2xm1 / 2^(x*log2(e))-1 = e^x-1 + ret + +.not_finite: + movl 8(%esp),%ecx / ecx <-- hi_32(sgnfcnd(x)) + cmpl $0x80000000,%ecx / hi_32(|x|) = hi_32(INF)? + jne .NaN_or_pinf / if not, x is NaN + movl 4(%esp),%edx / edx <-- lo_32(x) + cmpl $0,%edx / lo_32(x) = 0? + jne .NaN_or_pinf / if not, x is NaN + movl 12(%esp),%eax / ax <-- sign&bexp((x)) + andl $0x00008000,%eax / here, x is infinite, but +/-? + jz .NaN_or_pinf / branch if x = +INF +1: + fld1 / Here, x = -inf, so return -1 + fchs + ret + +.NaN_or_pinf: + / Here, x = NaN or +inf, so load x and return immediately. + fldt 4(%esp) + ret + .align 4 + SET_SIZE(expm1l) diff --git a/usr/src/lib/libm/i386/src/fabs.s b/usr/src/lib/libm/i386/src/fabs.s new file mode 100644 index 0000000000..b2fc32f9e2 --- /dev/null +++ b/usr/src/lib/libm/i386/src/fabs.s @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "fabs.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(fabs,function) +#include "libm_synonyms.h" + + ENTRY(fabs) + fldl 4(%esp) +#undef fabs + fabs + ret + .align 4 + SET_SIZE(fabs) diff --git a/usr/src/lib/libm/i386/src/fabsf.s b/usr/src/lib/libm/i386/src/fabsf.s new file mode 100644 index 0000000000..e89180e4e6 --- /dev/null +++ b/usr/src/lib/libm/i386/src/fabsf.s @@ -0,0 +1,42 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "fabsf.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(fabsf,function) +#include "libm_synonyms.h" + + ENTRY(fabsf) + flds 4(%esp) +#undef fabs + fabs + ret + .align 4 + SET_SIZE(fabsf) + diff --git a/usr/src/lib/libm/i386/src/fabsl.s b/usr/src/lib/libm/i386/src/fabsl.s new file mode 100644 index 0000000000..d21f3d3a37 --- /dev/null +++ b/usr/src/lib/libm/i386/src/fabsl.s @@ -0,0 +1,42 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "fabsl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(fabsl,function) +#include "libm_synonyms.h" + + ENTRY(fabsl) + fldt 4(%esp) +#undef fabs + fabs + ret + .align 4 + SET_SIZE(fabsl) + diff --git a/usr/src/lib/libm/i386/src/finitef.s b/usr/src/lib/libm/i386/src/finitef.s new file mode 100644 index 0000000000..70e119cc37 --- /dev/null +++ b/usr/src/lib/libm/i386/src/finitef.s @@ -0,0 +1,44 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "finitef.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(finitef,function) +#include "libm_synonyms.h" + + ENTRY(finitef) + movl 4(%esp),%eax / eax <-- x + notl %eax / not(bexp) = 0 iff bexp = all 1's + andl $0x7f800000,%eax / ZF <-- 1 iff not(bexp) = 0 + jz .done / no jump if arg. is finite + movl $1,%eax / %ax was 0; ansi needs %eax = 1 +.done: + ret + .align 4 + SET_SIZE(finitef) diff --git a/usr/src/lib/libm/i386/src/finitel.s b/usr/src/lib/libm/i386/src/finitel.s new file mode 100644 index 0000000000..3b3e792d59 --- /dev/null +++ b/usr/src/lib/libm/i386/src/finitel.s @@ -0,0 +1,56 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "finitel.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(finitel,function) +#include "libm_synonyms.h" + + ENTRY(finitel) + movl 12(%esp),%eax / %ax <-- sign&bexp(x) + testl $0x80000000,8(%esp) / ZF = 1 iff hi_32(sgnfcnd(x))'s msb = 0 + jz .chk_denormal_or_0 + notl %eax / not(bexp) = 0 iff bexp = all 1's + andl $0x00007fff,%eax / ZF <-- 1 iff not(bexp) = 0 + jz .done / no jump if arg. is finite + movl $1,%eax / ansi needs %eax = 1 +.done: + ret + +.chk_denormal_or_0: + andl $0x00007fff,%eax / ZF <-- 1 iff bexp = 0 iff denormal or 0 + jnz .unsupported / jump if arg has unsupported format + movl $1,%eax / ansi needs %eax = 1 + ret + +.unsupported: + movl $0,%eax / unsupported format does not represent + ret / a finite number + .align 4 + SET_SIZE(finitel) diff --git a/usr/src/lib/libm/i386/src/floor.s b/usr/src/lib/libm/i386/src/floor.s new file mode 100644 index 0000000000..c03b68bc7f --- /dev/null +++ b/usr/src/lib/libm/i386/src/floor.s @@ -0,0 +1,56 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "floor.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(floor,function) +#include "libm_synonyms.h" + + ENTRY(floor) + subl $8,%esp + fstcw (%esp) + fldl 12(%esp) + movw (%esp),%cx + orw $0x0c00,%cx + xorw $0x0800,%cx + movw %cx,4(%esp) + fldcw 4(%esp) / set RD = down + frndint + fstcw 4(%esp) / restore RD + movw 4(%esp),%dx + andw $0xf3ff,%dx + movw (%esp),%cx + andw $0x0c00,%cx + orw %dx,%cx + movw %cx,(%esp) + fldcw (%esp) / restore RD + addl $8,%esp + ret + .align 4 + SET_SIZE(floor) diff --git a/usr/src/lib/libm/i386/src/floorl.s b/usr/src/lib/libm/i386/src/floorl.s new file mode 100644 index 0000000000..d9dabfb87c --- /dev/null +++ b/usr/src/lib/libm/i386/src/floorl.s @@ -0,0 +1,81 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "floorl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(ceill,function) +LIBM_ANSI_PRAGMA_WEAK(floorl,function) +#include "libm_synonyms.h" + + ENTRY(ceill) + subl $8,%esp + fstcw (%esp) + fldt 12(%esp) + movw (%esp),%cx + orw $0x0c00,%cx + xorw $0x0400,%cx + movw %cx,4(%esp) + fldcw 4(%esp) / set RD = up + frndint + fstcw 4(%esp) / restore RD + movw 4(%esp),%dx + andw $0xf3ff,%dx + movw (%esp),%cx + andw $0x0c00,%cx + orw %dx,%cx + movw %cx,(%esp) + fldcw (%esp) / restore RD + addl $8,%esp + ret + .align 4 + SET_SIZE(ceill) + + + ENTRY(floorl) + subl $8,%esp + fstcw (%esp) + fldt 12(%esp) + movw (%esp),%cx + orw $0x0c00,%cx + xorw $0x0800,%cx + movw %cx,4(%esp) + fldcw 4(%esp) / set RD = down + frndint + fstcw 4(%esp) / restore RD + movw 4(%esp),%dx + andw $0xf3ff,%dx + movw (%esp),%cx + andw $0x0c00,%cx + orw %dx,%cx + movw %cx,(%esp) + fldcw (%esp) / restore RD + addl $8,%esp + ret + .align 4 + SET_SIZE(floorl) diff --git a/usr/src/lib/libm/i386/src/fmod.s b/usr/src/lib/libm/i386/src/fmod.s new file mode 100644 index 0000000000..0c8a048994 --- /dev/null +++ b/usr/src/lib/libm/i386/src/fmod.s @@ -0,0 +1,66 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "fmod.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(fmod,function) +#include "libm_synonyms.h" +#include "libm_protos.h" + + ENTRY(fmod) + movl 16(%esp),%eax / eax <-- hi_32(y) + andl $0x7fffffff,%eax / eax <-- hi_32(|y|) + orl 12(%esp),%eax / eax <-- lo_32(y)|hi_32(|y|) + je .zero + + fldl 12(%esp) / load arg y + fldl 4(%esp) / load arg x +.mod_loop: + fprem / partial fmod + fstsw %ax / store status word + andw $0x400,%ax / check for incomplete reduction + jne .mod_loop / while incomplete, do fprem again + fstp %st(1) + ret +.zero: + pushl %ebp + movl %esp,%ebp + PIC_SETUP(1) + pushl $27 / case 27 in _SVID_libm_err + pushl 20(%ebp) / pass x + pushl 16(%ebp) + pushl 12(%ebp) / pass y + pushl 8(%ebp) + call PIC_F(_SVID_libm_err) + addl $20,%esp + PIC_WRAPUP + leave + ret + .align 4 + SET_SIZE(fmod) diff --git a/usr/src/lib/libm/i386/src/fmodf.s b/usr/src/lib/libm/i386/src/fmodf.s new file mode 100644 index 0000000000..b4dbe3053c --- /dev/null +++ b/usr/src/lib/libm/i386/src/fmodf.s @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "fmodf.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(fmodf,function) +#include "libm_synonyms.h" + + ENTRY(fmodf) + flds 8(%esp) / load arg y + flds 4(%esp) / load arg x +.mod_loop: + fprem / partial fmod + fstsw %ax / store status word + andw $0x400,%ax / check for incomplete reduction + jne .mod_loop / while incomplete, do fprem again + fstp %st(1) + ret + .align 4 + SET_SIZE(fmodf) diff --git a/usr/src/lib/libm/i386/src/fmodl.s b/usr/src/lib/libm/i386/src/fmodl.s new file mode 100644 index 0000000000..c4c5849e4b --- /dev/null +++ b/usr/src/lib/libm/i386/src/fmodl.s @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "fmodl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(fmodl,function) +#include "libm_synonyms.h" + + ENTRY(fmodl) + fldt 16(%esp) / load arg y + fldt 4(%esp) / load arg x +.mod_loop: + fprem / partial fmod + fstsw %ax / store status word + andw $0x400,%ax / check for incomplete reduction + jne .mod_loop / while incomplete, do fprem again + fstp %st(1) + ret + .align 4 + SET_SIZE(fmodl) diff --git a/usr/src/lib/libm/i386/src/hypot.s b/usr/src/lib/libm/i386/src/hypot.s new file mode 100644 index 0000000000..0687a9f4fe --- /dev/null +++ b/usr/src/lib/libm/i386/src/hypot.s @@ -0,0 +1,138 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "hypot.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(hypot,function) +#include "libm_synonyms.h" +#include "libm_protos.h" + +#undef fabs + + .data + .align 4 +inf: + .long 0x7f800000 + + ENTRY(hypot) + movl 8(%esp),%eax / eax <-- hi_32(x) + andl $0x7fffffff,%eax / eax <-- hi_32(|x|) + jz .x_maybe_0 / if x = +/-0, return |y| + subl $0x7ff00000,%eax / eax <-- hi_32(|x|) - hi_32(INF) + jz .x_maybe_inf +.check_y: + movl 16(%esp),%eax / eax <-- hi_32(y) + andl $0x7fffffff,%eax / eax <-- hi_32(|y|) + jz .y_maybe_0 / if y = +/-0, return |x| + subl $0x7ff00000,%eax / eax <-- hi_32(|y|) - hi_32(INF) + jz .y_maybe_inf +.do_hypot: + fldl 12(%esp) / ,y + fmul %st(0),%st / ,y*y + fldl 4(%esp) / x,y*y + fmul %st(0),%st / x*x,y*y + faddp %st,%st(1) / x*x+y*y + fsqrt / sqrt(x*x+y*y) + subl $8,%esp + fstpl (%esp) / round to double + fldl (%esp) / sqrt(x*x+y*y) rounded to double + PIC_SETUP(1) + flds PIC_L(inf) / inf , sqrt(x*x+y*y) + PIC_WRAPUP + addl $8,%esp + fucomp + fstsw %ax / store status in %ax + sahf / 80387 flags in %ah to 80386 flags + jz .maybe_ovflw + ret + +.maybe_ovflw: + jnp .ovflw + ret + +.ovflw: + / overflow occurred + fstp %st(0) / stack empty + pushl %ebp + movl %esp,%ebp + PIC_SETUP(2) + pushl $4 + pushl 20(%ebp) / high y + pushl 16(%ebp) / low y + pushl 12(%ebp) / high x + pushl 8(%ebp) / low x + call PIC_F(_SVID_libm_err) + addl $20,%esp + PIC_WRAPUP + leave + ret + +.x_maybe_0: + movl 4(%esp),%ecx / ecx <-- lo_32(x) + orl %ecx,%eax / is x = +/-0? + jnz .check_y / branch if x is denormal + / x = +/-0, so return |y| + fldl 12(%esp) + fabs + ret + +.x_maybe_inf: + movl 4(%esp),%ecx / ecx <-- lo_32(x) + orl %ecx,%eax / is x = +/-INF? + jnz .check_y / branch if x is NaN + / push&pop y in case y is a SNaN + fldl 12(%esp) + fstp %st(0) + / x = +/-INF, so return |x| + fldl 4(%esp) + fabs + ret + +.y_maybe_0: + movl 12(%esp),%ecx / ecx <-- lo_32(y) + orl %ecx,%eax / is y = +/-0? + jnz .do_hypot / branch if y is denormal + / y = +/-0, so return |x| + fldl 4(%esp) + fabs + ret + +.y_maybe_inf: + movl 12(%esp),%ecx / ecx <-- lo_32(y) + orl %ecx,%eax / is y = +/-INF? + jnz .do_hypot / branch if y is NaN + / push&pop x in case x is a SNaN + fldl 4(%esp) + fstp %st(0) + / y = +/-INF, so return |y| + fldl 12(%esp) + fabs + ret + .align 4 + SET_SIZE(hypot) diff --git a/usr/src/lib/libm/i386/src/hypotf.s b/usr/src/lib/libm/i386/src/hypotf.s new file mode 100644 index 0000000000..068b75ea87 --- /dev/null +++ b/usr/src/lib/libm/i386/src/hypotf.s @@ -0,0 +1,70 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "hypotf.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(hypotf,function) +#include "libm_synonyms.h" +#include "libm_protos.h" + +#undef fabs + + ENTRY(hypotf) + movl 4(%esp),%eax / eax <-- x + andl $0x7fffffff,%eax / eax <-- |x| + jz .return_abs_y / if x = +/-0, return |y| + subl $0x7f800000,%eax / eax <-- |x| - INF + jz .return_abs_x / if x = +/-INF, return |x| + movl 8(%esp),%eax / eax <-- y + andl $0x7fffffff,%eax / eax <-- |y| + jz .return_abs_x / if y = +/-0, return |x| + subl $0x7f800000,%eax / eax <-- |y| - INF +.return_abs_y: + flds 8(%esp) / y + jz .take_abs / if y = +/-INF, return |y| + fmul %st(0),%st / y*y + flds 4(%esp) / x,y*y + fmul %st(0),%st / x*x,y*y + faddp %st,%st(1) / x*x+y*y + fsqrt / sqrt(x*x+y*y) + subl $4,%esp + fstps (%esp) / round to single + flds (%esp) + fwait + addl $4,%esp + ret + +.return_abs_x: + / returns |x| + flds 4(%esp) +.take_abs: + fabs + ret + .align 4 + SET_SIZE(hypotf) diff --git a/usr/src/lib/libm/i386/src/ieee_funcl.s b/usr/src/lib/libm/i386/src/ieee_funcl.s new file mode 100644 index 0000000000..60a22178e1 --- /dev/null +++ b/usr/src/lib/libm/i386/src/ieee_funcl.s @@ -0,0 +1,122 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "ieee_funcl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(isinfl,function) +LIBM_ANSI_PRAGMA_WEAK(isnormall,function) +LIBM_ANSI_PRAGMA_WEAK(issubnormall,function) +LIBM_ANSI_PRAGMA_WEAK(iszerol,function) +LIBM_ANSI_PRAGMA_WEAK(signbitl,function) +#include "libm_synonyms.h" + + ENTRY(isinfl) + movl 12(%esp),%eax / ax <-- sign and bexp of x + notl %eax + andl $0x00007fff,%eax + jz .L6 + movl $0,%eax +.not_inf: + ret + +.L6: / here, (eax) = 0.0 + movl 8(%esp),%ecx + xorl $0x80000000,%ecx / handle unsupported implicitly + orl 4(%esp), %ecx + jnz .not_inf + movl $1,%eax + ret + .align 4 + SET_SIZE(isinfl) + + ENTRY(isnormall) + / TRUE iff (x is finite, but + / neither subnormal nor zero) + / iff (msb(sgnfcnd(x) /= 0 + / & 0 < bexp(x) < 0x7fff) + movl 8(%esp),%eax / eax <-- hi_32(sgnfcnd(x)) + andl $0x80000000,%eax / eax[31] <-- msb(sgnfcnd(x)), + / rest_of(eax) <-- 0 + jz .L8 / jump iff msb(sgnfcnd(x)) = 0 + movl 12(%esp),%eax / ax <-- sign and bexp of x + notl %eax / ax[0..14] <-- not(bexp(x)) + andl $0x00007fff,%eax / eax <-- zero_xtnd(not(bexp(x))) + jz .L8 / jump iff bexp(x) = 0x7fff or 0 + xorl $0x00007fff,%eax / treat pseudo-denormal as subnormal + jz .L8 + movl $1,%eax +.L8: + ret + .align 4 + SET_SIZE(isnormall) + + ENTRY(issubnormall) + / TRUE iff (bexp(x) = 0 & + / msb(sgnfcnd(x)) = 0 & frac(x) /= 0) + movl 8(%esp),%eax / eax <-- hi_32(sgnfcnd(x)) + testl $0x80000000,%eax / eax[31] = msb(sgnfcnd(x)); + / set ZF if it's 0. + jz .may_be_subnorm / jump iff msb(sgnfcnd(x)) = 0 +.not_subnorm: + movl $0,%eax +.quicker_out: + ret +.may_be_subnorm: + testl $0x00007fff,12(%esp) / set ZF iff bexp(x) = 0 + jnz .not_subnorm / jump iff bexp(x) /= 0 + orl 4(%esp),%eax / (eax) = 0 iff sgnfcnd(x) = 0 + jz .quicker_out + movl $1,%eax + ret + .align 4 + SET_SIZE(issubnormall) + + ENTRY(iszerol) + movl 12(%esp),%eax / ax <-- sign and bexp of x + andl $0x00007fff,%eax / eax <-- zero_xtnd(bexp(x)) + jz .may_be_zero / jump iff bexp(x) = 0 +.not_zero: + movl $0,%eax + ret +.may_be_zero: / here, (eax) = 0 + orl 8(%esp),%eax / is hi_32(sgnfcnd(x)) = 0? + jnz .not_zero / jump iff hi_32(sgnfcnd(x)) /= 0 + orl 4(%esp),%eax / is lo_32(sgnfcnd(x)) = 0? + jnz .not_zero / jump iff lo_32(sgnfcnd(x)) /= 0 + movl $1,%eax + ret + .align 4 + SET_SIZE(iszerol) + + ENTRY(signbitl) + movl 10(%esp),%eax / eax[31] <-- sign_bit(x) + shrl $31,%eax / eax <-- zero_xtnd(sign_bit(x)) + ret + .align 4 + SET_SIZE(signbitl) diff --git a/usr/src/lib/libm/i386/src/ilogb.s b/usr/src/lib/libm/i386/src/ilogb.s new file mode 100644 index 0000000000..6d4215fb03 --- /dev/null +++ b/usr/src/lib/libm/i386/src/ilogb.s @@ -0,0 +1,86 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "ilogb.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(ilogb,function) +#include "libm_synonyms.h" +#include "xpg6.h" + + .data + .align 8 +two52: .long 0x0,0x43300000 / 2**52 + + ENTRY(ilogb) + movl 8(%esp),%eax / eax <-- hi_32(x) + andl $0x7fffffff,%eax / eax <-- hi_32(abs(x)) + testl $0x7ff00000,%eax / is bexp(x) 0? + jz .bexp_0 / jump if x is 0 or subnormal + / biased exponent is non-zero + cmpl $0x7ff00000,%eax / is bexp(x) 0x7ff? + jae .bexp_all_1 / jump if x is NaN or Inf + shrl $20,%eax / eax <-- bexp(x) + subl $1023,%eax / unbias exponent by 1023 + ret + +.bexp_all_1: + movl $0x7fffffff,%eax / x is NaN or inf, so return 0x7fffffff + jmp 0f + +.bexp_0: + orl 4(%esp),%eax / test whether x is 0 + jnz .ilogb_subnorm + movl $0x80000001,%eax / x is +/-0, so return 0x80000001 +0: + PIC_SETUP(0) + PIC_G_LOAD(movzwl,__xpg6,ecx) + PIC_WRAPUP + andl $_C99SUSv3_ilogb_0InfNaN_raises_invalid,%ecx + cmpl $0,%ecx + je 1f + fldz + fdivp %st,%st(0) / raise invalid as per SUSv3 +1: + ret + +.ilogb_subnorm: / subnormal input + fldl 4(%esp) / push x + PIC_SETUP(1) + fmull PIC_L(two52) / x*2**52 + PIC_WRAPUP + subl $8,%esp / set up storage area + fstpl (%esp) / store x*2**52 in storage are + movl $0x7ff00000,%eax + andl 4(%esp),%eax + shrl $20,%eax / extract exponent of x*2**52 + subl $1075,%eax / unbias it by 1075 (= 1023 + 52) + addl $8,%esp + ret + .align 4 + SET_SIZE(ilogb) diff --git a/usr/src/lib/libm/i386/src/ilogbf.s b/usr/src/lib/libm/i386/src/ilogbf.s new file mode 100644 index 0000000000..927c4e9943 --- /dev/null +++ b/usr/src/lib/libm/i386/src/ilogbf.s @@ -0,0 +1,91 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "ilogbf.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(ilogbf,function) +#include "libm_synonyms.h" +#include "xpg6.h" + + .data + .align 8 +two23: .long 0x4b000000 / 2**23 + + ENTRY(ilogbf) + movl 4(%esp),%eax / eax <-- x + testl $0x7f800000,%eax / is bexp(x) 0? + jz .bexp_0 / jump if x is 0 or subnormal + / here, biased exponent is non-zero + andl $0x7fffffff,%eax / eax <-- abs(x) + cmpl $0x7f800000,%eax / is bexp(x) 0xff? + jae .bexp_all_1 / jump if x is NaN or Inf + shrl $23,%eax / eax <-- zero_xtnd(bexp(x)) + subl $127,%eax / unbias exponent by 127 + ret + +.bexp_all_1: + movl $0x7fffffff,%eax / x is NaN or inf, so return 0x7fffffff + jmp 0f + +.bexp_0: + andl $0x7fffffff,%eax / eax <-- abs(x), and + / ZF = 1 iff x = 0.0 + jnz .ilogb_subnorm + movl $0x80000001,%eax / x is +/-0, so return 0x80000001 +0: + PIC_SETUP(0) + PIC_G_LOAD(movzwl,__xpg6,ecx) + PIC_WRAPUP + andl $_C99SUSv3_ilogb_0InfNaN_raises_invalid,%ecx + cmpl $0,%ecx + je 1f + fldz + fdivp %st,%st(0) / raise invalid as per SUSv3 +1: + ret + +.ilogb_subnorm: / subnormal input + flds 4(%esp) / push x + PIC_SETUP(1) + fmuls PIC_L(two23) / x*2**23; rebias x by 127+23, + / instead of 127 + PIC_WRAPUP + subl $4,%esp / set up storage area + fstps (%esp) / store x*2**23 in storage area + fwait / (shouldn't raise exception, but + / just in case) + movl $0x7f800000,%eax / eax <-- single_bexp_mask + andl (%esp),%eax / eax[23..30] <-- bexp(x*2**23), + / rest_of(eax) <-- 0 + shrl $23,%eax / eax <-- zero_xtnd(bexp(x*2**23)) + subl $150,%eax / unbias rebiased x by 150 (= 127 + 23) + addl $4,%esp / restore stack for caller + ret + .align 4 + SET_SIZE(ilogbf) diff --git a/usr/src/lib/libm/i386/src/ilogbl.s b/usr/src/lib/libm/i386/src/ilogbl.s new file mode 100644 index 0000000000..d2a6c0160b --- /dev/null +++ b/usr/src/lib/libm/i386/src/ilogbl.s @@ -0,0 +1,87 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "ilogbl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(ilogbl,function) +#include "libm_synonyms.h" +#include "xpg6.h" + + .data + .align 8 +two63: .long 0x0,0x43d00000 / 2**63 + + ENTRY(ilogbl) + movl 12(%esp),%eax / eax <-- sign and bexp of x + andl $0x00007fff,%eax / eax <-- bexp(x) + jz .bexp_0 / jump iff x is 0 or subnormal + / here, biased exponent is non-zero + testl $0x80000000,8(%esp) / test msb of hi_32(sgnfcnd(x)) + jz .ilogbl_not_finite / jump if unsupported format + cmpl $0x00007fff,%eax + je .ilogbl_not_finite + subl $16383,%eax / unbias exponent by 16383 = 0x3fff + ret + +.ilogbl_not_finite: + movl $0x7fffffff,%eax / x is NaN/inf/unsup + jmp 0f + +.bexp_0: + movl 8(%esp),%eax / eax <-- hi_32(sgnfcnd(x)) + orl 4(%esp),%eax / test whether x is 0 + jnz .ilogbl_subnorm / jump iff x is subnormal + movl $0x80000001,%eax / x is +/-0, so return 0x80000001 +0: + PIC_SETUP(0) + PIC_G_LOAD(movzwl,__xpg6,ecx) + PIC_WRAPUP + andl $_C99SUSv3_ilogb_0InfNaN_raises_invalid,%ecx + cmpl $0,%ecx + je 1f + fldz + fdivp %st,%st(0) / raise invalid as per SUSv3 +1: + ret + + +.ilogbl_subnorm: / subnormal or pseudo-denormal input + fldt 4(%esp) / push x, setting D-flag + PIC_SETUP(1) + fmull PIC_L(two63) / x*2**63 + PIC_WRAPUP + subl $12,%esp + fstpt (%esp) + movl $0x00007fff,%eax + andl 8(%esp),%eax / eax <-- sign and bexp of x*2**63 + subl $16445,%eax / unbias it by (16,383 + 63) + addl $12,%esp + ret + .align 4 + SET_SIZE(ilogbl) diff --git a/usr/src/lib/libm/i386/src/isnan.s b/usr/src/lib/libm/i386/src/isnan.s new file mode 100644 index 0000000000..1f343862b3 --- /dev/null +++ b/usr/src/lib/libm/i386/src/isnan.s @@ -0,0 +1,64 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "isnan.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(isnan,function) + .weak _isnan + .type _isnan,@function +_isnan = __isnan + .weak _isnand + .type _isnand,@function +_isnand = __isnan + .weak isnand + .type isnand,@function +isnand = __isnan +#include "libm_synonyms.h" + + ENTRY(isnan) + movl 8(%esp),%eax / eax <-- hi_32(x) + andl $0x7fffffff,%eax / eax <-- hi_32(abs(x)) + subl $0x7ff00000,%eax / weed out finite values + jae .nan_or_inf / no jump if arg. is finite + movl $0,%eax / ansi needs (eax) = 0 + ret +.nan_or_inf: + ja .got_nan / no jump if arg. may be infinite; + / let nan waste time + / (eax) = 0 here + testl $0xffffffff,4(%esp) / ZF <-- 1 iff lo_frac. = 0 + / iff arg. is infinite + jnz .got_nan / no jump if arg. is infinite; + ret +.got_nan: + movl $1,%eax / %eax was 0, must be made 1 to + / indicate TRUE + ret + .align 4 + SET_SIZE(isnan) diff --git a/usr/src/lib/libm/i386/src/isnanf.s b/usr/src/lib/libm/i386/src/isnanf.s new file mode 100644 index 0000000000..d2316ed50d --- /dev/null +++ b/usr/src/lib/libm/i386/src/isnanf.s @@ -0,0 +1,55 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "isnanf.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(isnanf,function) + .weak _isnanf + .type _isnanf,@function +_isnanf = __isnanf +#include "libm_synonyms.h" + + ENTRY(isnanf) + movl 4(%esp),%eax / eax <-- x + andl $0x7fffffff,%eax / eax <-- abs(x) + subl $0x7f800000,%eax / ZF <-- 1 iff x is infinite + jae .nan_or_inf / no jump iff arg. is finite + movl $0,%eax + ret +.nan_or_inf: + jnz .got_nan / no jump if arg. infinite; + / let nan waste time + ret / %eax = 0 here +.got_nan: + movl $1,%eax / %eax was 0, must be made 1 to + / indicate TRUE + ret + .align 4 + SET_SIZE(isnanf) + diff --git a/usr/src/lib/libm/i386/src/isnanl.s b/usr/src/lib/libm/i386/src/isnanl.s new file mode 100644 index 0000000000..00374c8198 --- /dev/null +++ b/usr/src/lib/libm/i386/src/isnanl.s @@ -0,0 +1,56 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "isnanl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(isnanl,function) +#include "libm_synonyms.h" + + ENTRY(isnanl) + movl 12(%esp),%eax / ax <-- sign bit and exp + andl $0x00007fff,%eax + jz .not_nan / jump if exp is all 0 + xorl $0x00007fff,%eax + jz .nan_or_inf / jump if exp is all 1 + testl $0x80000000,8(%esp) + jz .got_nan / jump if leading bit is 0 + movl $0,%eax +.not_nan: + ret +.nan_or_inf: / note that %eax = 0 from before + cmpl $0x80000000,8(%esp) / what is first half of significand? + jnz .got_nan / jump if not equal to 0x80000000 + testl $0xffffffff,4(%esp) / is second half of significand 0? + jnz .got_nan / jump if not equal to 0 + ret +.got_nan: + movl $1,%eax + ret + .align 4 + SET_SIZE(isnanl) diff --git a/usr/src/lib/libm/i386/src/libm_inlines.h b/usr/src/lib/libm/i386/src/libm_inlines.h new file mode 100644 index 0000000000..e57ecbaded --- /dev/null +++ b/usr/src/lib/libm/i386/src/libm_inlines.h @@ -0,0 +1,351 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * Copyright 2011, Richard Lowe + */ + +/* Functions in this file are duplicated in locallibm.il. Keep them in sync */ + +#ifndef _LIBM_INLINES_H +#define _LIBM_INLINES_H + +#ifdef __GNUC__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <sys/types.h> +#include <sys/ieeefp.h> + +#define _LO_WORD(x) ((uint32_t *)&x)[0] +#define _HI_WORD(x) ((uint32_t *)&x)[1] +#define _HIER_WORD(x) ((uint32_t *)&x)[2] + +extern __inline__ double +__inline_sqrt(double a) +{ + double ret; + + __asm__ __volatile__("fsqrt\n\t" : "=t" (ret) : "0" (a) : "cc"); + return (ret); +} + +extern __inline__ double +__ieee754_sqrt(double a) +{ + return (__inline_sqrt(a)); +} + +extern __inline__ float +__inline_sqrtf(float a) +{ + float ret; + + __asm__ __volatile__("fsqrt\n\t" : "=t" (ret) : "0" (a) : "cc"); + return (ret); +} + +extern __inline__ double +__inline_rint(double a) +{ + __asm__ __volatile__( + "andl $0x7fffffff,%1\n\t" + "cmpl $0x43300000,%1\n\t" + "jae 1f\n\t" + "frndint\n\t" + "1: fwait\n\t" + : "+t" (a), "+&r" (_HI_WORD(a)) + : + : "cc"); + + return (a); +} + +/* + * 00 - 24 bits + * 01 - reserved + * 10 - 53 bits + * 11 - 64 bits + */ +extern __inline__ int +__swapRP(int i) +{ + int ret; + uint16_t cw; + + __asm__ __volatile__("fstcw %0\n\t" : "=m" (cw)); + + ret = (cw >> 8) & 0x3; + cw = (cw & 0xfcff) | ((i & 0x3) << 8); + + __asm__ __volatile__("fldcw %0\n\t" : : "m" (cw)); + + return (ret); +} + +/* + * 00 - Round to nearest, with even preferred + * 01 - Round down + * 10 - Round up + * 11 - Chop + */ +extern __inline__ enum fp_direction_type +__swap87RD(enum fp_direction_type i) +{ + int ret; + uint16_t cw; + + __asm__ __volatile__("fstcw %0\n\t" : "=m" (cw)); + + ret = (cw >> 10) & 0x3; + cw = (cw & 0xf3ff) | ((i & 0x3) << 10); + + __asm__ __volatile__("fldcw %0\n\t" : : "m" (cw)); + + return (ret); +} + +extern __inline__ double +ceil(double d) +{ + /* + * Let's set a Rounding Control (RC) bits from x87 FPU Control Word + * to fp_positive and save old bits in rd. + */ + short rd = __swap87RD(fp_positive); + + /* + * The FRNDINT instruction returns a floating-point value that is the + * integral value closest to the source value in the direction of the + * rounding mode specified in the RC field of the x87 FPU control word. + * + * Rounds the source value in the ST(0) register to the nearest + * integral value, depending on the current rounding mode + * (setting of the RC field of the FPU control word), + * and stores the result in ST(0). + */ + __asm__ __volatile__("frndint" : "+t" (d) : : "cc"); + + /* restore old RC bits */ + __swap87RD(rd); + + return (d); +} + +extern __inline__ double +copysign(double d1, double d2) +{ + __asm__ __volatile__( + "andl $0x7fffffff,%0\n\t" /* %0 <-- hi_32(abs(d)) */ + "andl $0x80000000,%1\n\t" /* %1[31] <-- sign_bit(d2) */ + "orl %1,%0\n\t" /* %0 <-- hi_32(copysign(x,y)) */ + : "+&r" (_HI_WORD(d1)), "+r" (_HI_WORD(d2)) + : + : "cc"); + + return (d1); +} + +extern __inline__ double +fabs(double d) +{ + __asm__ __volatile__("fabs\n\t" : "+t" (d) : : "cc"); + return (d); +} + +extern __inline__ float +fabsf(float d) +{ + __asm__ __volatile__("fabs\n\t" : "+t" (d) : : "cc"); + return (d); +} + +extern __inline__ long double +fabsl(long double d) +{ + __asm__ __volatile__("fabs\n\t" : "+t" (d) : : "cc"); + return (d); +} + +extern __inline__ int +finite(double d) +{ + int ret = _HI_WORD(d); + + __asm__ __volatile__( + "notl %0\n\t" + "andl $0x7ff00000,%0\n\t" + "negl %0\n\t" + "shrl $31,%0\n\t" + : "+r" (ret) + : + : "cc"); + return (ret); +} + +extern __inline__ double +floor(double d) +{ + short rd = __swap87RD(fp_negative); + + __asm__ __volatile__("frndint" : "+t" (d), "+r" (rd) : : "cc"); + __swap87RD(rd); + + return (d); +} + +/* + * branchless __isnan + * ((0x7ff00000-[((lx|-lx)>>31)&1]|ahx)>>31)&1 = 1 iff x is NaN + */ +extern __inline__ int +isnan(double d) +{ + int ret; + + __asm__ __volatile__( + "movl %1,%%ecx\n\t" + "negl %%ecx\n\t" /* ecx <-- -lo_32(x) */ + "orl %%ecx,%1\n\t" + "shrl $31,%1\n\t" /* 1 iff lx != 0 */ + "andl $0x7fffffff,%2\n\t" /* ecx <-- hi_32(abs(x)) */ + "orl %2,%1\n\t" + "subl $0x7ff00000,%1\n\t" + "negl %1\n\t" + "shrl $31,%1\n\t" + : "=r" (ret) + : "0" (_HI_WORD(d)), "r" (_LO_WORD(d)) + : "ecx"); + + return (ret); +} + +extern __inline__ int +isnanf(float f) +{ + __asm__ __volatile__( + "andl $0x7fffffff,%0\n\t" + "negl %0\n\t" + "addl $0x7f800000,%0\n\t" + "shrl $31,%0\n\t" + : "+r" (f) + : + : "cc"); + + return (f); +} + +extern __inline__ double +rint(double a) { + return (__inline_rint(a)); +} + +extern __inline__ double +scalbn(double d, int n) +{ + double dummy; + + __asm__ __volatile__( + "fildl %2\n\t" /* Convert N to extended */ + "fxch\n\t" + "fscale\n\t" + : "+t" (d), "=u" (dummy) + : "m" (n) + : "cc"); + + return (d); +} + +extern __inline__ int +signbit(double d) +{ + return (_HI_WORD(d) >> 31); +} + +extern __inline__ int +signbitf(float f) +{ + return ((*(uint32_t *)&f) >> 31); +} + +extern __inline__ double +sqrt(double d) +{ + return (__inline_sqrt(d)); +} + +extern __inline__ float +sqrtf(float f) +{ + return (__inline_sqrtf(f)); +} + +extern __inline__ long double +sqrtl(long double ld) +{ + __asm__ __volatile__("fsqrt" : "+t" (ld) : : "cc"); + return (ld); +} + +extern __inline__ int +isnanl(long double ld) +{ + int ret = _HIER_WORD(ld); + + __asm__ __volatile__( + "andl $0x00007fff,%0\n\t" + "jz 1f\n\t" /* jump if exp is all 0 */ + "xorl $0x00007fff,%0\n\t" + "jz 2f\n\t" /* jump if exp is all 1 */ + "testl $0x80000000,%1\n\t" + "jz 3f\n\t" /* jump if leading bit is 0 */ + "xorl %0,%0\n\t" + "jmp 1f\n\t" + "2:\n\t" /* note that %0 = 0 from before */ + "cmpl $0x80000000,%1\n\t" /* what is first half of significand? */ + "jnz 3f\n\t" /* jump if not equal to 0x80000000 */ + "testl $0xffffffff,%2\n\t" /* is second half of significand 0? */ + "jnz 3f\n\t" /* jump if not equal to 0 */ + "jmp 1f\n\t" + "3:\n\t" + "movl $1,%0\n\t" + "1:\n\t" + : "+&r" (ret) + : "r" (_HI_WORD(ld)), "r" (_LO_WORD(ld)) + : "cc"); + + return (ret); +} + +#ifdef __cplusplus +} +#endif + +#endif /* __GNUC__ */ + +#endif /* _LIBM_INLINES_H */ diff --git a/usr/src/lib/libm/i386/src/llrint.s b/usr/src/lib/libm/i386/src/llrint.s new file mode 100644 index 0000000000..c3c27f9c83 --- /dev/null +++ b/usr/src/lib/libm/i386/src/llrint.s @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "llrint.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(llrint,function) +#include "libm_synonyms.h" + + ENTRY(llrint) + movl %esp,%ecx + subl $8,%esp + fldl 4(%ecx) / load x + fistpll -8(%ecx) / [x] + fwait + movl -8(%ecx),%eax + movl -4(%ecx),%edx + addl $8,%esp + ret + .align 4 + SET_SIZE(llrint) diff --git a/usr/src/lib/libm/i386/src/llrintf.s b/usr/src/lib/libm/i386/src/llrintf.s new file mode 100644 index 0000000000..e4656cbbd0 --- /dev/null +++ b/usr/src/lib/libm/i386/src/llrintf.s @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "llrintf.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(llrintf,function) +#include "libm_synonyms.h" + + ENTRY(llrintf) + movl %esp,%ecx + subl $8,%esp + flds 4(%ecx) / load x + fistpll -8(%ecx) / [x] + fwait + movl -8(%ecx),%eax + movl -4(%ecx),%edx + addl $8,%esp + ret + .align 4 + SET_SIZE(llrintf) diff --git a/usr/src/lib/libm/i386/src/llrintl.s b/usr/src/lib/libm/i386/src/llrintl.s new file mode 100644 index 0000000000..500fc472ca --- /dev/null +++ b/usr/src/lib/libm/i386/src/llrintl.s @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "llrintl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(llrintl,function) +#include "libm_synonyms.h" + + ENTRY(llrintl) + movl %esp,%ecx + subl $8,%esp + fldt 4(%ecx) / load x + fistpll -8(%ecx) / [x] + fwait + movl -8(%ecx),%eax + movl -4(%ecx),%edx + addl $8,%esp + ret + .align 4 + SET_SIZE(llrintl) diff --git a/usr/src/lib/libm/i386/src/locallibm.il b/usr/src/lib/libm/i386/src/locallibm.il new file mode 100644 index 0000000000..ca79724f86 --- /dev/null +++ b/usr/src/lib/libm/i386/src/locallibm.il @@ -0,0 +1,370 @@ +/ +/ CDDL HEADER START +/ +/ The contents of this file are subject to the terms of the +/ Common Development and Distribution License (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, this CDDL HEADER in each +/ file and 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 2011 Nexenta Systems, Inc. All rights reserved. +/ +/ Copyright 2006 Sun Microsystems, Inc. All rights reserved. +/ Use is subject to license terms. +/ + +/ Portions of this file are duplicated as GCC inline assembly in +/ libm_inlines.h. Keep them in sync. + + .inline __ieee754_sqrt,0 + fldl (%esp) + fsqrt + .end + + .inline __inline_rint,0 + fldl (%esp) + movl 4(%esp),%eax + andl $0x7fffffff,%eax + cmpl $0x43300000,%eax + jae 1f + frndint +1: + fwait / in case we jumped around the frndint + .end + + .inline __inline_sqrtf,0 + flds (%esp) + fsqrt + .end + + .inline __inline_sqrt,0 + fldl (%esp) + fsqrt + .end + + .inline __inline_fstsw,0 + fstsw %ax + .end + +/ +/ 00 - 24 bits +/ 01 - reserved +/ 10 - 53 bits +/ 11 - 64 bits +/ + .inline __swapRP,0 + subl $4,%esp + fstcw (%esp) + movw (%esp),%ax + movw %ax,%cx + andw $0xfcff,%cx + movl 4(%esp),%edx /// + andl $0x3,%edx + shlw $8,%dx + orw %dx,%cx + movl %ecx,(%esp) + fldcw (%esp) + shrw $8,%ax + andl $0x3,%eax + addl $4,%esp + .end + +/ +/ 00 - Round to nearest, with even preferred +/ 01 - Round down +/ 10 - Round up +/ 11 - Chop +/ + .inline __swap87RD,0 + subl $4,%esp + fstcw (%esp) + movw (%esp),%ax + movw %ax,%cx + andw $0xf3ff,%cx + movl 4(%esp),%edx + andl $0x3,%edx + shlw $10,%dx + orw %dx,%cx + movl %ecx,(%esp) + fldcw (%esp) + shrw $10,%ax + andl $0x3,%eax + addl $4,%esp + .end + +/ +/ Convert Top-of-Stack to long +/ + .inline __xtol,0 + subl $8,%esp / 8 bytes of stack space + fstcw 2(%esp) / byte[2:3] = old_cw + movw 2(%esp),%ax + andw $0xf3ff,%ax + orw $0x0c00,%ax / RD set to Chop + movw %ax,(%esp) / byte[0:1] = new_cw + fldcw (%esp) / set new_cw + fistpl 4(%esp) / byte[4:7] = converted long + fstcw (%esp) / restore old RD + movw (%esp),%ax + andw $0xf3ff,%ax + movw 2(%esp),%dx + andw $0x0c00,%dx + orw %ax,%dx + movw %dx,2(%esp) + fldcw 2(%esp) + movl 4(%esp),%eax + addl $8,%esp + .end + + .inline __ceil,0 + subl $8,%esp + fstcw (%esp) + fldl 8(%esp) /// + movw (%esp),%cx + orw $0x0c00,%cx + xorw $0x0400,%cx + movw %cx,4(%esp) + fldcw 4(%esp) / set RD = up + frndint + fstcw 4(%esp) / restore RD + movw 4(%esp),%dx + andw $0xf3ff,%dx + movw (%esp),%cx + andw $0x0c00,%cx + orw %dx,%cx + movw %cx,(%esp) + fldcw (%esp) + addl $8,%esp + .end + + .inline __copysign,0 + movl 4(%esp),%eax /// eax <-- hi_32(x) + movl 12(%esp),%ecx /// ecx <-- hi_32(y) + andl $0x7fffffff,%eax / eax <-- hi_32(abs(x)) + andl $0x80000000,%ecx / ecx[31] <-- sign_bit(y) + orl %ecx,%eax / eax <-- hi_32(__copysign(x,y)) + movl (%esp),%ecx /// ecx <-- lo_32(x) + / = lo_32(__copysign(x,y)) + subl $8,%esp / set up loading dock for result + movl %ecx,(%esp) / copy lo_32(result) to loading dock + movl %eax,4(%esp) / copy hi_32(result) to loading dock + fldl (%esp) / load __copysign(x,y) + fwait / in case fldl causes exception + addl $8,%esp / restore stack-pointer + .end + + .inline __d_sqrt_,0 + movl (%esp),%eax + fldl (%eax) + fsqrt + .end + + .inline __fabs,0 + fldl (%esp) /// + fabs + .end + + .inline __fabsf,0 + flds (%esp) + fabs + .end + + .inline __fabsl,0 + fldt (%esp) + fabs + .end + +/ +/ branchless _finite +/ + .inline _finite,0 + movl 4(%esp),%eax /// eax <-- hi_32(x) + notl %eax / not(bexp) = 0 iff bexp = all 1's + andl $0x7ff00000,%eax + negl %eax + shrl $31,%eax + .end + + .inline __floor,0 + subl $8,%esp + fstcw (%esp) + fldl 8(%esp) /// + movw (%esp),%cx + orw $0x0c00,%cx + xorw $0x0800,%cx + movw %cx,4(%esp) + fldcw 4(%esp) / set RD = down + frndint + fstcw 4(%esp) / restore RD + movw 4(%esp),%dx + andw $0xf3ff,%dx + movw (%esp),%cx + andw $0x0c00,%cx + orw %dx,%cx + movw %cx,(%esp) + fldcw (%esp) / restore RD + addl $8,%esp + .end + + .inline __isnanf,0 + movl (%esp),%eax + andl $0x7fffffff,%eax + negl %eax + addl $0x7f800000,%eax + shrl $31,%eax + .end + + + .inline __isnormal,0 + / TRUE iff (x is _finite, but + / neither subnormal nor +/-0) + / iff (0 < bexp(x) < 0x7ff) + movl 4(%esp),%eax / eax <-- hi_32(x) + andl $0x7ff00000,%eax / eax[20..30] <-- bexp(x), + / rest_of(eax) <-- 0 + pushfl + popl %ecx / bit 6 of ecx <-- not bexp(x) + subl $0x7ff00000,%eax + pushfl + popl %eax / bit 6 of eax <-- not bexp(x) + orl %ecx,%eax + andl $0x40,%eax + xorl $0x40,%eax + shrl $6,%eax + .end + + .inline __issubnormal,0 + / TRUE iff (bexp(x) = 0 and + / frac(x) /= 0) + movl $0,%eax + movl 4(%esp),%ecx / ecx <-- hi_32(x) + andl $0x7fffffff,%ecx / ecx <-- hi_32(abs(x)) + cmpl $0x00100000,%ecx / is bexp(x) = 0? + adcl $0,%eax / jump if bexp(x) = 0 + orl (%esp),%ecx / = 0 iff sgnfcnd(x) = 0 + / iff x = +/- 0.0 here + pushfl + popl %ecx + andl $0x40,%ecx + xorl $0x40,%ecx + shrl $6,%ecx + andl %ecx,%eax + .end + + .inline __iszero,0 + movl 4(%esp),%eax / eax <-- hi_32(x) + andl $0x7fffffff,%eax / eax <-- hi_32(abs(x)) + orl (%esp),%eax / = 0 iff x = +/- 0.0 + pushfl + popl %eax + andl $0x40,%eax + shrl $6,%eax + .end + + .inline __r_sqrt_,0 + movl (%esp),%eax + flds (%eax) + fsqrt + .end + + .inline __rint,0 + fldl (%esp) + movl 4(%esp),%eax + andl $0x7fffffff,%eax + cmpl $0x43300000,%eax + jae 1f + frndint +1: + fwait / in case we jumped around frndint + .end + + .inline __scalbn,0 + fildl 8(%esp) /// convert N to extended + fldl (%esp) /// push x + fscale + fstp %st(1) + .end + + .inline __signbit,0 + movl 4(%esp),%eax /// high part of x + shrl $31,%eax + .end + + .inline __signbitf,0 + movl (%esp),%eax + shrl $31,%eax + .end + + .inline __sqrt,0 + fldl (%esp) + fsqrt + .end + + .inline __sqrtf,0 + flds (%esp) + fsqrt + .end + + .inline __sqrtl,0 + fldt (%esp) + fsqrt + .end + + .inline __isnanl,0 + movl 8(%esp),%eax / ax <-- sign bit and __exp + andl $0x00007fff,%eax + jz 1f / jump if __exp is all 0 + xorl $0x00007fff,%eax + jz 2f / jump if __exp is all 1 + testl $0x80000000,4(%esp) + jz 3f / jump if leading bit is 0 + movl $0,%eax + jmp 1f +2: / note that %eax = 0 from before + cmpl $0x80000000,4(%esp) / what is first half of __significand? + jnz 3f / jump if not equal to 0x80000000 + testl $0xffffffff,(%esp) / is second half of __significand 0? + jnz 3f / jump if not equal to 0 + jmp 1f +3: + movl $1,%eax +1: + .end + + .inline __f95_signf,0 + sub $4,%esp + mov 4(%esp),%edx + mov (%edx),%eax + and $0x7fffffff,%eax + mov 8(%esp),%edx + mov (%edx),%ecx + and $0x80000000,%ecx + or %ecx,%eax + mov %eax,(%esp) + flds (%esp) + add $4,%esp + .end + + .inline __f95_sign,0 + mov (%esp),%edx + fldl (%edx) + fabs + mov 4(%esp),%edx + mov 4(%edx),%eax + test %eax,%eax + jns 1f + fchs +1: + .end + diff --git a/usr/src/lib/libm/i386/src/log.s b/usr/src/lib/libm/i386/src/log.s new file mode 100644 index 0000000000..0d72806019 --- /dev/null +++ b/usr/src/lib/libm/i386/src/log.s @@ -0,0 +1,96 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "log.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(log,function) +#include "libm_synonyms.h" +#include "libm_protos.h" + + ENTRY(log) + fldln2 / loge(2) + movl 8(%esp),%eax / eax <-- hi_32(x) + testl $0x80000000,%eax + jnz .maybe_0_or_less + testl $0x7fffffff,%eax + jz .maybe_0 + fldl 4(%esp) / arg, loge(2) + fyl2x / loge(2)*log2(arg); ln(arg) + ret + +.maybe_0: + movl 4(%esp),%ecx / ecx <-- lo_32(x) + cmpl $0,%ecx + je .zero / no branch if x is +denormal +.neg_nan_reentry: + fldl 4(%esp) / arg, loge(2) + fyl2x / loge(2)*log2(arg); ln(arg) + ret + +.zero_or_less: + / x =< 0 + testl $0x7fffffff,%eax + jnz .less_than_0 + movl 4(%esp),%ecx / ecx <-- lo_32(x) + cmpl $0,%ecx + jne .less_than_0 / branch if x is -denormal +.zero: + / x = +/-0 + pushl %ebp + movl %esp,%ebp + PIC_SETUP(1) + pushl $16 + jmp .merge + +.maybe_0_or_less: + cmpl $0xfff00000,%eax / -INF below hi_32(x)? + ja .neg_nan_reentry + jb .zero_or_less + movl 4(%esp),%ecx / ecx <-- lo_32(x) + cmpl $0,%ecx / is x NaN or -INF? + jne .neg_nan_reentry / branch if x is NaN with signbit = 1 + / x = -INF +.less_than_0: + pushl %ebp + movl %esp,%ebp + PIC_SETUP(2) + pushl $17 +.merge: + fstp %st(0) / stack empty + pushl 12(%ebp) + pushl 8(%ebp) + pushl 12(%ebp) + pushl 8(%ebp) + call PIC_F(_SVID_libm_err) + addl $20,%esp + PIC_WRAPUP + leave + ret + .align 4 + SET_SIZE(log) diff --git a/usr/src/lib/libm/i386/src/log10.s b/usr/src/lib/libm/i386/src/log10.s new file mode 100644 index 0000000000..65f9620f55 --- /dev/null +++ b/usr/src/lib/libm/i386/src/log10.s @@ -0,0 +1,96 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "log10.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(log10,function) +#include "libm_synonyms.h" +#include "libm_protos.h" + + ENTRY(log10) + fldlg2 / log10(2) + movl 8(%esp),%eax / eax <-- hi_32(x) + testl $0x80000000,%eax + jnz .maybe_0_or_less + testl $0x7fffffff,%eax + jz .maybe_0 + fldl 4(%esp) / arg, log10(2) + fyl2x / log10(2)*log2(arg); log10(arg) + ret + +.maybe_0: + movl 4(%esp),%ecx / ecx <-- lo_32(x) + cmpl $0,%ecx + je .zero / no branch if x is +denormal +.neg_nan_reentry: + fldl 4(%esp) / arg, log10(2) + fyl2x / log10(2)*log2(arg); log10(arg) + ret + +.zero_or_less: + / x =< 0 + testl $0x7fffffff,%eax + jnz .less_than_0 + movl 4(%esp),%ecx / ecx <-- lo_32(x) + cmpl $0,%ecx + jne .less_than_0 / branch if x is -denormal +.zero: + / x = +/-0 + pushl %ebp + movl %esp,%ebp + PIC_SETUP(1) + pushl $18 + jmp .merge + +.maybe_0_or_less: + cmpl $0xfff00000,%eax / -INF below hi_32(x)? + ja .neg_nan_reentry + jb .zero_or_less + movl 4(%esp),%ecx / ecx <-- lo_32(x) + cmpl $0,%ecx / is x NaN or -INF? + jne .neg_nan_reentry / branch if x is NaN with signbit = 1 + / x = -INF +.less_than_0: + pushl %ebp + movl %esp,%ebp + PIC_SETUP(2) + pushl $19 +.merge: + fstp %st(0) / stack empty + pushl 12(%ebp) + pushl 8(%ebp) + pushl 12(%ebp) + pushl 8(%ebp) + call PIC_F(_SVID_libm_err) + addl $20,%esp + PIC_WRAPUP + leave + ret + .align 4 + SET_SIZE(log10) diff --git a/usr/src/lib/libm/i386/src/log10f.s b/usr/src/lib/libm/i386/src/log10f.s new file mode 100644 index 0000000000..5b69b547ed --- /dev/null +++ b/usr/src/lib/libm/i386/src/log10f.s @@ -0,0 +1,42 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "log10f.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(log10f,function) +#include "libm_synonyms.h" +#include "libm_protos.h" + + ENTRY(log10f) + fldlg2 + flds 4(%esp) / st = arg, st(1) = log10(2) + fyl2x / st = log10(arg) = log10(2)*log2(arg) + ret + .align 4 + SET_SIZE(log10f) diff --git a/usr/src/lib/libm/i386/src/log10l.s b/usr/src/lib/libm/i386/src/log10l.s new file mode 100644 index 0000000000..6a86fd9968 --- /dev/null +++ b/usr/src/lib/libm/i386/src/log10l.s @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "log10l.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(log10l,function) +#include "libm_synonyms.h" + + ENTRY(log10l) + fldlg2 + fldt 4(%esp) / st = arg, st(1) = log10(2) + fyl2x / st = log10(arg) = log10(2)*log2(arg) + ret + .align 4 + SET_SIZE(log10l) diff --git a/usr/src/lib/libm/i386/src/log2.s b/usr/src/lib/libm/i386/src/log2.s new file mode 100644 index 0000000000..32424aa7b5 --- /dev/null +++ b/usr/src/lib/libm/i386/src/log2.s @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "log2.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(log2,function) +#include "libm_synonyms.h" + + ENTRY(log2) + fld1 / push 1.0 + fldl 4(%esp) / push x + fyl2x / st = 1.0*log2(arg) + ret + .align 4 + SET_SIZE(log2) diff --git a/usr/src/lib/libm/i386/src/log2f.s b/usr/src/lib/libm/i386/src/log2f.s new file mode 100644 index 0000000000..67f78ef095 --- /dev/null +++ b/usr/src/lib/libm/i386/src/log2f.s @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "log2f.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(log2f,function) +#include "libm_synonyms.h" + + ENTRY(log2f) + fld1 / push 1.0 + flds 4(%esp) / push x + fyl2x / st = 1.0*log2(arg) + ret + .align 4 + SET_SIZE(log2f) diff --git a/usr/src/lib/libm/i386/src/log2l.s b/usr/src/lib/libm/i386/src/log2l.s new file mode 100644 index 0000000000..1181f50bbd --- /dev/null +++ b/usr/src/lib/libm/i386/src/log2l.s @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "log2l.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(log2l,function) +#include "libm_synonyms.h" + + ENTRY(log2l) + fld1 / push 1.0 + fldt 4(%esp) / push x + fyl2x / st = 1.0*log2(arg) + ret + .align 4 + SET_SIZE(log2l) diff --git a/usr/src/lib/libm/i386/src/logl.s b/usr/src/lib/libm/i386/src/logl.s new file mode 100644 index 0000000000..1eef76f5ca --- /dev/null +++ b/usr/src/lib/libm/i386/src/logl.s @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "logl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(logl,function) +#include "libm_synonyms.h" + + ENTRY(logl) + fldln2 + fldt 4(%esp) / st = arg, st(1) = loge(2) + fyl2x / st = ln(arg) = loge(2)*log2(arg) + ret + .align 4 + SET_SIZE(logl) diff --git a/usr/src/lib/libm/i386/src/lrint.s b/usr/src/lib/libm/i386/src/lrint.s new file mode 100644 index 0000000000..f34c5b6f4a --- /dev/null +++ b/usr/src/lib/libm/i386/src/lrint.s @@ -0,0 +1,45 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "lrint.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(lrint,function) +#include "libm_synonyms.h" + + ENTRY(lrint) + movl %esp,%ecx + subl $8,%esp + fldl 4(%ecx) / load x + fistpl -8(%ecx) / [x] + fwait + movl -8(%ecx),%eax + addl $8,%esp + ret + .align 4 + SET_SIZE(lrint) diff --git a/usr/src/lib/libm/i386/src/lrintf.s b/usr/src/lib/libm/i386/src/lrintf.s new file mode 100644 index 0000000000..e2fb9d2827 --- /dev/null +++ b/usr/src/lib/libm/i386/src/lrintf.s @@ -0,0 +1,45 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "lrintf.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(lrintf,function) +#include "libm_synonyms.h" + + ENTRY(lrintf) + movl %esp,%ecx + subl $8,%esp + flds 4(%ecx) / load x + fistpl -8(%ecx) / [x] + fwait + movl -8(%ecx),%eax + addl $8,%esp + ret + .align 4 + SET_SIZE(lrintf) diff --git a/usr/src/lib/libm/i386/src/lrintl.s b/usr/src/lib/libm/i386/src/lrintl.s new file mode 100644 index 0000000000..c78afbdd70 --- /dev/null +++ b/usr/src/lib/libm/i386/src/lrintl.s @@ -0,0 +1,45 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "lrintl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(lrintl,function) +#include "libm_synonyms.h" + + ENTRY(lrintl) + movl %esp,%ecx + subl $8,%esp + fldt 4(%ecx) / load x + fistpl -8(%ecx) / [x] + fwait + movl -8(%ecx),%eax + addl $8,%esp + ret + .align 4 + SET_SIZE(lrintl) diff --git a/usr/src/lib/libm/i386/src/lround.s b/usr/src/lib/libm/i386/src/lround.s new file mode 100644 index 0000000000..dbafe5ea93 --- /dev/null +++ b/usr/src/lib/libm/i386/src/lround.s @@ -0,0 +1,97 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "lround.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(lround,function) +#include "libm_synonyms.h" +#undef fabs + + .section .rodata + .align 4 +.Lhalf: .float 0.5 + + ENTRY(lround) + movl %esp,%ecx + subl $8,%esp + fstcw -8(%ecx) + fldl 4(%ecx) + movw -8(%ecx),%dx + andw $0xf3ff,%dx + movw %dx,-4(%ecx) + fldcw -4(%ecx) / set RD = to_nearest + fld %st(0) + frndint / [x],x + fstcw -4(%ecx) + movw -4(%ecx),%dx + andw $0xf3ff,%dx + movw -8(%ecx),%ax + andw $0x0c00,%ax + orw %dx,%ax + movw %ax,-8(%ecx) + fldcw -8(%ecx) / restore RD + fucom / check if x is already an integer + fstsw %ax + sahf + jp 0f + je 0f + fxch / x,[x] + fsub %st(1),%st / x-[x],[x] + fabs / |x-[x]|,[x] + PIC_SETUP(1) + fcoms PIC_L(.Lhalf) + PIC_WRAPUP + fnstsw %ax + sahf + jae 2f / if |x-[x]| = 0.5 goto halfway, + / most cases will not take branch. +0: + fstp %st(0) +1: + fistpl -8(%ecx) + fwait + movl -8(%ecx),%eax + addl $8,%esp + ret +2: + / x = n+0.5, recompute lround(x) as x+sign(x)*0.5 + fldl 4(%ecx) / x, 0.5, [x] + movl 8(%ecx),%eax / high part of x + andl $0x80000000,%eax + jnz 3f + faddp + fstp %st(1) + jmp 1b +3: + / here, x is negative, so return x-0.5 + fsubp %st,%st(1) / x-0.5,[x] + fstp %st(1) + jmp 1b + .align 4 + SET_SIZE(lround) diff --git a/usr/src/lib/libm/i386/src/lroundl.s b/usr/src/lib/libm/i386/src/lroundl.s new file mode 100644 index 0000000000..8c5f2205ee --- /dev/null +++ b/usr/src/lib/libm/i386/src/lroundl.s @@ -0,0 +1,97 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "lroundl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(lroundl,function) +#include "libm_synonyms.h" +#undef fabs + + .section .rodata + .align 4 +.Lhalf: .float 0.5 + + ENTRY(lroundl) + movl %esp,%ecx + subl $8,%esp + fstcw -8(%ecx) + fldt 4(%ecx) + movw -8(%ecx),%dx + andw $0xf3ff,%dx + movw %dx,-4(%ecx) + fldcw -4(%ecx) / set RD = to_nearest + fld %st(0) + frndint / [x],x + fstcw -4(%ecx) + movw -4(%ecx),%dx + andw $0xf3ff,%dx + movw -8(%ecx),%ax + andw $0x0c00,%ax + orw %dx,%ax + movw %ax,-8(%ecx) + fldcw -8(%ecx) / restore RD + fucom / check if x is already an integer + fstsw %ax + sahf + jp 0f + je 0f + fxch / x,[x] + fsub %st(1),%st / x-[x],[x] + fabs / |x-[x]|,[x] + PIC_SETUP(1) + fcoms PIC_L(.Lhalf) + PIC_WRAPUP + fnstsw %ax + sahf + jae 2f / if |x-[x]| = 0.5 goto halfway, + / most cases will not take branch. +0: + fstp %st(0) +1: + fistpl -8(%ecx) + fwait + movl -8(%ecx),%eax + addl $8,%esp + ret +2: + / x = n+0.5, recompute lroundl(x) as x+sign(x)*0.5 + fldt 4(%ecx) / x, 0.5, [x] + movw 12(%ecx),%ax / sign+exp part of x + andw $0x8000,%ax / look at sign bit + jnz 3f + faddp + fstp %st(1) + jmp 1b +3: + / here, x is negative, so return x-0.5 + fsubp %st,%st(1) / x-0.5,[x] + fstp %st(1) + jmp 1b + .align 4 + SET_SIZE(lroundl) diff --git a/usr/src/lib/libm/i386/src/nextafter.s b/usr/src/lib/libm/i386/src/nextafter.s new file mode 100644 index 0000000000..b04bc0dd8a --- /dev/null +++ b/usr/src/lib/libm/i386/src/nextafter.s @@ -0,0 +1,134 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "nextafter.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(nextafter,function) + .weak _nextafter + .type _nextafter,@function +_nextafter = __nextafter +#include "libm_synonyms.h" +#include "libm_protos.h" + + .data + .align 8 +Fmin: .long 0x1,0x0 +ftmp: .long 0,0 /// WILL WRITE INTO + + + ENTRY(nextafter) + pushl %ebp + movl %esp,%ebp + fldl 16(%ebp) / y + subl $8,%esp + fldl 8(%ebp) / load x + fucom / x : y + fstsw %ax + sahf + jp .NaN + je .equal + fstp %st(1) / x + ja .bigger + / x < y + ftst + movl $1,%ecx /// Fmin + movl %ecx,-8(%ebp) + movl $0,%ecx /// Fmin+4 + movl %ecx,-4(%ebp) + fnstsw %ax + sahf + je .final + ja .addulp + jb .subulp +.bigger: + / x > y + ftst + movl $1,%ecx /// Fmin + movl %ecx,-8(%ebp) + movl $0,%ecx /// Fmin+4 + xorl $0x80000000,%ecx + movl %ecx,-4(%ebp) + fnstsw %ax + sahf + je .final + jb .addulp +.subulp: + movl 8(%ebp),%eax / low x + movl 12(%ebp),%ecx / high x + subl $1,%eax / low x - ulp + movl %eax,-8(%ebp) + sbbl $0x0,%ecx + movl %ecx,-4(%ebp) + jmp .final +.addulp: + movl 8(%ebp),%eax / low x + movl 12(%ebp),%ecx / high x + addl $1,%eax / low x + ulp + movl %eax,-8(%ebp) + adcl $0x0,%ecx + movl %ecx,-4(%ebp) + +.final: + fstp %st(0) + fldl -8(%ebp) + andl $0x7ff00000,%ecx + jz .underflow + cmpl $0x7ff00000,%ecx + je .overflow + jmp .return +.overflow: + PIC_SETUP(1) + pushl $46 + fstp %st(0) / stack empty + pushl -4(%ebp) + pushl -8(%ebp) + pushl -4(%ebp) + pushl -8(%ebp) + call PIC_F(_SVID_libm_err) + addl $20,%esp + PIC_WRAPUP + jmp .return +.underflow: + PIC_SETUP(2) + fldl PIC_L(Fmin) + fmul %st(0),%st + fstpl PIC_L(ftmp) / create underflow signal + PIC_WRAPUP + jmp .return +.equal: + fstp %st(0) / C99 says to return y when x == y + jmp .return +.NaN: + faddp %st,%st(1) / x+y,x +.return: + fwait + leave + ret + .align 4 + SET_SIZE(nextafter) diff --git a/usr/src/lib/libm/i386/src/nextafterf.s b/usr/src/lib/libm/i386/src/nextafterf.s new file mode 100644 index 0000000000..9cbb36166e --- /dev/null +++ b/usr/src/lib/libm/i386/src/nextafterf.s @@ -0,0 +1,114 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "nextafterf.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(nextafterf,function) +#include "libm_synonyms.h" + + .data + .align 4 +Fmaxf: .long 0x7f7fffff +Fminf: .long 0x1 +ftmpf: .long 0 + + + ENTRY(nextafterf) + pushl %ebp + movl %esp,%ebp + movl $0,%eax /// upper half of %eax must be initialized + flds 12(%ebp) / y + subl $4,%esp + flds 8(%ebp) / x, y + fucom / x : y + fstsw %ax + sahf + jp .NaN + je .equal + fstp %st(1) / x + ja .bigger + / x < y + ftst / x : 0 + movl $0x1,-4(%ebp) / -4(%ebp) contains Fminf + fnstsw %ax + sahf + je .final + ja .addulp + jb .subulp +.bigger: + / x > y + ftst / x : 0 + movl $0x80000001,-4(%ebp) / -4(%ebp) contains -Fminf + fnstsw %ax + sahf + je .final + jb .addulp +.subulp: + movl 8(%ebp),%eax / x + subl $1,%eax / x - ulp + movl %eax,-4(%ebp) + jmp .final +.addulp: + movl 8(%ebp),%eax / x + addl $1,%eax / x + ulp + movl %eax,-4(%ebp) + +.final: + fstp %st(0) / empty + flds -4(%ebp) / z + andl $0x7f800000,%eax + jz .underflow + cmpl $0x7f800000,%eax + je .overflow + jmp .return +.overflow: + PIC_SETUP(1) + flds PIC_L(Fmaxf) / Fmaxf, z + fmul %st(0),%st / overflow-to-Inf, z + fstps PIC_L(ftmpf) / z & create overflow signal + PIC_WRAPUP + jmp .return +.underflow: + PIC_SETUP(2) + flds PIC_L(Fminf) / Fminf, z + fmul %st(0),%st / underflow-to-0, z + fstps PIC_L(ftmpf) / z & create underflow signal + PIC_WRAPUP + jmp .return +.equal: + fstp %st(0) / C99 says to return y when x == y + jmp .return +.NaN: + faddp %st,%st(1) / x+y +.return: + fwait + leave + ret + .align 4 + SET_SIZE(nextafterf) diff --git a/usr/src/lib/libm/i386/src/nextafterl.s b/usr/src/lib/libm/i386/src/nextafterl.s new file mode 100644 index 0000000000..cdf8647039 --- /dev/null +++ b/usr/src/lib/libm/i386/src/nextafterl.s @@ -0,0 +1,186 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "nextafterl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(nextafterl,function) +#include "libm_synonyms.h" + + .section .rodata + .align 4 +.LFmaxl: .long 0xffffffff,0xffffffff,0x00007ffe +.LFminl: .long 0x1,0x0,0x0 + + + ENTRY(nextafterl) + pushl %ebp + movl %esp,%ebp + fldt 20(%ebp) / y + subl $12,%esp + fldt 8(%ebp) / load x + fucom / x : y + fstsw %ax + sahf + jp .LNaN + je .Lequal + fstp %st(1) / x + ja .Lbigger + / x < y + ftst + movl $1,-12(%ebp) /// -12(%ebp) contains Fminl + movl $0,-8(%ebp) + movl $0,%ecx /// final needs this + movl %ecx,-4(%ebp) + fnstsw %ax + sahf + je .Lfinal + ja .Laddulp + jb .Lsubulp +.Lbigger: + / x > y + ftst + movl $1,-12(%ebp) /// -12(%ebp) contains -Fminl + movl $0,-8(%ebp) + movl $0x00008000,%ecx /// final needs this + movl %ecx,-4(%ebp) + fnstsw %ax + sahf + je .Lfinal + jb .Laddulp +.Lsubulp: + movl 12(%ebp),%edx / high word of significand of x + movl 16(%ebp),%ecx / x's exponent + andl $0x0000ffff,%ecx + movl %edx,%eax + not %eax + andl $0x80000000,%eax / look at explicit leading bit + orl %ecx,%eax + andl $0x80007fff,%eax + jnz .Lnot_pseudonormal / zero value implies pseudonormal + addl $1,%ecx / if pseudonormal, turn into equivalent normal +.Lnot_pseudonormal: + movl 8(%ebp),%eax / low x + subl $1,%eax / low x - ulp + movl %eax,-12(%ebp) + cmpl $0xffffffff,%eax / this means low x was 0 + jz .Lborrow + movl %edx,-8(%ebp) + movl %ecx,-4(%ebp) + jmp .Lfinal +.Lborrow: + cmpl $0x80000000,%edx / look at high x + je .Lsecond_borrow + subl $1,%edx + movl %edx,-8(%ebp) + movl %ecx,-4(%ebp) + jmp .Lfinal +.Lsecond_borrow: + movl %ecx,%eax + andl $0x7fff,%eax / look at exp x without sign bit + cmpl $1,%eax + jbe .Lsubnormal_result / exp > 1 ==> result will be normal + movl $0xffffffff,-8(%ebp) + subl $1,%ecx + movl %ecx,-4(%ebp) + jmp .Lfinal +.Lsubnormal_result: + movl $0x7fffffff,-8(%ebp) + movl %ecx,%eax + andl $0x8000,%eax / look at sign bit + jz .Lpositive + movl $0x8000,%ecx + movl %ecx,-4(%ebp) + jmp .Lfinal +.Lpositive: + movl $0,%ecx + movl %ecx,-4(%ebp) + jmp .Lfinal +.Laddulp: + movl 12(%ebp),%edx / high x + movl 16(%ebp),%ecx / x's exponent + andl $0x0000ffff,%ecx + movl %edx,%eax + not %eax + andl $0x80000000,%eax / look at explicit leading bit + orl %ecx,%eax + andl $0x80007fff,%eax + jnz .Lnot_pseudonormal_2 / zero value implies pseudonormal + addl $1,%ecx +.Lnot_pseudonormal_2: + movl 8(%ebp),%eax / low x + addl $1,%eax / low x + ulp + movl %eax,-12(%ebp) + jz .Lcarry / jump if the content of %eax is 0 + movl %edx,-8(%ebp) + movl %ecx,-4(%ebp) + jmp .Lfinal +.Lcarry: + movl %edx,%eax + andl $0x7fffffff,%eax + cmpl $0x7fffffff,%eax / look at high x + je .Lsecond_carry + addl $1,%edx + movl %edx,-8(%ebp) + movl %ecx,-4(%ebp) + jmp .Lfinal +.Lsecond_carry: + movl $0x80000000,-8(%ebp) + addl $1,%ecx + movl %ecx,-4(%ebp) +.Lfinal: + fstp %st(0) + fldt -12(%ebp) + andl $0x00007fff,%ecx + jz .Lunderflow + cmpw $0x7fff,%cx + je .Loverflow + jmp .Lreturn +.Loverflow: + PIC_SETUP(1) + fldt PIC_L(.LFmaxl) + PIC_WRAPUP + fmulp %st,%st(0) / create overflow signal + jmp .Lreturn +.Lunderflow: + PIC_SETUP(2) + fldt PIC_L(.LFminl) + PIC_WRAPUP + fmulp %st,%st(0) / create underflow signal + jmp .Lreturn +.Lequal: + fstp %st(0) / C99 says to return y when x == y + jmp .Lreturn +.LNaN: + faddp %st,%st(1) / x+y,x +.Lreturn: + fwait + leave + ret + .align 4 + SET_SIZE(nextafterl) diff --git a/usr/src/lib/libm/i386/src/nexttowardl.s b/usr/src/lib/libm/i386/src/nexttowardl.s new file mode 100644 index 0000000000..c39b33d04b --- /dev/null +++ b/usr/src/lib/libm/i386/src/nexttowardl.s @@ -0,0 +1,186 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "nexttowardl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(nexttowardl,function) +#include "libm_synonyms.h" + + .section .rodata + .align 4 +.LFmaxl: .long 0xffffffff,0xffffffff,0x00007ffe +.LFminl: .long 0x1,0x0,0x0 + + + ENTRY(nexttowardl) + pushl %ebp + movl %esp,%ebp + fldt 20(%ebp) / y + subl $12,%esp + fldt 8(%ebp) / load x + fucom / x : y + fstsw %ax + sahf + jp .LNaN + je .Lequal + fstp %st(1) / x + ja .Lbigger + / x < y + ftst + movl $1,-12(%ebp) /// -12(%ebp) contains Fminl + movl $0,-8(%ebp) + movl $0,%ecx /// final needs this + movl %ecx,-4(%ebp) + fnstsw %ax + sahf + je .Lfinal + ja .Laddulp + jb .Lsubulp +.Lbigger: + / x > y + ftst + movl $1,-12(%ebp) /// -12(%ebp) contains -Fminl + movl $0,-8(%ebp) + movl $0x00008000,%ecx /// final needs this + movl %ecx,-4(%ebp) + fnstsw %ax + sahf + je .Lfinal + jb .Laddulp +.Lsubulp: + movl 12(%ebp),%edx / high word of significand of x + movl 16(%ebp),%ecx / x's exponent + andl $0x0000ffff,%ecx + movl %edx,%eax + not %eax + andl $0x80000000,%eax / look at explicit leading bit + orl %ecx,%eax + andl $0x80007fff,%eax + jnz .Lnot_pseudonormal / zero value implies pseudonormal + addl $1,%ecx / if pseudonormal, turn into equivalent normal +.Lnot_pseudonormal: + movl 8(%ebp),%eax / low x + subl $1,%eax / low x - ulp + movl %eax,-12(%ebp) + cmpl $0xffffffff,%eax / this means low x was 0 + jz .Lborrow + movl %edx,-8(%ebp) + movl %ecx,-4(%ebp) + jmp .Lfinal +.Lborrow: + cmpl $0x80000000,%edx / look at high x + je .Lsecond_borrow + subl $1,%edx + movl %edx,-8(%ebp) + movl %ecx,-4(%ebp) + jmp .Lfinal +.Lsecond_borrow: + movl %ecx,%eax + andl $0x7fff,%eax / look at exp x without sign bit + cmpl $1,%eax + jbe .Lsubnormal_result / exp > 1 ==> result will be normal + movl $0xffffffff,-8(%ebp) + subl $1,%ecx + movl %ecx,-4(%ebp) + jmp .Lfinal +.Lsubnormal_result: + movl $0x7fffffff,-8(%ebp) + movl %ecx,%eax + andl $0x8000,%eax / look at sign bit + jz .Lpositive + movl $0x8000,%ecx + movl %ecx,-4(%ebp) + jmp .Lfinal +.Lpositive: + movl $0,%ecx + movl %ecx,-4(%ebp) + jmp .Lfinal +.Laddulp: + movl 12(%ebp),%edx / high x + movl 16(%ebp),%ecx / x's exponent + andl $0x0000ffff,%ecx + movl %edx,%eax + not %eax + andl $0x80000000,%eax / look at explicit leading bit + orl %ecx,%eax + andl $0x80007fff,%eax + jnz .Lnot_pseudonormal_2 / zero value implies pseudonormal + addl $1,%ecx +.Lnot_pseudonormal_2: + movl 8(%ebp),%eax / low x + addl $1,%eax / low x + ulp + movl %eax,-12(%ebp) + jz .Lcarry / jump if the content of %eax is 0 + movl %edx,-8(%ebp) + movl %ecx,-4(%ebp) + jmp .Lfinal +.Lcarry: + movl %edx,%eax + andl $0x7fffffff,%eax + cmpl $0x7fffffff,%eax / look at high x + je .Lsecond_carry + addl $1,%edx + movl %edx,-8(%ebp) + movl %ecx,-4(%ebp) + jmp .Lfinal +.Lsecond_carry: + movl $0x80000000,-8(%ebp) + addl $1,%ecx + movl %ecx,-4(%ebp) +.Lfinal: + fstp %st(0) + fldt -12(%ebp) + andl $0x00007fff,%ecx + jz .Lunderflow + cmpw $0x7fff,%cx + je .Loverflow + jmp .Lreturn +.Loverflow: + PIC_SETUP(1) + fldt PIC_L(.LFmaxl) + PIC_WRAPUP + fmulp %st,%st(0) / create overflow signal + jmp .Lreturn +.Lunderflow: + PIC_SETUP(2) + fldt PIC_L(.LFminl) + PIC_WRAPUP + fmulp %st,%st(0) / create underflow signal + jmp .Lreturn +.Lequal: + fstp %st(0) / C99 says to return y when x == y + jmp .Lreturn +.LNaN: + faddp %st,%st(1) / x+y,x +.Lreturn: + fwait + leave + ret + .align 4 + SET_SIZE(nexttowardl) diff --git a/usr/src/lib/libm/i386/src/pow.s b/usr/src/lib/libm/i386/src/pow.s new file mode 100644 index 0000000000..c539a7791d --- /dev/null +++ b/usr/src/lib/libm/i386/src/pow.s @@ -0,0 +1,473 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "pow.s" + +/ Note: 0^NaN should not signal "invalid" but this implementation +/ does because y is placed on the NPX stack. + +/ Special cases: +/ +/ x ** 0 is 1 _SVID_libm_err if x is 0 or NaN +/ 1 ** y is 1 (C99) +/ x ** NaN is NaN +/ NaN ** y (except 0) is NaN +/ x ** 1 is x +/ +-(|x| > 1) ** +inf is +inf +/ +-(|x| > 1) ** -inf is +0 +/ +-(|x| < 1) ** +inf is +0 +/ +-(|x| < 1) ** -inf is +inf +/ (-1) ** +-inf is +1 (C99) +/ +0 ** +y (except 0, NaN) is +0 +/ -0 ** +y (except 0, NaN, odd int) is +0 +/ -0 ** +y (odd int) is -0 +/ +-0 ** -y (except 0, NaN) _SVID_libm_err +/ +inf ** +y (except 0, NaN) is +inf +/ +inf ** -y (except 0, NaN) is +0 +/ -inf ** +-y (except 0, NaN) is -0 ** -+y (NO z flag) +/ x ** -1 is 1/x +/ x ** 2 is x*x +/ -x ** y (an integer) is (-1)**(y) * (+x)**(y) +/ x ** y (x negative & y not integer) _SVID_libm_err +/ if x and y are finite and x**y = 0 _SVID_libm_err (underflow) +/ if x and y are finite and x**y = inf _SVID_libm_err (overflow) + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(pow,function) +#include "libm_synonyms.h" +#include "libm_protos.h" +#include "xpg6.h" + +#undef fabs + + .data + .align 4 +negzero: + .float -0.0 +one: + .float 1.0 +negone: + .float -1.0 +two: + .float 2.0 +Snan: + .long 0x7f800001 +pinfinity: + .long 0x7f800000 +ninfinity: + .long 0xff800000 + + + ENTRY(pow) + pushl %ebp + movl %esp,%ebp + PIC_SETUP(1) + + fldl 8(%ebp) / x + fxam / determine class of x + fnstsw %ax / store status in %ax + movb %ah,%dh / %dh <- condition code of x + + fldl 16(%ebp) / y , x + fxam / determine class of y + fnstsw %ax / store status in %ax + movb %ah,%dl / %dl <- condition code of y + + call .pow_main /// LOCAL + PIC_WRAPUP + leave + ret + +.pow_main: + / x ** 0 is 1 unless x is 0 or a NaN + movb %dl,%cl + andb $0x45,%cl + cmpb $0x40,%cl / C3=1 C2=0 C1=? C0=0 when +-0 + jne 1f + movb %dh,%cl + andb $0x45,%cl + cmpb $0x40,%cl / C3=1 C2=0 C1=? C0=0 when +-0 + jne 2f + / 0^0 + pushl $20 + jmp .SVIDerr / SVID error handler +2: + cmpb $0x01,%cl /// C3=0 C2=0 C1=? C0=1 when +-NaN + jne 2f + / NaN^0 + pushl $42 + jmp .SVIDerr +2: + / (not 0 or NaN)^0 + fstp %st(0) / x + fstp %st(0) / stack empty + fld1 / 1 + ret + +1: / y is not zero + PIC_G_LOAD(movzwl,__xpg6,eax) + andl $_C99SUSv3_pow_treats_Inf_as_an_even_int,%eax + cmpl $0,%eax + je 1f + + / C99: 1 ** anything is 1 + fld1 / 1, y, x + fucomp %st(2) / y, x + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + jp 1f / so that pow(NaN1,NaN2) returns NaN2 + jne 1f + fstp %st(0) / x + ret + +1: + / x ** NaN is NaN + movb %dl,%cl + andb $0x45,%cl + cmpb $0x01,%cl / C3=0 C2=0 C1=? C0=1 when +-NaN + jne 1f + fstp %st(1) / y + ret + +1: / y is not NaN + / NaN ** y (except 0) is NaN + movb %dh,%cl + andb $0x45,%cl + cmpb $0x01,%cl / C3=0 C2=0 C1=? C0=1 when +-NaN + jne 1f + fstp %st(0) / x + ret + +1: / x is not NaN + / x ** 1 is x + fcoms PIC_L(one) / y , x + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + jne 1f + fstp %st(0) / x + ret + +1: / y is not 1 + / +-(|x| > 1) ** +inf is +inf + / +-(|x| > 1) ** -inf is +0 + / +-(|x| < 1) ** +inf is +0 + / +-(|x| < 1) ** -inf is +inf + / +-(|x| = 1) ** +-inf is NaN + movb %dl,%cl + andb $0x47,%cl + cmpb $0x05,%cl / C3=0 C2=1 C1=0 C0=1 when +inf + je .yispinf + cmpb $0x07,%cl / C3=0 C2=1 C1=1 C0=1 when -inf + je .yisninf + + / +0 ** +y (except 0, NaN) is +0 + / -0 ** +y (except 0, NaN, odd int) is +0 + / +0 ** -y (except 0, NaN) is +inf (z flag) + / -0 ** -y (except 0, NaN, odd int) is +inf (z flag) + / -0 ** y (odd int) is - (+0 ** x) + movb %dh,%cl + andb $0x47,%cl + cmpb $0x40,%cl / C3=1 C2=0 C1=0 C0=0 when +0 + je .xispzero + cmpb $0x42,%cl / C3=1 C2=0 C1=1 C0=0 when -0 + je .xisnzero + + / +inf ** +y (except 0, NaN) is +inf + / +inf ** -y (except 0, NaN) is +0 + / -inf ** +-y (except 0, NaN) is -0 ** -+y (NO z flag) + movb %dh,%cl + andb $0x47,%cl + cmpb $0x05,%cl / C3=0 C2=1 C1=0 C0=1 when +inf + je .xispinf + cmpb $0x07,%cl / C3=0 C2=1 C1=1 C0=1 when -inf + je .xisninf + + / x ** -1 is 1/x + fcoms PIC_L(negone) / y , x + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + jne 1f + fld %st(1) / x , y , x + fdivrs PIC_L(one) / 1/x , y , x + jmp .signok / check for over/underflow + +1: / y is not -1 + / x ** 2 is x*x + fcoms PIC_L(two) / y , x + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + jne 1f + fld %st(1) / x , y , x + fld %st(0) / x , x , y , x + fmulp / x^2 , y , x + jmp .signok / check for over/underflow + +1: / y is not 2 + / make copies of x & y + fld %st(1) / x , y , x + fld %st(1) / y , x , y , x + + / -x ** y (an integer) is (-1)**(y) * (+x)**(y) + / x ** y (x negative & y not integer) is NaN + movl $0,%ecx / track whether to flip sign of result + fld %st(1) / x , y , x , y , x + ftst / compare %st(0) with 0 + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + fstp %st(0) / y , x , y , x + ja .merge / x > 0 + / x < 0 + call .y_is_int + cmpl $0,%ecx + jne 1f + / x < 0, y is non-integral + fstp %st(0) / x , y , x + fstp %st(0) / y , x + pushl $24 + jmp .SVIDerr / SVID error handler + +1: / x < 0 & y = int + fxch / x , y , y , x + fchs / px = -x , y , y , x + fxch / y , px , y , x +.merge: + / px > 0 + fxch / px , y , y , x + + / x**y = exp(y*ln(x)) + fyl2x / t=y*log2(px) , y , x + fld %st(0) / t , t , y , x + frndint / [t] , t , y , x + fxch / t , [t] , y , x + fucom + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + je 1f / t is integral + fsub %st(1),%st / t-[t] , [t] , y , x + f2xm1 / 2**(t-[t])-1 , [t] , y , x + fadds PIC_L(one) / 2**(t-[t]) , [t] , y , x + fscale / 2**t = px**y , [t] , y , x + jmp 2f +1: + fstp %st(0) / t=[t] , y , x + fld1 / 1 , t , y , x + fscale / 1*2**t = x**y , t , y , x +2: + fstp %st(1) / x**y , y , x + cmpl $1,%ecx + jne .signok + fchs / change sign since x<0 & y=-int +.signok: + subl $8,%esp + fstpl (%esp) / round to double precision + fldl (%esp) / place result on NPX stack + addl $8,%esp + + fxam / determine class of x**y + fnstsw %ax / store status in %ax + andw $0x4500,%ax + / check for overflow + cmpw $0x0500,%ax / C0=0 C1=1 C2=? C3=1 then +-inf + jne 1f + / x^y overflows + fstp %st(0) / y , x + pushl $21 + jmp .SVIDerr +1: + / check for underflow + cmpw $0x4000,%ax / C0=1 C1=0 C2=? C3=0 then +-0 + jne 1f + / x^y underflows + fstp %st(0) / y , x + pushl $22 + jmp .SVIDerr +1: + fstp %st(2) / y , x**y + fstp %st(0) / x**y + ret + +/ ------------------------------------------------------------------------ + +.xispinf: + ftst / compare %st(0) with 0 + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + ja .retpinf / y > 0 + jmp .retpzero / y < 0 + +.xisninf: + / -inf ** +-y is -0 ** -+y + fchs / -y , x + flds PIC_L(negzero) / -0 , -y , x + fstp %st(2) / -y , -0 + jmp .xisnzero + +.yispinf: + fld %st(1) / x , y , x + fabs / |x| , y , x + fcomps PIC_L(one) / y , x + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + je .retponeorinvalid / x == -1 C99 + ja .retpinf / |x| > 1 + jmp .retpzero / |x| < 1 + +.yisninf: + fld %st(1) / x , y , x + fabs / |x| , y , x + fcomps PIC_L(one) / y , x + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + je .retponeorinvalid / x == -1 C99 + ja .retpzero / |x| > 1 + jmp .retpinf / |x| < 1 + +.xispzero: + / y cannot be 0 or NaN ; stack has y , x + ftst / compare %st(0) with 0 + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + ja .retpzero / y > 0 + / x = +0 & y < 0 + jmp .SVIDzerotoneg + +.xisnzero: + / y cannot be 0 or NaN ; stack has y , x + call .y_is_int + cmpl $1,%ecx + jne 1f / y is not an odd integer + / y is an odd integer + ftst / compare %st(0) with 0 + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + ja .retnzero / y > 0 + / x = -0 & y < 0 (odd int) return -inf (z flag) + / x = -inf & y != 0 or NaN return -inf (NO z flag) + movb %dh,%cl + andb $0x45,%cl + cmpb $0x05,%cl / C3=0 C2=1 C1=? C0=1 when +-inf + jne .SVIDzerotoneg + fstp %st(0) / x + fstp %st(0) / stack empty + flds PIC_L(ninfinity) / -inf + ret + +1: / y is not an odd integer + ftst / compare %st(0) with 0 + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + ja .retpzero / y > 0 + / x = -0 & y < 0 (not odd int) return +inf (z flag) + / x = -inf & y not 0 or NaN return +inf (NO z flag) + movb %dh,%cl + andb $0x45,%cl + cmpb $0x05,%cl / C3=0 C2=1 C1=? C0=1 when +-inf + jne .SVIDzerotoneg + jmp .retpinf / return +inf (NO z flag) + +.retpzero: + fstp %st(0) / x + fstp %st(0) / stack empty + fldz / +0 + ret + +.retnzero: + fstp %st(0) / x + fstp %st(0) / stack empty + flds PIC_L(negzero) / -0 + ret + +.retponeorinvalid: + PIC_G_LOAD(movzwl,__xpg6,eax) + andl $_C99SUSv3_pow_treats_Inf_as_an_even_int,%eax + cmpl $0,%eax + je 1f + fstp %st(0) / x + fstp %st(0) / stack empty + fld1 / 1 + ret + +1: + fstp %st(0) / x + fstp %st(0) / stack empty + flds PIC_L(Snan) / Q NaN (i flag) + fwait + ret + +.retpinf: + fstp %st(0) / x + fstp %st(0) / stack empty + flds PIC_L(pinfinity) / +inf + ret + +.SVIDzerotoneg: + pushl $23 +.SVIDerr: + / At this point the fp stack contains y , x and the number + / of the error case has been pushed on the memory stack. + subl $16,%esp + fstpl 8(%esp) / push y + fstpl (%esp) / push x; NPX stack empty + call PIC_F(_SVID_libm_err) / report result/error according to SVID + addl $20,%esp + ret + +/ Set %ecx to 2 if y is an even integer, 1 if y is an odd integer, +/ 0 otherwise. Assume y is not zero. Do not raise inexact or modify +/ %edx. +.y_is_int: + movl 20(%ebp),%eax + andl $0x7fffffff,%eax / |y| + cmpl $0x43400000,%eax + jae 1f / |y| >= 2^53, an even int + cmpl $0x3ff00000,%eax + jb 2f / |y| < 1, can't be an int + movl %eax,%ecx + sarl $20,%ecx + subl $0x433,%ecx + negl %ecx / 52 - unbiased exponent of y + movl 16(%ebp),%eax + bsfl %eax,%eax / index of least sig. 1 bit + jne 3f / jump if 1 bit found + movl 20(%ebp),%eax + bsfl %eax,%eax + addl $32,%eax / 32 + index of least sig. 1 bit +3: + cmpl %ecx,%eax + jb 2f + ja 1f + movl $1,%ecx + ret +1: + movl $2,%ecx + ret +2: + xorl %ecx,%ecx + ret + .align 4 + SET_SIZE(pow) diff --git a/usr/src/lib/libm/i386/src/powf.s b/usr/src/lib/libm/i386/src/powf.s new file mode 100644 index 0000000000..e45b9d4694 --- /dev/null +++ b/usr/src/lib/libm/i386/src/powf.s @@ -0,0 +1,443 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "powf.s" + +/ Note: 0^SNaN should not signal "invalid" but this implementation +/ does because y is placed on the NPX stack. + +/ Special cases: +/ +/ x ** 0 is 1 +/ 1 ** y is 1 (C99) +/ x ** NaN is NaN +/ NaN ** y (except 0) is NaN +/ x ** 1 is x +/ +-(|x| > 1) ** +inf is +inf +/ +-(|x| > 1) ** -inf is +0 +/ +-(|x| < 1) ** +inf is +0 +/ +-(|x| < 1) ** -inf is +inf +/ (-1) ** +-inf is +1 (C99) +/ +0 ** +y (except 0, NaN) is +0 +/ -0 ** +y (except 0, NaN, odd int) is +0 +/ +0 ** -y (except 0, NaN) is +inf (z flag) +/ -0 ** -y (except 0, NaN, odd int) is +inf (z flag) +/ -0 ** y (odd int) is - (+0 ** x) +/ +inf ** +y (except 0, NaN) is +inf +/ +inf ** -y (except 0, NaN) is +0 +/ -inf ** +-y (except 0, NaN) is -0 ** -+y (NO z flag) +/ x ** -1 is 1/x +/ x ** 2 is x*x +/ -x ** y (an integer) is (-1)**(y) * (+x)**(y) +/ x ** y (x negative & y not integer) is NaN (i flag) + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(powf,function) +#include "libm_synonyms.h" +#include "libm_protos.h" +#include "xpg6.h" + +#undef fabs + + .data + .align 4 +negzero: + .float -0.0 +half: + .float 0.5 +one: + .float 1.0 +negone: + .float -1.0 +two: + .float 2.0 +Snan: + .long 0x7f800001 +pinfinity: + .long 0x7f800000 +ninfinity: + .long 0xff800000 + + + ENTRY(powf) + pushl %ebp + movl %esp,%ebp + PIC_SETUP(1) + + flds 8(%ebp) / x + fxam / determine class of x + fnstsw %ax / store status in %ax + movb %ah,%dh / %dh <- condition code of x + + flds 12(%ebp) / y , x + fxam / determine class of y + fnstsw %ax / store status in %ax + movb %ah,%dl / %dl <- condition code of y + + call .pow_main /// LOCAL + PIC_WRAPUP + leave + ret + +.pow_main: + / x ** 0 is 1 + movb %dl,%cl + andb $0x45,%cl + cmpb $0x40,%cl / C3=1 C2=0 C1=? C0=0 when +-0 + jne 1f + fstp %st(0) / x + fstp %st(0) / stack empty + fld1 / 1 + ret + +1: / y is not zero + PIC_G_LOAD(movzwl,__xpg6,eax) + andl $_C99SUSv3_pow_treats_Inf_as_an_even_int,%eax + cmpl $0,%eax + je 1f + + / C99: 1 ** anything is 1 + fld1 / 1, y, x + fucomp %st(2) / y, x + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + jp 1f / so that pow(NaN1,NaN2) returns NaN2 + jne 1f + fstp %st(0) / x + ret + +1: + / x ** NaN is NaN + movb %dl,%cl + andb $0x45,%cl + cmpb $0x01,%cl / C3=0 C2=0 C1=? C0=1 when +-NaN + jne 1f + fstp %st(1) / y + ret + +1: / y is not NaN + / NaN ** y (except 0) is NaN + movb %dh,%cl + andb $0x45,%cl + cmpb $0x01,%cl / C3=0 C2=0 C1=? C0=1 when +-NaN + jne 1f + fstp %st(0) / x + ret + +1: / x is not NaN + / x ** 1 is x + fcoms PIC_L(one) / y , x + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + jne 1f + fstp %st(0) / x + ret + +1: / y is not 1 + / +-(|x| > 1) ** +inf is +inf + / +-(|x| > 1) ** -inf is +0 + / +-(|x| < 1) ** +inf is +0 + / +-(|x| < 1) ** -inf is +inf + / +-(|x| = 1) ** +-inf is NaN + movb %dl,%cl + andb $0x47,%cl + cmpb $0x05,%cl / C3=0 C2=1 C1=0 C0=1 when +inf + je .yispinf + cmpb $0x07,%cl / C3=0 C2=1 C1=1 C0=1 when -inf + je .yisninf + + / +0 ** +y (except 0, NaN) is +0 + / -0 ** +y (except 0, NaN, odd int) is +0 + / +0 ** -y (except 0, NaN) is +inf (z flag) + / -0 ** -y (except 0, NaN, odd int) is +inf (z flag) + / -0 ** y (odd int) is - (+0 ** x) + movb %dh,%cl + andb $0x47,%cl + cmpb $0x40,%cl / C3=1 C2=0 C1=0 C0=0 when +0 + je .xispzero + cmpb $0x42,%cl / C3=1 C2=0 C1=1 C0=0 when -0 + je .xisnzero + + / +inf ** +y (except 0, NaN) is +inf + / +inf ** -y (except 0, NaN) is +0 + / -inf ** +-y (except 0, NaN) is -0 ** -+y (NO z flag) + movb %dh,%cl + andb $0x47,%cl + cmpb $0x05,%cl / C3=0 C2=1 C1=0 C0=1 when +inf + je .xispinf + cmpb $0x07,%cl / C3=0 C2=1 C1=1 C0=1 when -inf + je .xisninf + + / x ** -1 is 1/x + fcoms PIC_L(negone) / y , x + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + jne 1f + fld %st(1) / x , y , x + fdivrs PIC_L(one) / 1/x , y , x + jmp .signok / check for over/underflow + +1: / y is not -1 + / x ** 2 is square(x) + fcoms PIC_L(two) / y , x + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + jne 1f + fld %st(1) / x , y , x + fld %st(0) / x , x , y , x + fmulp / x^2 , y , x + jmp .signok / check for over/underflow + +1: / y is not 2 + / x ** 1/2 is sqrt(x) + fcoms PIC_L(half) / y , x + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + jne 1f + fld %st(1) / x , y , x + fsqrt / sqrt(x) , y , x + jmp .signok / check for over/underflow + +1: / y is not 2 + / make copies of x & y + fld %st(1) / x , y , x + fld %st(1) / y , x , y , x + + / -x ** y (an integer) is (-1)**(y) * (+x)**(y) + / x ** y (x negative & y not integer) is NaN + movl $0,%ecx / track whether to flip sign of result + fld %st(1) / x , y , x , y , x + ftst / compare %st(0) with 0 + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + fstp %st(0) / y , x , y , x + ja .merge / x > 0 + / x < 0 + call .y_is_int + cmpl $0,%ecx + jne 1f + / x < 0 & y != int so x**y = NaN (i flag) + fstp %st(0) / x , y , x + fstp %st(0) / y , x + fstp %st(0) / y , x + fstp %st(0) / y , x + fldz + fdiv %st,%st(0) / 0/0 + ret + +1: / x < 0 & y = int + fxch / x , y , y , x + fchs / px = -x , y , y , x + fxch / y , px , y , x +.merge: + / px > 0 + fxch / px , y , y , x + + / x**y = exp(y*ln(x)) + fyl2x / t=y*log2(px) , y , x + fld %st(0) / t , t , y , x + frndint / [t] , t , y , x + fxch / t , [t] , y , x + fucom + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + je 1f / px = int + fsub %st(1),%st / t-[t] , [t] , y , x + f2xm1 / 2**(t-[t])-1 , [t] , y , x + fadds PIC_L(one) / 2**(t-[t]) , [t] , y , x + fscale / 2**t = px**y , [t] , y , x + jmp 2f +1: + fstp %st(0) / t=[t] , y , x + fld1 / 1 , t , y , x + fscale / 1*2**t = x**y , t , y , x +2: + fstp %st(1) / x**y , y , x + cmpl $1,%ecx + jne .signok + fchs / change sign since x<0 & y=-int +.signok: + subl $4,%esp + fstps (%esp) / round to single precision + flds (%esp) / place result on NPX stack + addl $4,%esp + fstp %st(2) / y , x**y + fstp %st(0) / x**y + ret + +/ ------------------------------------------------------------------------ + +.xispinf: + ftst / compare %st(0) with 0 + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + ja .retpinf / y > 0 + jmp .retpzero / y < 0 + +.xisninf: + / -inf ** +-y is -0 ** -+y + fchs / -y , x + flds PIC_L(negzero) / -0 , -y , x + fstp %st(2) / -y , -0 + jmp .xisnzero + +.yispinf: + fld %st(1) / x , y , x + fabs / |x| , y , x + fcomps PIC_L(one) / y , x + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + je .retponeorinvalid / x == -1 C99 + ja .retpinf / |x| > 1 + jmp .retpzero / |x| < 1 + +.yisninf: + fld %st(1) / x , y , x + fabs / |x| , y , x + fcomps PIC_L(one) / y , x + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + je .retponeorinvalid / x == -1 C99 + ja .retpzero / |x| > 1 + jmp .retpinf / |x| < 1 + +.xispzero: + / y cannot be 0 or NaN ; stack has y , x + ftst / compare %st(0) with 0 + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + ja .retpzero / y > 0 + / x = +0 & y < 0 so x**y = +inf + jmp .retpinfzflag / ret +inf & z flag + +.xisnzero: + / y cannot be 0 or NaN ; stack has y , x + call .y_is_int + cmpl $1,%ecx + jne 1f / y is not an odd integer + / y is an odd integer + ftst / compare %st(0) with 0 + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + ja .retnzero / y > 0 + / x = -0 & y < 0 (odd int) return -inf (z flag) + / x = -inf & y != 0 or NaN return -inf (NO z flag) + movb %dh,%cl + andb $0x45,%cl + cmpb $0x05,%cl / C3=0 C2=1 C1=? C0=1 when +-inf + je 2f + fdiv %st,%st(1) / y / x, x (raise z flag) +2: + fstp %st(0) / x + fstp %st(0) / stack empty + flds PIC_L(ninfinity) / -inf + ret + +1: / y is not an odd integer + ftst / compare %st(0) with 0 + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + ja .retpzero / y > 0 + / x = -0 & y < 0 (not odd int) return +inf (z flag) + / x = -inf & y not 0 or NaN return +inf (NO z flag) + movb %dh,%cl + andb $0x45,%cl + cmpb $0x05,%cl / C3=0 C2=1 C1=? C0=1 when +-inf + jne .retpinfzflag / ret +inf & divide-by-0 flag + jmp .retpinf / return +inf (NO z flag) + +.retpzero: + fstp %st(0) / x + fstp %st(0) / stack empty + fldz / +0 + ret + +.retnzero: + fstp %st(0) / x + fstp %st(0) / stack empty + flds PIC_L(negzero) / -0 + ret + +.retponeorinvalid: + PIC_G_LOAD(movzwl,__xpg6,eax) + andl $_C99SUSv3_pow_treats_Inf_as_an_even_int,%eax + cmpl $0,%eax + je 1f + fstp %st(0) / x + fstp %st(0) / stack empty + fld1 / 1 + ret + +1: + fstp %st(0) / x + fstp %st(0) / stack empty + flds PIC_L(Snan) / Q NaN (i flag) + fwait + ret + +.retpinf: + fstp %st(0) / x + fstp %st(0) / stack empty + flds PIC_L(pinfinity) / +inf + ret + +.retpinfzflag: + fstp %st(0) / x + fstp %st(0) / stack empty + fldz + fdivrs PIC_L(one) / 1/0 + ret + +/ Set %ecx to 2 if y is an even integer, 1 if y is an odd integer, +/ 0 otherwise. Assume y is not zero. Do not raise inexact or modify +/ %edx. +.y_is_int: + movl 12(%ebp),%eax + andl $0x7fffffff,%eax / |y| + cmpl $0x4b800000,%eax + jae 1f / |y| >= 2^24, an even int + cmpl $0x3f800000,%eax + jb 2f / |y| < 1, can't be an int + movl %eax,%ecx + sarl $23,%ecx + subl $150,%ecx + negl %ecx / 23 - unbiased exponent of y + bsfl %eax,%eax / index of least sig. 1 bit + cmpl %ecx,%eax + jb 2f + ja 1f + movl $1,%ecx + ret +1: + movl $2,%ecx + ret +2: + xorl %ecx,%ecx + ret + .align 4 + SET_SIZE(powf) diff --git a/usr/src/lib/libm/i386/src/powl.s b/usr/src/lib/libm/i386/src/powl.s new file mode 100644 index 0000000000..f20f0f4411 --- /dev/null +++ b/usr/src/lib/libm/i386/src/powl.s @@ -0,0 +1,440 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "powl.s" + +/ Special cases: +/ +/ x ** 0 is 1 +/ 1 ** y is 1 (C99) +/ x ** NaN is NaN +/ NaN ** y (except 0) is NaN +/ x ** 1 is x +/ +-(|x| > 1) ** +inf is +inf +/ +-(|x| > 1) ** -inf is +0 +/ +-(|x| < 1) ** +inf is +0 +/ +-(|x| < 1) ** -inf is +inf +/ (-1) ** +-inf is +1 (C99) +/ +0 ** +y (except 0, NaN) is +0 +/ -0 ** +y (except 0, NaN, odd int) is +0 +/ +0 ** -y (except 0, NaN) is +inf (z flag) +/ -0 ** -y (except 0, NaN, odd int) is +inf (z flag) +/ -0 ** y (odd int) is - (+0 ** x) +/ +inf ** +y (except 0, NaN) is +inf +/ +inf ** -y (except 0, NaN) is +0 +/ -inf ** +-y (except 0, NaN) is -0 ** -+y (NO z flag) +/ x ** -1 is 1/x +/ x ** 2 is x*x +/ -x ** y (an integer) is (-1)**(y) * (+x)**(y) +/ x ** y (x negative & y not integer) is NaN (i flag) + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(powl,function) +#include "libm_synonyms.h" +#include "xpg6.h" + +#undef fabs + + .data + .align 4 +negzero: + .float -0.0 +half: + .float 0.5 +one: + .float 1.0 +negone: + .float -1.0 +two: + .float 2.0 +Snan: + .long 0x7f800001 +pinfinity: + .long 0x7f800000 +ninfinity: + .long 0xff800000 + + + ENTRY(powl) + pushl %ebp + movl %esp,%ebp + PIC_SETUP(1) + + fldt 8(%ebp) / x + fxam / determine class of x + fnstsw %ax / store status in %ax + movb %ah,%dh / %dh <- condition code of x + + fldt 20(%ebp) / y , x + fxam / determine class of y + fnstsw %ax / store status in %ax + movb %ah,%dl / %dl <- condition code of y + + call .pow_main /// LOCAL + PIC_WRAPUP + leave + ret + +.pow_main: + / x ** 0 is 1 + movb %dl,%cl + andb $0x45,%cl + cmpb $0x40,%cl / C3=1 C2=0 C1=? C0=0 when +-0 + jne 1f + fstp %st(0) / x + fstp %st(0) / stack empty + fld1 / 1 + ret + +1: / y is not zero + PIC_G_LOAD(movzwl,__xpg6,eax) + andl $_C99SUSv3_pow_treats_Inf_as_an_even_int,%eax + cmpl $0,%eax + je 1f + + / C99: 1 ** anything is 1 + fld1 / 1, y, x + fucomp %st(2) / y, x + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + jp 1f / so that pow(NaN1,NaN2) returns NaN2 + jne 1f + fstp %st(0) / x + ret + +1: + / x ** NaN is NaN + movb %dl,%cl + andb $0x45,%cl + cmpb $0x01,%cl / C3=0 C2=0 C1=? C0=1 when +-NaN + jne 1f + fstp %st(1) / y + ret + +1: / y is not NaN + / NaN ** y (except 0) is NaN + movb %dh,%cl + andb $0x45,%cl + cmpb $0x01,%cl / C3=0 C2=0 C1=? C0=1 when +-NaN + jne 1f + fstp %st(0) / x + ret + +1: / x is not NaN + / x ** 1 is x + fcoms PIC_L(one) / y , x + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + jne 1f + fstp %st(0) / x + ret + +1: / y is not 1 + / +-(|x| > 1) ** +inf is +inf + / +-(|x| > 1) ** -inf is +0 + / +-(|x| < 1) ** +inf is +0 + / +-(|x| < 1) ** -inf is +inf + / +-(|x| = 1) ** +-inf is NaN + movb %dl,%cl + andb $0x47,%cl + cmpb $0x05,%cl / C3=0 C2=1 C1=0 C0=1 when +inf + je .yispinf + cmpb $0x07,%cl / C3=0 C2=1 C1=1 C0=1 when -inf + je .yisninf + + / +0 ** +y (except 0, NaN) is +0 + / -0 ** +y (except 0, NaN, odd int) is +0 + / +0 ** -y (except 0, NaN) is +inf (z flag) + / -0 ** -y (except 0, NaN, odd int) is +inf (z flag) + / -0 ** y (odd int) is - (+0 ** x) + movb %dh,%cl + andb $0x47,%cl + cmpb $0x40,%cl / C3=1 C2=0 C1=0 C0=0 when +0 + je .xispzero + cmpb $0x42,%cl / C3=1 C2=0 C1=1 C0=0 when -0 + je .xisnzero + + / +inf ** +y (except 0, NaN) is +inf + / +inf ** -y (except 0, NaN) is +0 + / -inf ** +-y (except 0, NaN) is -0 ** -+y (NO z flag) + movb %dh,%cl + andb $0x47,%cl + cmpb $0x05,%cl / C3=0 C2=1 C1=0 C0=1 when +inf + je .xispinf + cmpb $0x07,%cl / C3=0 C2=1 C1=1 C0=1 when -inf + je .xisninf + + / x ** -1 is 1/x + fcoms PIC_L(negone) / y , x + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + jne 1f + fld %st(1) / x , y , x + fdivrs PIC_L(one) / 1/x , y , x + jmp .signok / check for over/underflow + +1: / y is not -1 + / x ** 2 is x*x + fcoms PIC_L(two) / y , x + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + jne 1f + fld %st(1) / x , y , x + fld %st(0) / x , x , y , x + fmulp / x^2 , y , x + jmp .signok / check for over/underflow + +1: / y is not 2 + / x ** 1/2 is sqrt(x) + fcoms PIC_L(half) / y , x + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + jne 1f + fld %st(1) / x , y , x + fsqrt / sqrt(x) , y , x + jmp .signok / check for over/underflow + +1: / y is not 1/2 + / make copies of x & y + fld %st(1) / x , y , x + fld %st(1) / y , x , y , x + + / -x ** y (an integer) is (-1)**(y) * (+x)**(y) + / x ** y (x negative & y not integer) is NaN + movl $0,%ecx / track whether to flip sign of result + fld %st(1) / x , y , x , y , x + ftst / compare %st(0) with 0 + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + fstp %st(0) / y , x , y , x + ja .merge / x > 0 + / x < 0 + call .y_is_int + cmpl $0,%ecx + jne 1f + / x < 0 & y != int so x**y = NaN (i flag) + fstp %st(0) / x , y , x + fstp %st(0) / y , x + fstp %st(0) / x + fstp %st(0) / stack empty + fldz + fdiv %st,%st(0) / 0/0 + ret + +1: / x < 0 & y = int + fxch / x , y , y , x + fchs / px = -x , y , y , x + fxch / y , px , y , x +.merge: + / px > 0 + fxch / px , y , y , x + + / x**y = exp(y*ln(x)) + fyl2x / t=y*log2(px) , y , x + fld %st(0) / t , t , y , x + frndint / [t] , t , y , x + fxch / t , [t] , y , x + fucom + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + je 1f / t is integral + fsub %st(1),%st / t-[t] , [t] , y , x + f2xm1 / 2**(t-[t])-1 , [t] , y , x + fadds PIC_L(one) / 2**(t-[t]) , [t] , y , x + fscale / 2**t = px**y , [t] , y , x + jmp 2f +1: + fstp %st(0) / t=[t] , y , x + fld1 / 1 , t , y , x + fscale / 1*2**t = x**y , t , y , x +2: + fstp %st(1) / x**y , y , x + cmpl $1,%ecx + jne .signok + fchs / change sign since x<0 & y=-int +.signok: + fstp %st(2) / y , x**y + fstp %st(0) / x**y + ret + +/ ------------------------------------------------------------------------ + +.xispinf: + ftst / compare %st(0) with 0 + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + ja .retpinf / y > 0 + jmp .retpzero / y < 0 + +.xisninf: + / -inf ** +-y is -0 ** -+y + fchs / -y , x + flds PIC_L(negzero) / -0 , -y , x + fstp %st(2) / -y , -0 + jmp .xisnzero + +.yispinf: + fld %st(1) / x , y , x + fabs / |x| , y , x + fcomps PIC_L(one) / y , x + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + je .retponeorinvalid / x == -1 C99 + ja .retpinf / |x| > 1 + jmp .retpzero / |x| < 1 + +.yisninf: + fld %st(1) / x , y , x + fabs / |x| , y , x + fcomps PIC_L(one) / y , x + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + je .retponeorinvalid / x == -1 C99 + ja .retpzero / |x| > 1 + jmp .retpinf / |x| < 1 + +.xispzero: + / y cannot be 0 or NaN ; stack has y , x + ftst / compare %st(0) with 0 + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + ja .retpzero / y > 0 + / x = +0 & y < 0 so x**y = +inf + jmp .retpinfzflag / ret +inf & z flag + +.xisnzero: + / y cannot be 0 or NaN ; stack has y , x + call .y_is_int + cmpl $1,%ecx + jne 1f / y is not an odd integer + / y is an odd integer + ftst / compare %st(0) with 0 + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + ja .retnzero / y > 0 + / x = -0 & y < 0 (odd int) return -inf (z flag) + / x = -inf & y != 0 or NaN return -inf (NO z flag) + movb %dh,%cl + andb $0x45,%cl + cmpb $0x05,%cl / C3=0 C2=1 C1=? C0=1 when +-inf + je 2f + fdiv %st,%st(1) / y / x, x (raise z flag) +2: + fstp %st(0) / x + fstp %st(0) / stack empty + flds PIC_L(ninfinity) / -inf + ret + +1: / y is not an odd integer + ftst / compare %st(0) with 0 + fnstsw %ax / store status in %ax + sahf / 80387 flags in %ax to 80386 flags + ja .retpzero / y > 0 + / x = -0 & y < 0 (not odd int) return +inf (z flag) + / x = -inf & y not 0 or NaN return +inf (NO z flag) + movb %dh,%cl + andb $0x45,%cl + cmpb $0x05,%cl / C3=0 C2=1 C1=? C0=1 when +-inf + jne .retpinfzflag / ret +inf & divide-by-0 flag + jmp .retpinf / return +inf (NO z flag) + +.retpzero: + fstp %st(0) / x + fstp %st(0) / stack empty + fldz / +0 + ret + +.retnzero: + fstp %st(0) / x + fstp %st(0) / stack empty + flds PIC_L(negzero) / -0 + ret + +.retponeorinvalid: + PIC_G_LOAD(movzwl,__xpg6,eax) + andl $_C99SUSv3_pow_treats_Inf_as_an_even_int,%eax + cmpl $0,%eax + je 1f + fstp %st(0) / x + fstp %st(0) / stack empty + fld1 / 1 + ret + +1: + fstp %st(0) / x + fstp %st(0) / stack empty + flds PIC_L(Snan) / Q NaN (i flag) + fwait + ret + +.retpinf: + fstp %st(0) / x + fstp %st(0) / stack empty + flds PIC_L(pinfinity) / +inf + ret + +.retpinfzflag: + fstp %st(0) / x + fstp %st(0) / stack empty + fldz + fdivrs PIC_L(one) / 1/0 + ret + +/ Set %ecx to 2 if y is an even integer, 1 if y is an odd integer, +/ 0 otherwise. Assume y is not zero. Do not raise inexact or modify +/ %edx. +.y_is_int: + movl 28(%ebp),%eax + andl $0x7fff,%eax / exponent of y + cmpl $0x403f,%eax + jae 1f / |y| >= 2^64, an even int + cmpl $0x3fff,%eax + jb 2f / |y| < 1, can't be an int + movl %eax,%ecx + subl $0x403e,%ecx + negl %ecx / 63 - unbiased exponent of y + movl 20(%ebp),%eax + bsfl %eax,%eax / index of least sig. 1 bit + jne 3f / jump if 1 bit found + movl 24(%ebp),%eax + bsfl %eax,%eax + addl $32,%eax / 32 + index of least sig. 1 bit +3: + cmpl %ecx,%eax + jb 2f + ja 1f + movl $1,%ecx + ret +1: + movl $2,%ecx + ret +2: + xorl %ecx,%ecx + ret + .align 4 + SET_SIZE(powl) diff --git a/usr/src/lib/libm/i386/src/remainder.s b/usr/src/lib/libm/i386/src/remainder.s new file mode 100644 index 0000000000..5b651c3b21 --- /dev/null +++ b/usr/src/lib/libm/i386/src/remainder.s @@ -0,0 +1,82 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "remainder.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(remainder,function) +#include "libm_synonyms.h" +#include "libm_protos.h" + + ENTRY(remainder) + pushl %ebp + movl %esp,%ebp + fldl 16(%esp) / load arg y + fldl 8(%esp) / load arg x + fucom + fnstsw %ax + sahf + jp .rem_loop / if x or y is NaN, use fprem1 + + movl 20(%esp),%eax / eax <-- hi_32(y) + andl $0x7fffffff,%eax / eax <-- hi_32(|y|) + orl 16(%esp),%eax / eax <-- lo_32(y)|hi_32(|y|) + je .yzero_or_xinf + + movl 12(%esp),%eax / eax <-- hi_32(x) + andl $0x7fffffff,%eax / eax <-- hi_32(|x|) + cmpl $0x7ff00000,%eax + jne .rem_loop + cmpl $0,8(%esp) + je .yzero_or_xinf + +.rem_loop: + fprem1 / partial remainder + fstsw %ax / store status word + andw $0x400,%ax / check for incomplete reduction + jne .rem_loop / while incomplete, do fprem1 again + fstp %st(1) + leave + ret + +.yzero_or_xinf: + PIC_SETUP(1) + fstp %st(0) / x + fstp %st(0) / empty NPX stack + pushl $28 / case 28 in _SVID_libm_err + pushl 20(%ebp) / pass y + pushl 16(%ebp) + pushl 12(%ebp) / pass x + pushl 8(%ebp) + call PIC_F(_SVID_libm_err) + addl $20,%esp + PIC_WRAPUP + leave + ret + .align 4 + SET_SIZE(remainder) diff --git a/usr/src/lib/libm/i386/src/remainderf.s b/usr/src/lib/libm/i386/src/remainderf.s new file mode 100644 index 0000000000..2529903e58 --- /dev/null +++ b/usr/src/lib/libm/i386/src/remainderf.s @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "remainderf.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(remainderf,function) +#include "libm_synonyms.h" + + ENTRY(remainderf) + flds 8(%esp) / load arg y + flds 4(%esp) / load arg x +.rem_loop: + fprem1 / partial remainder + fstsw %ax / store status word + andw $0x400,%ax / check whether reduction complete + jne .rem_loop / while reduction incomplete, do fprem1 + fstp %st(1) + ret + .align 4 + SET_SIZE(remainderf) diff --git a/usr/src/lib/libm/i386/src/remainderl.s b/usr/src/lib/libm/i386/src/remainderl.s new file mode 100644 index 0000000000..84191d4ff5 --- /dev/null +++ b/usr/src/lib/libm/i386/src/remainderl.s @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "remainderl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(remainderl,function) +#include "libm_synonyms.h" + + ENTRY(remainderl) + fldt 16(%esp) / load arg y + fldt 4(%esp) / load arg x +.rem_loop: + fprem1 / partial remainder + fstsw %ax / store status word + andw $0x400,%ax / check whether reduction complete + jne .rem_loop / while reduction incomplete, do fprem1 + fstp %st(1) + ret + .align 4 + SET_SIZE(remainderl) diff --git a/usr/src/lib/libm/i386/src/remquo.s b/usr/src/lib/libm/i386/src/remquo.s new file mode 100644 index 0000000000..81c03b8451 --- /dev/null +++ b/usr/src/lib/libm/i386/src/remquo.s @@ -0,0 +1,70 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "remquo.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(remquo,function) +#include "libm_synonyms.h" +#include "libm_protos.h" + + ENTRY(remquo) + fldl 12(%esp) / load arg y + fldl 4(%esp) / load arg x +.Lrem_loop: + fprem1 / partial remainder + fstsw %ax / store status word + andw $0x400,%ax / check whether reduction complete + jne .Lrem_loop / while reduction incomplete, do fprem1 + fstsw %ax + fwait + fstp %st(1) + movw %ax,%dx + andw $0x4000,%dx / get C3 + sarw $13,%dx + movw %ax,%cx + andw $0x100,%cx / get C0 + sarw $6,%cx + addw %cx,%dx + andw $0x200,%ax / get C1 + sarw $9,%ax + addw %dx,%ax + cwtl + movl 8(%esp),%edx / sign and bexp of x + movl 16(%esp),%ecx / sign and bexp of y + andl $0x80000000,%edx / edx <- sign(x) + andl $0x80000000,%ecx / ecx <- sign(y) + cmpl %edx,%ecx + je .pos + negl %eax / negative n +.pos: + movl 20(%esp),%ecx + movl %eax,0(%ecx) / last 3 significant bits of quotient + ret + .align 4 + SET_SIZE(remquo) diff --git a/usr/src/lib/libm/i386/src/remquof.s b/usr/src/lib/libm/i386/src/remquof.s new file mode 100644 index 0000000000..787a7c1d11 --- /dev/null +++ b/usr/src/lib/libm/i386/src/remquof.s @@ -0,0 +1,70 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "remquof.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(remquof,function) +#include "libm_synonyms.h" +#include "libm_protos.h" + + ENTRY(remquof) + flds 8(%esp) / load arg y + flds 4(%esp) / load arg x +.Lremf_loop: + fprem1 / partial remainder + fstsw %ax / store status word + andw $0x400,%ax / check whether reduction complete + jne .Lremf_loop / while reduction incomplete, do fprem1 + fstsw %ax + fwait + fstp %st(1) + movw %ax,%dx + andw $0x4000,%dx / get C3 + sarw $13,%dx + movw %ax,%cx + andw $0x100,%cx / get C0 + sarw $6,%cx + addw %cx,%dx + andw $0x200,%ax / get C1 + sarw $9,%ax + addw %dx,%ax + cwtl + movl 4(%esp),%edx / sign and bexp of x + movl 8(%esp),%ecx / sign and bexp of y + andl $0x80000000,%edx / edx <- sign(x) + andl $0x80000000,%ecx / ecx <- sign(y) + cmpl %edx,%ecx + je .pos + negl %eax / negative n +.pos: + movl 12(%esp),%ecx + movl %eax,0(%ecx) / last 3 significant bits of quotient + ret + .align 4 + SET_SIZE(remquof) diff --git a/usr/src/lib/libm/i386/src/remquol.s b/usr/src/lib/libm/i386/src/remquol.s new file mode 100644 index 0000000000..86d0f40677 --- /dev/null +++ b/usr/src/lib/libm/i386/src/remquol.s @@ -0,0 +1,70 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "remquol.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(remquol,function) +#include "libm_synonyms.h" +#include "libm_protos.h" + + ENTRY(remquol) + fldt 16(%esp) / load arg y + fldt 4(%esp) / load arg x +.Lreml_loop: + fprem1 / partial remainder + fstsw %ax / store status word + andw $0x400,%ax / check whether reduction complete + jne .Lreml_loop / while reduction incomplete, do fprem1 + fstsw %ax + fwait + fstp %st(1) + movw %ax,%dx + andw $0x4000,%dx / get C3 + sarw $13,%dx + movw %ax,%cx + andw $0x100,%cx / get C0 + sarw $6,%cx + addw %cx,%dx + andw $0x200,%ax / get C1 + sarw $9,%ax + addw %dx,%ax + cwtl + movl 12(%esp),%edx / sign and bexp of x + movl 24(%esp),%ecx / sign and bexp of y + andl $0x00008000,%edx / edx <- sign(x) + andl $0x00008000,%ecx / ecx <- sign(y) + cmpl %edx,%ecx + je .pos + negl %eax / negative n +.pos: + movl 28(%esp),%ecx + movl %eax,0(%ecx) / last 3 significant bits of quotient + ret + .align 4 + SET_SIZE(remquol) diff --git a/usr/src/lib/libm/i386/src/rint.s b/usr/src/lib/libm/i386/src/rint.s new file mode 100644 index 0000000000..0395ee7ecb --- /dev/null +++ b/usr/src/lib/libm/i386/src/rint.s @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "rint.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(rint,function) +#include "libm_synonyms.h" + + ENTRY(rint) + fldl 4(%esp) / load x + movl 8(%esp),%eax / eax <-- hi_32(x) + andl $0x7fffffff,%eax / eax <-- hi_32(|x|) + cmpl $0x43300000,%eax / is |x| >= 2**52? + jae .done / if so, branch (already integral) + frndint / [x], per rounding mode +.done: + fwait + ret + .align 4 + SET_SIZE(rint) diff --git a/usr/src/lib/libm/i386/src/rintf.s b/usr/src/lib/libm/i386/src/rintf.s new file mode 100644 index 0000000000..58eafe6c2b --- /dev/null +++ b/usr/src/lib/libm/i386/src/rintf.s @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "rintf.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(rintf,function) +#include "libm_synonyms.h" + + ENTRY(rintf) + flds 4(%esp) / load x + movl 4(%esp),%eax / eax <-- x + andl $0x7fffffff,%eax / eax <-- |x| + cmpl $0x4b000000,%eax / is |x| >= 2**23? + jae .done / if so, branch (already integral) + frndint / [x], per rounding mode +.done: + fwait + ret + .align 4 + SET_SIZE(rintf) diff --git a/usr/src/lib/libm/i386/src/rintl.s b/usr/src/lib/libm/i386/src/rintl.s new file mode 100644 index 0000000000..c967d1a12d --- /dev/null +++ b/usr/src/lib/libm/i386/src/rintl.s @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "rintl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(rintl,function) +#include "libm_synonyms.h" + + ENTRY(rintl) + fldt 4(%esp) / load x + frndint / [x], per rounding mode + fwait + ret + .align 4 + SET_SIZE(rintl) diff --git a/usr/src/lib/libm/i386/src/rndintl.s b/usr/src/lib/libm/i386/src/rndintl.s new file mode 100644 index 0000000000..80a3676397 --- /dev/null +++ b/usr/src/lib/libm/i386/src/rndintl.s @@ -0,0 +1,150 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "rndintl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(aintl,function) +LIBM_ANSI_PRAGMA_WEAK(irintl,function) +LIBM_ANSI_PRAGMA_WEAK(anintl,function) +LIBM_ANSI_PRAGMA_WEAK(nintl,function) +#include "libm_synonyms.h" +#undef fabs + + ENTRY(aintl) + movl %esp,%eax + subl $8,%esp + fstcw -8(%eax) + fldt 4(%eax) + movw -8(%eax),%cx + orw $0x0c00,%cx + movw %cx,-4(%eax) + fldcw -4(%eax) / set RD = to_zero + frndint + fstcw -4(%eax) + movw -4(%eax),%dx + andw $0xf3ff,%dx + movw -8(%eax),%cx + andw $0x0c00,%cx + orw %dx,%cx + movw %cx,-8(%eax) + fldcw -8(%eax) / restore RD + addl $8,%esp + ret + .align 4 + SET_SIZE(aintl) + + ENTRY(irintl) + movl %esp,%ecx + subl $8,%esp + fldt 4(%ecx) / load x + fistpl -8(%ecx) / [x] + fwait + movl -8(%ecx),%eax + addl $8,%esp + ret + .align 4 + SET_SIZE(irintl) + + .data + .align 4 +half: .float 0.5 + + ENTRY(anintl) +.Lanintl: + movl %esp,%ecx + subl $8,%esp + fstcw -8(%ecx) + fldt 4(%ecx) + movw -8(%ecx),%dx + andw $0xf3ff,%dx + movw %dx,-4(%ecx) + fldcw -4(%ecx) / set RD = to_nearest + fld %st(0) + frndint / [x],x + fstcw -4(%ecx) + movw -4(%ecx),%dx + andw $0xf3ff,%dx + movw -8(%ecx),%ax + andw $0x0c00,%ax + orw %dx,%ax + movw %ax,-8(%ecx) + fldcw -8(%ecx) / restore RD + fucom / check if x is already an integer + fstsw %ax + sahf + jp .L0 + je .L0 + fxch / x,[x] + fsub %st(1),%st / x-[x],[x] + fabs / |x-[x]|,[x] + PIC_SETUP(1) + fcoms PIC_L(half) + PIC_WRAPUP + fnstsw %ax + sahf + jae .halfway / if |x-[x]| = 0.5 goto halfway, + / most cases will not take branch. +.L0: + addl $8,%esp + fstp %st(0) + ret +.halfway: + / x = n+0.5, recompute anint(x) as x+sign(x)*0.5 + fldt 4(%ecx) / x, 0.5, [x] + movw 12(%ecx),%ax / sign+exp part of x + andw $0x8000,%ax / look at sign bit + jnz .x_neg + faddp + addl $8,%esp + fstp %st(1) + ret +.x_neg: + / here, x is negative, so return x-0.5 + fsubp %st,%st(1) / x-0.5,[x] + addl $8,%esp + fstp %st(1) + ret + .align 4 + SET_SIZE(anintl) + + ENTRY(nintl) + pushl %ebp + movl %esp,%ebp + subl $8,%esp + pushl 16(%ebp) + pushl 12(%ebp) + pushl 8(%ebp) + call .Lanintl /// LOCAL + fistpl -8(%ebp) + fwait + movl -8(%ebp),%eax + leave + ret + .align 4 + SET_SIZE(nintl) diff --git a/usr/src/lib/libm/i386/src/round.s b/usr/src/lib/libm/i386/src/round.s new file mode 100644 index 0000000000..32923221b3 --- /dev/null +++ b/usr/src/lib/libm/i386/src/round.s @@ -0,0 +1,95 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "round.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(round,function) +#include "libm_synonyms.h" +#undef fabs + + .section .rodata + .align 4 +.Lhalf: .float 0.5 + + ENTRY(round) + movl %esp,%ecx + subl $8,%esp + fstcw -8(%ecx) + fldl 4(%ecx) + movw -8(%ecx),%dx + andw $0xf3ff,%dx + movw %dx,-4(%ecx) + fldcw -4(%ecx) / set RD = to_nearest + fld %st(0) + frndint / [x],x + fstcw -4(%ecx) + movw -4(%ecx),%dx + andw $0xf3ff,%dx + movw -8(%ecx),%ax + andw $0x0c00,%ax + orw %dx,%ax + movw %ax,-8(%ecx) + fldcw -8(%ecx) / restore RD + fucom / check if x is already an integer + fstsw %ax + sahf + jp 0f + je 0f + fxch / x,[x] + fsub %st(1),%st / x-[x],[x] + fabs / |x-[x]|,[x] + PIC_SETUP(1) + fcoms PIC_L(.Lhalf) + PIC_WRAPUP + fnstsw %ax + sahf + jae 2f / if |x-[x]| = 0.5 goto halfway, + / most cases will not take branch. +0: + addl $8,%esp + fstp %st(0) + ret +2: + / x = n+0.5, recompute round(x) as x+sign(x)*0.5 + fldl 4(%ecx) / x, 0.5, [x] + movl 8(%ecx),%eax / high part of x + andl $0x80000000,%eax + jnz 3f + faddp + addl $8,%esp + fstp %st(1) + ret +3: + / here, x is negative, so return x-0.5 + fsubp %st,%st(1) / x-0.5,[x] + addl $8,%esp + fstp %st(1) + ret + .align 4 + SET_SIZE(round) diff --git a/usr/src/lib/libm/i386/src/roundl.s b/usr/src/lib/libm/i386/src/roundl.s new file mode 100644 index 0000000000..1db4133245 --- /dev/null +++ b/usr/src/lib/libm/i386/src/roundl.s @@ -0,0 +1,95 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "roundl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(roundl,function) +#include "libm_synonyms.h" +#undef fabs + + .section .rodata + .align 4 +.Lhalf: .float 0.5 + + ENTRY(roundl) + movl %esp,%ecx + subl $8,%esp + fstcw -8(%ecx) + fldt 4(%ecx) + movw -8(%ecx),%dx + andw $0xf3ff,%dx + movw %dx,-4(%ecx) + fldcw -4(%ecx) / set RD = to_nearest + fld %st(0) + frndint / [x],x + fstcw -4(%ecx) + movw -4(%ecx),%dx + andw $0xf3ff,%dx + movw -8(%ecx),%ax + andw $0x0c00,%ax + orw %dx,%ax + movw %ax,-8(%ecx) + fldcw -8(%ecx) / restore RD + fucom / check if x is already an integer + fstsw %ax + sahf + jp 0f + je 0f + fxch / x,[x] + fsub %st(1),%st / x-[x],[x] + fabs / |x-[x]|,[x] + PIC_SETUP(1) + fcoms PIC_L(.Lhalf) + PIC_WRAPUP + fnstsw %ax + sahf + jae 2f / if |x-[x]| = 0.5 goto halfway, + / most cases will not take branch. +0: + addl $8,%esp + fstp %st(0) + ret +2: + / x = n+0.5, recompute roundl(x) as x+sign(x)*0.5 + fldt 4(%ecx) / x, 0.5, [x] + movw 12(%ecx),%ax / sign+exp of x + andw $0x8000,%ax / look at sign bit + jnz 3f + faddp + addl $8,%esp + fstp %st(1) + ret +3: + / here, x is negative, so return x-0.5 + fsubp %st,%st(1) / x-0.5,[x] + addl $8,%esp + fstp %st(1) + ret + .align 4 + SET_SIZE(roundl) diff --git a/usr/src/lib/libm/i386/src/scalbln.s b/usr/src/lib/libm/i386/src/scalbln.s new file mode 100644 index 0000000000..62e016ab3c --- /dev/null +++ b/usr/src/lib/libm/i386/src/scalbln.s @@ -0,0 +1,42 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "scalbln.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(scalbln,function) +#include "libm_synonyms.h" + + ENTRY(scalbln) + fildl 12(%esp) / convert N to extended + fldl 4(%esp) / push x + fscale + fstp %st(1) + ret + .align 4 + SET_SIZE(scalbln) diff --git a/usr/src/lib/libm/i386/src/scalblnf.s b/usr/src/lib/libm/i386/src/scalblnf.s new file mode 100644 index 0000000000..a3d34bb404 --- /dev/null +++ b/usr/src/lib/libm/i386/src/scalblnf.s @@ -0,0 +1,42 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "scalblnf.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(scalblnf,function) +#include "libm_synonyms.h" + + ENTRY(scalblnf) + fildl 8(%esp) / convert N to extended + flds 4(%esp) / push x + fscale + fstp %st(1) + ret + .align 4 + SET_SIZE(scalblnf) diff --git a/usr/src/lib/libm/i386/src/scalblnl.s b/usr/src/lib/libm/i386/src/scalblnl.s new file mode 100644 index 0000000000..b166e31efa --- /dev/null +++ b/usr/src/lib/libm/i386/src/scalblnl.s @@ -0,0 +1,43 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "scalblnl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(scalblnl,function) +#include "libm_synonyms.h" + + ENTRY(scalblnl) + fildl 16(%esp) / convert 32-bit integer N + / to extended-double + fldt 4(%esp) / push x + fscale + fstp %st(1) + ret + .align 4 + SET_SIZE(scalblnl) diff --git a/usr/src/lib/libm/i386/src/scalbn.s b/usr/src/lib/libm/i386/src/scalbn.s new file mode 100644 index 0000000000..270e61d30e --- /dev/null +++ b/usr/src/lib/libm/i386/src/scalbn.s @@ -0,0 +1,42 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "scalbn.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(scalbn,function) +#include "libm_synonyms.h" + + ENTRY(scalbn) + fildl 12(%esp) / convert N to extended + fldl 4(%esp) / push x + fscale + fstp %st(1) + ret + .align 4 + SET_SIZE(scalbn) diff --git a/usr/src/lib/libm/i386/src/scalbnf.s b/usr/src/lib/libm/i386/src/scalbnf.s new file mode 100644 index 0000000000..525b832eee --- /dev/null +++ b/usr/src/lib/libm/i386/src/scalbnf.s @@ -0,0 +1,42 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "scalbnf.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(scalbnf,function) +#include "libm_synonyms.h" + + ENTRY(scalbnf) + fildl 8(%esp) / convert N to extended + flds 4(%esp) / push x + fscale + fstp %st(1) + ret + .align 4 + SET_SIZE(scalbnf) diff --git a/usr/src/lib/libm/i386/src/scalbnl.s b/usr/src/lib/libm/i386/src/scalbnl.s new file mode 100644 index 0000000000..09dc73d997 --- /dev/null +++ b/usr/src/lib/libm/i386/src/scalbnl.s @@ -0,0 +1,43 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "scalbnl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(scalbnl,function) +#include "libm_synonyms.h" + + ENTRY(scalbnl) + fildl 16(%esp) / convert 32-bit integer N + / to extended-double + fldt 4(%esp) / push x + fscale + fstp %st(1) + ret + .align 4 + SET_SIZE(scalbnl) diff --git a/usr/src/lib/libm/i386/src/sin.s b/usr/src/lib/libm/i386/src/sin.s new file mode 100644 index 0000000000..57919836d1 --- /dev/null +++ b/usr/src/lib/libm/i386/src/sin.s @@ -0,0 +1,59 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "sin.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(sin,function) +#include "libm_synonyms.h" +#include "libm_protos.h" + + ENTRY(sin) + PIC_SETUP(1) + call PIC_F(__reduction) + PIC_WRAPUP + cmpl $1,%eax + jl .sin0 + je .sin1 + cmpl $2,%eax + je .sin2 + fcos + fchs + ret +.sin2: + fsin + fchs + ret +.sin1: + fcos + ret +.sin0: + fsin + ret + .align 4 + SET_SIZE(sin) diff --git a/usr/src/lib/libm/i386/src/sincos.s b/usr/src/lib/libm/i386/src/sincos.s new file mode 100644 index 0000000000..14acff1581 --- /dev/null +++ b/usr/src/lib/libm/i386/src/sincos.s @@ -0,0 +1,82 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "sincos.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(sincos,function) +#include "libm_synonyms.h" +#include "libm_protos.h" + + ENTRY(sincos) + PIC_SETUP(1) + call PIC_F(__reduction) + PIC_WRAPUP + fsincos + cmpl $1,%eax + jl .sincos0 + je .sincos1 + cmpl $2,%eax + je .sincos2 + / n=3 + fchs + movl 12(%esp),%eax + fstpl 0(%eax) + movl 16(%esp),%eax + fstpl 0(%eax) + fwait + ret +.sincos2: + / n=2 + fchs + movl 16(%esp),%eax + fstpl 0(%eax) + fchs + movl 12(%esp),%eax + fstpl 0(%eax) + fwait + ret +.sincos1: + / n=1 + movl 12(%esp),%eax + fstpl 0(%eax) + fchs + movl 16(%esp),%eax + fstpl 0(%eax) + fwait + ret +.sincos0: + / n=0 + movl 16(%esp),%eax + fstpl 0(%eax) + movl 12(%esp),%eax + fstpl 0(%eax) + fwait + ret + .align 4 + SET_SIZE(sincos) diff --git a/usr/src/lib/libm/i386/src/sqrtl.s b/usr/src/lib/libm/i386/src/sqrtl.s new file mode 100644 index 0000000000..05636173d0 --- /dev/null +++ b/usr/src/lib/libm/i386/src/sqrtl.s @@ -0,0 +1,40 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "sqrtl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(sqrtl,function) +#include "libm_synonyms.h" + + ENTRY(sqrtl) + fldt 4(%esp) + fsqrt + ret + .align 4 + SET_SIZE(sqrtl) diff --git a/usr/src/lib/libm/i386/src/tan.s b/usr/src/lib/libm/i386/src/tan.s new file mode 100644 index 0000000000..d3cdf08fc0 --- /dev/null +++ b/usr/src/lib/libm/i386/src/tan.s @@ -0,0 +1,52 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "tan.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(tan,function) +#include "libm_synonyms.h" +#include "libm_protos.h" + + ENTRY(tan) + PIC_SETUP(1) + call PIC_F(__reduction) + PIC_WRAPUP + andl $1,%eax + cmpl $0,%eax + je .tan1 + fptan + fdivp %st,%st(1) + fchs + ret +.tan1: + fptan + fstp %st(0) + ret + .align 4 + SET_SIZE(tan) diff --git a/usr/src/lib/libm/i386/src/trunc.s b/usr/src/lib/libm/i386/src/trunc.s new file mode 100644 index 0000000000..06a6973cf0 --- /dev/null +++ b/usr/src/lib/libm/i386/src/trunc.s @@ -0,0 +1,56 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "trunc.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(trunc,function) +#include "libm_synonyms.h" + + ENTRY(trunc) + movl %esp,%eax + subl $8,%esp + fstcw -8(%eax) + fldl 4(%eax) + movw -8(%eax),%cx + orw $0x0c00,%cx + movw %cx,-4(%eax) + fldcw -4(%eax) / set RD = to_zero + frndint + fstcw -4(%eax) + movw -4(%eax),%dx + andw $0xf3ff,%dx + movw -8(%eax),%cx + andw $0x0c00,%cx + orw %dx,%cx + movw %cx,-8(%eax) + fldcw -8(%eax) / restore RD + addl $8,%esp + ret + .align 4 + SET_SIZE(trunc) diff --git a/usr/src/lib/libm/i386/src/truncl.s b/usr/src/lib/libm/i386/src/truncl.s new file mode 100644 index 0000000000..11881ccabc --- /dev/null +++ b/usr/src/lib/libm/i386/src/truncl.s @@ -0,0 +1,56 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved. + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .file "truncl.s" + +#include "libm.h" +LIBM_ANSI_PRAGMA_WEAK(truncl,function) +#include "libm_synonyms.h" + + ENTRY(truncl) + movl %esp,%eax + subl $8,%esp + fstcw -8(%eax) + fldt 4(%eax) + movw -8(%eax),%cx + orw $0x0c00,%cx + movw %cx,-4(%eax) + fldcw -4(%eax) / set RD = to_zero + frndint + fstcw -4(%eax) + movw -4(%eax),%dx + andw $0xf3ff,%dx + movw -8(%eax),%cx + andw $0x0c00,%cx + orw %dx,%cx + movw %cx,-8(%eax) + fldcw -8(%eax) / restore RD + addl $8,%esp + ret + .align 4 + SET_SIZE(truncl) |