1
/* -*- Mode: Asm -*- */
3
/* Copyright (c) 2002 Michael Stumpf <mistumpf@de.pepperl-fuchs.com>
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions are met:
10
* Redistributions of source code must retain the above copyright
11
notice, this list of conditions and the following disclaimer.
13
* Redistributions in binary form must reproduce the above copyright
14
notice, this list of conditions and the following disclaimer in
15
the documentation and/or other materials provided with the
18
* Neither the name of the copyright holders nor the names of
19
contributors may be used to endorse or promote products derived
20
from this software without specific prior written permission.
22
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
POSSIBILITY OF SUCH DAMAGE.
35
/* $Id: fp_cosinus.S,v 1.7.2.1 2005/12/11 19:40:01 aesok Exp $ */
38
fp_cosinus.S is part of FPlib V 0.3.0 ported to avr-as
39
for details see readme.fplib
41
*----------------------------------------------------------------------------------------
43
* A = cosinus(A) with A = [0...2PI[
47
* |a\ b c / d a \ b | c /d | / | \ ;
48
* +--\-----/-------- => ---\--+--/--- => +--/--- => +--X--- ;
49
* 0 \ / 2pi -pi \ | / pi 0| / pi | / pi/2 ;
51
* cos(x-PI) = cos(x) = cos(x) ;
54
* a b c d a b c d a b c d a b c d
55
* + - - + - + + - - + + - + + + +
56
* sign complement for sections b + c
59
#if !defined(__DOXYGEN__)
65
TEXT_SEG(fplib, __fp_cosinus)
66
FUNCTION(__fp_cosinus)
68
GLOBAL(__fp_cosinus) ; input A = [-2PI...2PI[
70
ANDI rA3,0x7F ; input A = [0...2PI[
75
LDI rB0,0xDB ; load -PI
76
RCALL _U(__addsf3) ; now A = [-PI..+PI[
77
LDI rSI0,0x80 ; assume sign complement (b,c)
78
ANDI rA3,0x7F ; positive cos(x-PI) = cos(-(x-PI)) = -cos(x)
82
LDI rB0,0xDB ; load PI/2
86
CPC rA3,rB3 ; cmp A to PI/2
87
BRCS 1f ; branch if lower
88
; now (A = x) > PI/2, B = PI/2
90
LDI rB2,0x49 ; B = -PI
91
RCALL _U(__addsf3) ; PI-A = -(A+-PI)
92
CLR rSI0 ; no sign complement (a,d)
97
LDI ZL,LOW(table_cos) ;
98
LDI ZH,HIGH(table_cos) ;
99
RCALL _U(__fp_powerseries) ;
101
EOR rA3,rSI0 ; complement sign
109
/* cos(x) = ( 1 - x�(1/2! - x�(1/4! - x�(1/6! - x�(1/8! - x�(1/10! - x�(1/12! - x�(1/14!))
112
DCB 8 ; no of table entries - 1 (preload value)
113
; looks like 6 steps are sufficient
114
; 7 steps for sin(pi) == 0
115
;;DCB 0x4A, 0x34, 0x13, 0xC3 ;, 0x1E ; 1/18!
116
DCB 0x29, 0x57, 0x3F, 0x9F ; 1/16!
117
DCB 0x2D, 0x49, 0xCB, 0xA5 ; 1/14!
118
DCB 0x31, 0x0F, 0x76, 0xC7 ; 1/12!
119
DCB 0x34, 0x93, 0xF2, 0x7E ; 1/10!
120
DCB 0x37, 0xD0, 0x0D, 0x01 ; 1/8!
121
DCB 0x3A, 0xB6, 0x0B, 0x61 ; 1/6!
122
DCB 0x3D, 0x2A, 0xAA, 0xAB ; 1/4! = 1/24
123
DCB 0x3F, 0x00, 0x00, 0x00 ; 1/2!
124
DCB 0x3F, 0x80, 0x00, 0x00 ; 1.0
127
#endif /* not __DOXYGEN__ */