199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * CDDL HEADER START
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The contents of this file are subject to the terms of the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Common Development and Distribution License (the "License").
199767f8919635c4928607450d9e0abb932109ceToomas Soome * You may not use this file except in compliance with the License.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * or http://www.opensolaris.org/os/licensing.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * See the License for the specific language governing permissions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * and limitations under the License.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * When distributing Covered Code, include this CDDL HEADER in each
199767f8919635c4928607450d9e0abb932109ceToomas Soome * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * If applicable, add the following below this CDDL HEADER, with the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * fields enclosed by brackets "[]" replaced with your own identifying
199767f8919635c4928607450d9e0abb932109ceToomas Soome * information: Portions Copyright [yyyy] [name of copyright owner]
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * CDDL HEADER END
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Use is subject to license terms.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome .file "hypot.s"
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "libm.h"
199767f8919635c4928607450d9e0abb932109ceToomas SoomeLIBM_ANSI_PRAGMA_WEAK(hypot,function)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "libm_protos.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome .data
199767f8919635c4928607450d9e0abb932109ceToomas Soome .align 4
199767f8919635c4928607450d9e0abb932109ceToomas Soomeinf:
199767f8919635c4928607450d9e0abb932109ceToomas Soome .long 0x7f800000
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome ENTRY(hypot)
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl 8(%esp),%eax / eax <-- hi_32(x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome andl $0x7fffffff,%eax / eax <-- hi_32(|x|)
199767f8919635c4928607450d9e0abb932109ceToomas Soome jz .x_maybe_0 / if x = +/-0, return |y|
199767f8919635c4928607450d9e0abb932109ceToomas Soome subl $0x7ff00000,%eax / eax <-- hi_32(|x|) - hi_32(INF)
199767f8919635c4928607450d9e0abb932109ceToomas Soome jz .x_maybe_inf
199767f8919635c4928607450d9e0abb932109ceToomas Soome.check_y:
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl 16(%esp),%eax / eax <-- hi_32(y)
199767f8919635c4928607450d9e0abb932109ceToomas Soome andl $0x7fffffff,%eax / eax <-- hi_32(|y|)
199767f8919635c4928607450d9e0abb932109ceToomas Soome jz .y_maybe_0 / if y = +/-0, return |x|
199767f8919635c4928607450d9e0abb932109ceToomas Soome subl $0x7ff00000,%eax / eax <-- hi_32(|y|) - hi_32(INF)
199767f8919635c4928607450d9e0abb932109ceToomas Soome jz .y_maybe_inf
199767f8919635c4928607450d9e0abb932109ceToomas Soome.do_hypot:
199767f8919635c4928607450d9e0abb932109ceToomas Soome fldl 12(%esp) / ,y
199767f8919635c4928607450d9e0abb932109ceToomas Soome fmul %st(0),%st / ,y*y
199767f8919635c4928607450d9e0abb932109ceToomas Soome fldl 4(%esp) / x,y*y
199767f8919635c4928607450d9e0abb932109ceToomas Soome fmul %st(0),%st / x*x,y*y
199767f8919635c4928607450d9e0abb932109ceToomas Soome faddp %st,%st(1) / x*x+y*y
199767f8919635c4928607450d9e0abb932109ceToomas Soome fsqrt / sqrt(x*x+y*y)
199767f8919635c4928607450d9e0abb932109ceToomas Soome subl $8,%esp
199767f8919635c4928607450d9e0abb932109ceToomas Soome fstpl (%esp) / round to double
199767f8919635c4928607450d9e0abb932109ceToomas Soome fldl (%esp) / sqrt(x*x+y*y) rounded to double
199767f8919635c4928607450d9e0abb932109ceToomas Soome PIC_SETUP(1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome flds PIC_L(inf) / inf , sqrt(x*x+y*y)
199767f8919635c4928607450d9e0abb932109ceToomas Soome PIC_WRAPUP
199767f8919635c4928607450d9e0abb932109ceToomas Soome addl $8,%esp
199767f8919635c4928607450d9e0abb932109ceToomas Soome fucomp
199767f8919635c4928607450d9e0abb932109ceToomas Soome fstsw %ax / store status in %ax
199767f8919635c4928607450d9e0abb932109ceToomas Soome sahf / 80387 flags in %ah to 80386 flags
199767f8919635c4928607450d9e0abb932109ceToomas Soome jz .maybe_ovflw
199767f8919635c4928607450d9e0abb932109ceToomas Soome ret
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome.maybe_ovflw:
199767f8919635c4928607450d9e0abb932109ceToomas Soome jnp .ovflw
199767f8919635c4928607450d9e0abb932109ceToomas Soome ret
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome.ovflw:
199767f8919635c4928607450d9e0abb932109ceToomas Soome / overflow occurred
199767f8919635c4928607450d9e0abb932109ceToomas Soome fstp %st(0) / stack empty
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %ebp
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %esp,%ebp
199767f8919635c4928607450d9e0abb932109ceToomas Soome PIC_SETUP(2)
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl $4
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl 20(%ebp) / high y
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl 16(%ebp) / low y
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl 12(%ebp) / high x
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl 8(%ebp) / low x
199767f8919635c4928607450d9e0abb932109ceToomas Soome call PIC_F(_SVID_libm_err)
199767f8919635c4928607450d9e0abb932109ceToomas Soome addl $20,%esp
199767f8919635c4928607450d9e0abb932109ceToomas Soome PIC_WRAPUP
199767f8919635c4928607450d9e0abb932109ceToomas Soome leave
199767f8919635c4928607450d9e0abb932109ceToomas Soome ret
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome.x_maybe_0:
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl 4(%esp),%ecx / ecx <-- lo_32(x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome orl %ecx,%eax / is x = +/-0?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jnz .check_y / branch if x is denormal
199767f8919635c4928607450d9e0abb932109ceToomas Soome / x = +/-0, so return |y|
199767f8919635c4928607450d9e0abb932109ceToomas Soome fldl 12(%esp)
199767f8919635c4928607450d9e0abb932109ceToomas Soome fabs
199767f8919635c4928607450d9e0abb932109ceToomas Soome ret
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome.x_maybe_inf:
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl 4(%esp),%ecx / ecx <-- lo_32(x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome orl %ecx,%eax / is x = +/-INF?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jnz .check_y / branch if x is NaN
199767f8919635c4928607450d9e0abb932109ceToomas Soome / push&pop y in case y is a SNaN
199767f8919635c4928607450d9e0abb932109ceToomas Soome fldl 12(%esp)
199767f8919635c4928607450d9e0abb932109ceToomas Soome fstp %st(0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome / x = +/-INF, so return |x|
199767f8919635c4928607450d9e0abb932109ceToomas Soome fldl 4(%esp)
199767f8919635c4928607450d9e0abb932109ceToomas Soome fabs
199767f8919635c4928607450d9e0abb932109ceToomas Soome ret
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome.y_maybe_0:
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl 12(%esp),%ecx / ecx <-- lo_32(y)
199767f8919635c4928607450d9e0abb932109ceToomas Soome orl %ecx,%eax / is y = +/-0?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jnz .do_hypot / branch if y is denormal
199767f8919635c4928607450d9e0abb932109ceToomas Soome / y = +/-0, so return |x|
199767f8919635c4928607450d9e0abb932109ceToomas Soome fldl 4(%esp)
199767f8919635c4928607450d9e0abb932109ceToomas Soome fabs
199767f8919635c4928607450d9e0abb932109ceToomas Soome ret
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome.y_maybe_inf:
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl 12(%esp),%ecx / ecx <-- lo_32(y)
199767f8919635c4928607450d9e0abb932109ceToomas Soome orl %ecx,%eax / is y = +/-INF?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jnz .do_hypot / branch if y is NaN
199767f8919635c4928607450d9e0abb932109ceToomas Soome / push&pop x in case x is a SNaN
199767f8919635c4928607450d9e0abb932109ceToomas Soome fldl 4(%esp)
199767f8919635c4928607450d9e0abb932109ceToomas Soome fstp %st(0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome / y = +/-INF, so return |y|
199767f8919635c4928607450d9e0abb932109ceToomas Soome fldl 12(%esp)
199767f8919635c4928607450d9e0abb932109ceToomas Soome fabs
199767f8919635c4928607450d9e0abb932109ceToomas Soome ret
199767f8919635c4928607450d9e0abb932109ceToomas Soome .align 4
199767f8919635c4928607450d9e0abb932109ceToomas Soome SET_SIZE(hypot)
199767f8919635c4928607450d9e0abb932109ceToomas Soome