1
/* Copyright (c) 2002 Michael Stumpf <mistumpf@de.pepperl-fuchs.com>
2
Copyright (c) 2006 Dmitry Xmelkov
5
Redistribution and use in source and binary forms, with or without
6
modification, are permitted provided that the following conditions are met:
8
* Redistributions of source code must retain the above copyright
9
notice, this list of conditions and the following disclaimer.
10
* Redistributions in binary form must reproduce the above copyright
11
notice, this list of conditions and the following disclaimer in
12
the documentation and/or other materials provided with the
14
* Neither the name of the copyright holders nor the names of
15
contributors may be used to endorse or promote products derived
16
from this software without specific prior written permission.
18
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
POSSIBILITY OF SUCH DAMAGE. */
30
/* $Id: fp_rempio2.S,v 1.1 2007/01/14 14:58:04 dmix Exp $ */
35
/* <non_standart> __fp_rempio2 (float x);
36
The __fp_rempio2() function computes the remainder of dividing
37
absolute value of x by Pi/2. The return value is x - n*Pi/2, where
38
n is the quotient of abs(x)/(Pi/2), rounded towards zero to an integer.
40
rA3.rA2.rA1.rA0.rAE - flt40_t remainder
44
#define HI40_PIO2 0x3FC90FDA /* (flt40_t) Pi/2 */
45
#define LO40_PIO2 0xA2
46
#define MNT32_PIO2 0xC90FDAA2 /* mantissa of Pi/2, 32 bits */
47
#define SPLIT_PIO2 0x7FC80FDA /* split(HI40_PIO2) */
54
; split and check finite
56
brcs 0b ; only finite numbers are valid
58
; init division result ('com' at the end)
62
ldi rB1, hi8(SPLIT_PIO2 + 1)
63
ldi rB2, hlo8(SPLIT_PIO2 + 1)
64
ldi rB3, hhi8(SPLIT_PIO2 + 1)
65
cpi rA0, lo8(SPLIT_PIO2 + 1)
69
brlo .L_pack ; A < Pi/2 ==> return A
71
clr ZH ; highest A byte
72
subi rA3, hhi8(HI40_PIO2 << 1) ; ilogb(A) - ilogb(B)
74
subi rAE, lo8(MNT32_PIO2)
75
sbci rA0, hi8(MNT32_PIO2)
76
sbci rA1, hlo8(MNT32_PIO2)
77
sbci rA2, hhi8(MNT32_PIO2)
80
subi rAE, lo8(-MNT32_PIO2)
81
sbci rA0, hi8(-MNT32_PIO2)
82
sbci rA1, hlo8(-MNT32_PIO2)
83
sbci rA2, hhi8(-MNT32_PIO2)
97
/* FIXME: Is it possible to obtain a zero value in rA2.1.0.E ?
98
I do't known. So, there is a check in exponent decrement. */
99
ldi rA3, hhi8((HI40_PIO2 << 1) - 0x01000000)