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 "ilogbf.s"
  30 
  31 #include "libm.h"
  32 LIBM_ANSI_PRAGMA_WEAK(ilogbf,function)
  33 #include "xpg6.h"
  34 
  35         .data
  36         .align  8
  37 two23:  .long   0x4b000000              / 2**23
  38 
  39         ENTRY(ilogbf)
  40         movl    4(%esp),%eax            / eax <-- x
  41         testl   $0x7f800000,%eax        / is bexp(x) 0?
  42         jz      .bexp_0                 / jump if x is 0 or subnormal
  43                                         / here, biased exponent is non-zero
  44         andl    $0x7fffffff,%eax        / eax <-- abs(x)
  45         cmpl    $0x7f800000,%eax        / is bexp(x) 0xff?
  46         jae     .bexp_all_1             / jump if x is NaN or Inf
  47         shrl    $23,%eax                / eax <-- zero_xtnd(bexp(x))
  48         subl    $127,%eax               / unbias exponent by 127
  49         ret
  50 
  51 .bexp_all_1:
  52         movl    $0x7fffffff,%eax        / x is NaN or inf, so return 0x7fffffff
  53         jmp     0f
  54 
  55 .bexp_0:
  56         andl    $0x7fffffff,%eax        / eax <-- abs(x), and
  57                                         / ZF = 1 iff x = 0.0
  58         jnz     .ilogb_subnorm
  59         movl    $0x80000001,%eax        / x is +/-0, so return 0x80000001
  60 0:
  61         PIC_SETUP(0)
  62         PIC_G_LOAD(movzwl,__xpg6,ecx)
  63         PIC_WRAPUP
  64         andl    $_C99SUSv3_ilogb_0InfNaN_raises_invalid,%ecx
  65         cmpl    $0,%ecx
  66         je      1f
  67         fldz
  68         fdivp   %st,%st(0)              / raise invalid as per SUSv3
  69 1:
  70         ret
  71 
  72 .ilogb_subnorm:                         / subnormal input
  73         flds    4(%esp)                 / push x
  74         PIC_SETUP(1)
  75         fmuls   PIC_L(two23)            / x*2**23; rebias x by 127+23,
  76                                         /          instead of 127
  77         PIC_WRAPUP
  78         subl    $4,%esp                 / set up storage area
  79         fstps   (%esp)                  / store x*2**23 in storage area
  80         fwait                           / (shouldn't raise exception, but
  81                                         / just in case)
  82         movl    $0x7f800000,%eax        / eax <-- single_bexp_mask
  83         andl    (%esp),%eax             / eax[23..30]  <-- bexp(x*2**23),
  84                                         / rest_of(eax) <-- 0
  85         shrl    $23,%eax                / eax <-- zero_xtnd(bexp(x*2**23))
  86         subl    $150,%eax               / unbias rebiased x by 150 (= 127 + 23)
  87         addl    $4,%esp                 / restore stack for caller
  88         ret
  89         .align  4
  90         SET_SIZE(ilogbf)