1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  23  */
  24 /*
  25  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  26  * Use is subject to license terms.
  27  */
  28 
  29         .file "exp10.s"
  30 
  31 #include "libm.h"
  32 LIBM_ANSI_PRAGMA_WEAK(exp10,function)
  33 #include "libm_synonyms.h"
  34 
  35         ENTRY(exp10)
  36         movl    8(%esp),%ecx            / ecx <-- hi_32(x)
  37         andl    $0x7fffffff,%ecx        / ecx <-- hi_32(|x|)
  38         cmpl    $0x3fd34413,%ecx        / Is |x| < log10(2)?
  39         jb      .shortcut               / If so, take a shortcut.
  40         je      .check_tail             / maybe |x| only slightly < log10(2)
  41         cmpl    $0x7ff00000,%ecx        / hi_32(|x|) >= hi_32(INF)?
  42         jae     .not_finite             / if so, x is not finite
  43 .finite_non_special:                    / Here, log10(2) < |x| < INF
  44         fldl    4(%esp)                 / push x (=arg)
  45 
  46         subl    $8,%esp                 / save RP and set round-to-64-bits
  47         fstcw   (%esp)
  48         movw    (%esp),%ax
  49         movw    %ax,4(%esp)
  50         orw     $0x0300,%ax
  51         movw    %ax,(%esp)
  52         fldcw   (%esp)
  53 
  54         fldl2t                          / push log2(10)  }NOT for xtndd_dbl
  55         fmulp   %st,%st(1)              / z = x*log2(10) }NOT for xtndd_dbl
  56         fld     %st(0)                  / duplicate stack top
  57         frndint                         / [z],z
  58         fucom                           / z integral?
  59         fstsw  %ax
  60         sahf
  61         je      .z_integral             / branch if z integral
  62         fxch                            / z, [z]
  63         fsub    %st(1),%st              / z-[z], [z]
  64         f2xm1                           / 2**(z-[z])-1, [z]
  65         fld1                            / 1,2**(z-[z])-1, [z]
  66         faddp   %st,%st(1)              / 2**(z-[z]), [z]
  67         fscale                          / 2**z = 10**(arg), [z]
  68         fstp    %st(1)
  69 
  70         fstcw   (%esp)                  / restore old RP
  71         movw    (%esp),%dx
  72         andw    $0xfcff,%dx
  73         movw    4(%esp),%cx
  74         andw    $0x0300,%cx
  75         orw     %dx,%cx
  76         movw    %cx,(%esp)
  77         fldcw   (%esp)
  78         add     $8,%esp
  79 
  80         ret
  81 
  82 .z_integral:                            / here, z is integral
  83         fstp    %st(0)                  / ,z
  84         fld1                            / 1 = 2**0, z
  85         fscale                          / 2**(0 + z) = 2**z = 10**(arg), z
  86         fstp    %st(1)                  / 10**(arg)
  87 
  88         fstcw   (%esp)                  / restore old RP
  89         movw    (%esp),%dx
  90         andw    $0xfcff,%dx
  91         movw    4(%esp),%cx
  92         andw    $0x0300,%cx
  93         orw     %dx,%cx
  94         movw    %cx,(%esp)
  95         fldcw   (%esp)
  96         add     $8,%esp
  97 
  98         ret
  99 
 100 .check_tail:
 101         movl    4(%esp),%edx            / edx <-- lo_32(x)
 102         cmpl    $0x509f79fe,%edx        / Is |x| slightly > log10(2)?
 103         ja      .finite_non_special     / branch if |x| slightly > log10(2)
 104 .shortcut:
 105         / Here, |x| < log10(2), so |z| = |x*log2(10)| < 1
 106         / whence z is in f2xm1's domain.
 107         fldl    4(%esp)                 / push x (=arg)
 108         fldl2t                          / push log2(10)  }NOT for xtndd_dbl
 109         fmulp   %st,%st(1)              / z = x*log2(10) }NOT for xtndd_dbl
 110         f2xm1                           / 2**z - 1
 111         fld1                            / 1,2**z - 1
 112         faddp   %st,%st(1)              / 2**z = 10**x
 113         ret
 114 
 115 .not_finite:
 116         cmpl    $0x7ff00000,%ecx        / hi_32(|x|) > hi_32(INF)?
 117         ja      .NaN_or_pinf            / if so, x is NaN 
 118         movl    4(%esp),%edx            / edx <-- lo_32(x)
 119         cmpl    $0,%edx                 / lo_32(x) = 0?
 120         jne     .NaN_or_pinf            / if not, x is NaN
 121         movl    8(%esp),%eax            / eax <-- hi_32(x)
 122         andl    $0x80000000,%eax        / here, x is infinite, but +/-?
 123         jz      .NaN_or_pinf            / branch if x = +INF
 124         fldz                            / Here, x = -inf, so return 0
 125         ret
 126 
 127 .NaN_or_pinf:
 128         / Here, x = NaN or +inf, so load x and return immediately.
 129         fldl    4(%esp)
 130         fwait
 131         ret
 132         .align  4
 133         SET_SIZE(exp10)