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 "exp10f.s"
  30 
  31 #include "libm.h"
  32 
  33         ENTRY(exp10f)
  34         movl    4(%esp),%ecx            / ecx <-- x
  35         andl    $0x7fffffff,%ecx        / ecx <-- |x|
  36         cmpl    $0x3e9a209a,%ecx        / Is |x| < log10(2)?
  37         jbe     .shortcut               / If so, take a shortcut.
  38         cmpl    $0x7f800000,%ecx        / |x| >= INF?
  39         jae     .not_finite             / if so, x is not finite
  40         flds    4(%esp)                 / push x (=arg)
  41 
  42         subl    $8,%esp                 / save RP and set round-to-64-bits
  43         fstcw   (%esp)
  44         movw    (%esp),%ax
  45         movw    %ax,4(%esp)
  46         orw     $0x0300,%ax
  47         movw    %ax,(%esp)
  48         fldcw   (%esp)
  49 
  50         fldl2t                          / push log2(10)  }NOT for xtndd_dbl
  51         fmulp   %st,%st(1)              / z = x*log2(10) }NOT for xtndd_dbl
  52         fld     %st(0)                  / duplicate stack top
  53         frndint                         / [z],z
  54         fucom                           / z integral?
  55         fstsw   %ax
  56         sahf
  57         je      .z_integral             / branch if z integral
  58         fxch                            / z, [z]
  59         fsub    %st(1),%st              / z-[z], [z]
  60         f2xm1                           / 2**(z-[z])-1, [z]
  61         fld1                            / 1,2**(z-[z])-1, [z]
  62         faddp   %st,%st(1)              / 2**(z-[z]), [z]
  63         fscale                          / 2**z = 10**(arg), [z]
  64         fstp    %st(1)
  65 
  66         fstcw   (%esp)                  / restore old RP
  67         movw    (%esp),%dx
  68         andw    $0xfcff,%dx
  69         movw    4(%esp),%cx
  70         andw    $0x0300,%cx
  71         orw     %dx,%cx
  72         movw    %cx,(%esp)
  73         fldcw   (%esp)
  74         add     $8,%esp
  75 
  76         ret
  77 
  78 .z_integral:                            / here, z is integral
  79         fstp    %st(0)                  / ,z
  80         fld1                            / 1 = 2**0, z
  81         fscale                          / 2**(0 + z) = 2**z = 10**(arg), z
  82         fstp    %st(1)                  / 10**(arg)
  83 
  84         fstcw   (%esp)                  / restore old RP
  85         movw    (%esp),%dx
  86         andw    $0xfcff,%dx
  87         movw    4(%esp),%cx
  88         andw    $0x0300,%cx
  89         orw     %dx,%cx
  90         movw    %cx,(%esp)
  91         fldcw   (%esp)
  92         add     $8,%esp
  93 
  94         ret
  95 
  96 .shortcut:
  97         / Here, |x| < log10(2), so |z| = |x*log2(10)| < 1
  98         / whence z is in f2xm1's domain.
  99         flds    4(%esp)                 / push x (=arg)
 100         fldl2t                          / push log2(10)  }NOT for xtndd_dbl
 101         fmulp   %st,%st(1)              / z = x*log2(10) }NOT for xtndd_dbl
 102         f2xm1                           / 2**z - 1
 103         fld1                            / 1,2**z - 1
 104         faddp   %st,%st(1)              / 2**z = 10**x
 105         ret
 106 
 107 .not_finite:
 108         ja      .NaN_or_pinf            / branch if x is NaN 
 109         movl    4(%esp),%eax            / eax <-- x
 110         andl    $0x80000000,%eax        / here, x is infinite, but +/-?
 111         jz      .NaN_or_pinf            / branch if x = +INF
 112         fldz                            / Here, x = -inf, so return 0
 113         ret
 114 
 115 .NaN_or_pinf:
 116         / Here, x = NaN or +inf, so load x and return immediately.
 117         flds    4(%esp)
 118         fwait
 119         ret
 120         .align  4
 121         SET_SIZE(exp10f)