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 2006 Sun Microsystems, Inc.  All rights reserved.
  26  * Use is subject to license terms.
  27  */
  28 
  29         .file "exp10l.s"
  30 
  31 #include "libm.h"
  32 LIBM_ANSI_PRAGMA_WEAK(exp10l,function)
  33 #include "libm_synonyms.h"
  34 
  35         .data
  36         .align  4
  37 lt2_hi: .long   0xfbd00000, 0x9a209a84, 0x00003ffd
  38 lt2_lo: .long   0x653f4837, 0x8677076a, 0x0000bfc9
  39 
  40         ENTRY(exp10l)
  41         movl    12(%esp),%ecx           / cx <--sign&bexp(x)
  42         andl    $0x00007fff,%ecx        / ecx <-- zero_xtnd(bexp(x))
  43         cmpl    $0x00003ffd,%ecx        / Is |x| < log10(2)?
  44         jb      .shortcut               / If so, take a shortcut.
  45         je      .check_tail             / maybe |x| only slightly < log10(2)
  46         cmpl    $0x00007fff,%ecx        / bexp(|x|) = bexp(INF)?
  47         je      .not_finite             / if so, x is not finite
  48         cmpl    $0x0000400e,%ecx        / |x| < 32768 = 2^15?
  49         jb      .finite_non_special     / if so, proceed with argument reduction
  50         fldt    4(%esp)                 / x
  51         fld1                            / 1, x
  52         jmp     1f
  53 .finite_non_special:                    / Here, log10(2) < |x| < 2^15
  54         fldt    4(%esp)                 / x
  55         fld     %st(0)                  / x, x
  56         fldl2t                          / log2(10), x, x
  57         fmulp                           / z := x*log2(10), x
  58         frndint                         / [z], x
  59         fst     %st(2)                  / [z], x, [z]
  60         PIC_SETUP(1)
  61         fldt    PIC_L(lt2_hi)           / lt2_hi, [z], x, [z]
  62         fmulp                           / [z]*lt2_hi, x, [z]
  63         fsubrp  %st,%st(1)              / x-[z]*lt2_hi, [z]
  64         fldt    PIC_L(lt2_lo)           / lt2_lo, x-[z]*lt2_hi, [z]
  65         PIC_WRAPUP
  66         fmul    %st(2),%st              / [z]*lt2_lo, x-[z]*lt2_hi, [z]
  67         fsubrp  %st,%st(1)              / r := x-[z]*log10(2), [z]
  68         fldl2t                          / log2(10), r, [z]
  69         fmulp                           / f := r*log2(10), [z]
  70         f2xm1                           / 2^f-1,[z]
  71         fld1                            / 1, 2^f-1, [z]
  72         faddp   %st,%st(1)              / 2^f, [z]
  73 1:
  74         fscale                          / 10^x, [z]
  75         fstp    %st(1)
  76         ret
  77 
  78 .check_tail:
  79         movl    8(%esp),%ecx            / ecx <-- hi_32(sgnfcnd(x))
  80         cmpl    $0x9a209a84,%ecx        / Is |x| < log10(2)?
  81         ja      .finite_non_special
  82         jb      .shortcut
  83         movl    4(%esp),%edx            / edx <-- lo_32(sgnfcnd(x))
  84         cmpl    $0xfbcff798,%edx        / Is |x| slightly > log10(2)?
  85         ja      .finite_non_special     / branch if |x| slightly > log10(2)
  86 .shortcut:
  87         / Here, |x| < log10(2), so |z| = |x/log10(2)| < 1
  88         / whence z is in f2xm1's domain.
  89         fldt    4(%esp)                 / x
  90         fldl2t                          / log2(10), x
  91         fmulp                           / z := x*log2(10)
  92         f2xm1                           / 2^z-1
  93         fld1                            / 1, 2^z-1
  94         faddp   %st,%st(1)              / 10^x
  95         ret
  96 
  97 .not_finite:
  98         movl    8(%esp),%ecx            / ecx <-- hi_32(sgnfcnd(x))
  99         cmpl    $0x80000000,%ecx        / hi_32(sgnfcnd(x)) = hi_32(sgnfcnd(INF))?
 100         jne     .NaN_or_pinf            / if not, x is NaN or unsupp.
 101         movl    4(%esp),%edx            / edx <-- lo_32(sgnfcnd(x))
 102         cmpl    $0,%edx                 / lo_32(sgnfcnd(x)) = 0?
 103         jne     .NaN_or_pinf            / if not, x is NaN
 104         movl    12(%esp),%eax           / ax <-- sign&bexp((x))
 105         andl    $0x00008000,%eax        / here, x is infinite, but +/-?
 106         jz      .NaN_or_pinf            / branch if x = +INF
 107         fldz                            / Here, x = -inf, so return 0
 108         ret
 109 
 110 .NaN_or_pinf:
 111         / Here, x = NaN or +inf, so load x and return immediately.
 112         fldt    4(%esp)
 113         ret
 114         .align  4
 115         SET_SIZE(exp10l)