Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Written by J.T. Conklin <jtc@netbsd.org>.
  3.  * Adapted for use as log2 by Ulrich Drepper <drepper@cygnus.com>.
  4.  * Public domain.
  5.  *
  6.  * Changed to use fyl2xp1 for values near 1, <drepper@cygnus.com>.
  7.  *
  8.  * Removed header file dependency for use in libmingwex.a by
  9.  *   Danny Smith <dannysmith@users.sourceforge.net>
  10.  */
  11.  
  12.         .file   "log2f.S"
  13.         .text
  14.         .align 4
  15. one:    .double 1.0
  16.         /* It is not important that this constant is precise.  It is only
  17.            a value which is known to be on the safe side for using the
  18.            fyl2xp1 instruction.  */
  19. limit:  .double 0.29
  20.  
  21.         .text
  22.         .align 4
  23. .globl _log2f
  24.         .def    _log2f; .scl    2;      .type   32;     .endef
  25. _log2f:
  26.         fldl    one
  27.         flds    4(%esp)         /* x : 1 */
  28.         fxam
  29.         fnstsw
  30.         fld     %st             /* x : x : 1 */
  31.         sahf
  32.         jc      3f              /* in case x is NaN or ±Inf */
  33. 4:      fsub    %st(2), %st     /* x-1 : x : 1 */
  34.         fld     %st             /* x-1 : x-1 : x : 1 */
  35.         fabs                    /* |x-1| : x-1 : x : 1 */
  36.         fcompl  limit           /* x-1 : x : 1 */
  37.         fnstsw                  /* x-1 : x : 1 */
  38.         andb    $0x45, %ah
  39.         jz      2f
  40.         fstp    %st(1)          /* x-1 : 1 */
  41.         fyl2xp1                 /* log(x) */
  42.         ret
  43.  
  44. 2:      fstp    %st(0)          /* x : 1 */
  45.         fyl2x                   /* log(x) */
  46.         ret
  47.  
  48. 3:      jp      4b              /* in case x is ±Inf */
  49.         fstp    %st(1)
  50.         fstp    %st(1)
  51.         ret
  52.