1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
/* -*- Mode: Asm -*- */
/* Copyright (c) 2002 Michael Stumpf <mistumpf@de.pepperl-fuchs.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of the copyright holders nor the names of
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
/*
addsf3x.S is part of FPlib V 0.3.0 ported to avr-as
for details see readme.fplib
*----------------------------------------------------------------------------------------
*
*--- addition kernel : used by other high level functions
* add two extended numbers RX = AX + BX
* AX rA3 : rA2:rA1:rA0:rAE sign stored in rT1c.7, rAE cleared by fp_split1
* BX rB3 : rB2:rB1:rB0:rBE sign(A) ^ sign(B) stored in T
* RX rA3 : rA2:rA1:rA0:rAE resulting sign stored in rT1c.7 (rT1c.7 complemented, if B > A)
*/
#if !defined(DOXYGEN)
#include "gasava.inc"
#include "fplib.inc"
TEXT_SEG(fplib, __addsf3x)
FUNCTION(__addsf3x)
GLOBAL(__addsf3x)
CP rAE,rBE ; some high level functions use ___addsf3x
CPC rA0,rB0 ; directely with preset rAE,rBE
CPC rA1,rB1 ;
CPC rA2,rB2 ;
CPC rA3,rB3 ; A - B
BREQ ___addsf3x_300
BRCC ___addsf3x_100 ; A >= B
BRTC ___addsf3x_01 ; if T clear the A & B of same sign
COM rT1c ; else complement sign
___addsf3x_01:
MOV rT0,rAE
MOV rAE,rBE
MOV rBE,rT0
MOV rT0,rA0
MOV rA0,rB0
MOV rB0,rT0
MOV rT0,rA1
MOV rA1,rB1
MOV rB1,rT0
MOV rT0,rA2
MOV rA2,rB2
MOV rB2,rT0
MOV rT0,rA3
MOV rA3,rB3
MOV rB3,rT0
; now A > B
___addsf3x_100: ; denormalize lower mantissa until exponents are the same
CLR rTI0 ; holds mantissa extension beyond rBE
TST rB3 ;
BREQ ___addsf3x_130 ; A + 0
SUB rB3,rA3 ; get difference, rB3 negative
BREQ ___addsf3x_120 ; same : no shift
CPI rB3,LOW(-25) ; no significant digits left after shift
BRCS ___addsf3x_130 ;
___addsf3x_110: ;
LSR rB2 ;
ROR rB1 ;
ROR rB0 ;
ROR rBE ; fraction >> 1 ;
SBCI rTI0,0 ; mark if any overflow beyond rBE ;
INC rB3 ; exponent ++
BRNE ___addsf3x_110 ;
___addsf3x_120:
BRTS ___addsf3x_200 ; branch if different sign
ADD rAE,rBE ; maybe rAE and rBE are preset
adc rA0,rB0 ;
adc rA1,rB1 ;
adc rA2,rB2 ; add both mantissae
BRCC ___addsf3x_130 ; no fraction overflow if C = 0
ROR rA2 ; correct overflow
ROR rA1
ROR rA0
ROR rAE ; fraction >> 1
SBCI rTI0,0 ; mark if any overflow beyond rBE
INC rA3 ; exponent++
___addsf3x_130:
BST rT1c,7
MOV rT0,rTI0
RET
___addsf3x_200:
SUB rAE,rTI0 ; extended mantissa : 0 - lost bits
CLR rAE
SBC rAE,rBE ; subtract the lower from the larger
SBC rA0,rB0 ; extended mantissa : if rBE == 0x80 -> rAE = 0x80
SBC rA1,rB1 ;
SBC rA2,rB2 ;
RJMP ___addsf3x_130 ;
; A == B
___addsf3x_300:
BRTC ___addsf3x_100 ; same sign, test for zero & add
RJMP _U(__fp_zerox) ; different signs
ENDFUNC
#endif /* not DOXYGEN */
|