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   "__reduction.s"
  30 
  31 /
  32 /    After argument reduction which returns n:
  33 /       n mod 4     sin(x)      cos(x)        tan(x)
  34 /     ----------------------------------------------------------
  35 /          0          S           C             S/C
  36 /          1          C          -S            -C/S
  37 /          2         -S          -C             S/C
  38 /          3         -C           S            -C/S
  39 /     ----------------------------------------------------------
  40 
  41 #include "libm.h"
  42 #include "libm_synonyms.h"
  43 #include "libm_protos.h"
  44 #undef fabs
  45 
  46         ENTRY(__reduction)
  47 #ifndef PIC
  48         movl    12(%esp),%eax           / load the high part of arg
  49 #else
  50         movl    16(%esp),%eax           / load the high part of arg
  51 #endif
  52         andl    $0x7fffffff,%eax        / clear sign
  53         cmpl    $0x3fe921fb,%eax        / Is |x| < pi/4 (= 0x3fe921fb54...) ?
  54         jbe     .L0
  55         cmpl    $0x7ff00000,%eax        / Is arg a NaN or an Inf ?
  56         jb      .L1
  57 .L0:
  58 #ifndef PIC
  59         fldl    8(%esp)                 / push arg
  60 #else
  61         fldl    12(%esp)                / push arg
  62 #endif
  63         fwait
  64         movl    $0,%eax                 / set n = 0
  65         ret
  66 .L1:
  67         pushl   %ebp
  68         movl    %esp,%ebp
  69         subl    $16,%esp
  70         PIC_SETUP(1)
  71         leal    -16(%ebp),%eax          / address of y[0]
  72         pushl   %eax
  73 #ifndef PIC
  74         pushl   16(%ebp)
  75         pushl   12(%ebp)
  76 #else
  77         pushl   20(%ebp)
  78         pushl   16(%ebp)
  79 #endif
  80         call    PIC_F(__rem_pio2)       / call __rem_pio2(x,&y)
  81         fldl    -8(%ebp)                / y[1]
  82         fldl    -16(%ebp)               / y[0], y[1]
  83         faddp   %st,%st(1)              / y[0]+y[1] round-to-extended
  84         addl    $28,%esp                / 16+4*3
  85         andl    $3,%eax
  86         PIC_WRAPUP
  87         leave
  88         ret
  89         .align  4
  90         SET_SIZE(__reduction)