~ubuntu-branches/ubuntu/breezy/avr-libc/breezy

« back to all changes in this revision

Viewing changes to libm/fplib/addsf3x.S

  • Committer: Bazaar Package Importer
  • Author(s): Hakan Ardo
  • Date: 2002-04-15 14:53:38 UTC
  • Revision ID: james.westby@ubuntu.com-20020415145338-c8hi0tn5bx74w7o3
Tags: upstream-20020203
ImportĀ upstreamĀ versionĀ 20020203

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  -*- Mode: Asm -*-  */
 
2
/*
 
3
    addsf3x.S is part of     FPlib V 0.3.0       ported to avr-as
 
4
    for copyright and details see readme.fplib
 
5
 
 
6
 *----------------------------------------------------------------------------------------
 
7
 *
 
8
 *--- addition kernel : used by other high level functions
 
9
 * add two extended numbers RX = AX + BX
 
10
 * AX  rA3 : rA2:rA1:rA0:rAE sign stored in rT1c.7, rAE cleared by fp_split1
 
11
 * BX  rB3 : rB2:rB1:rB0:rBE sign(A) ^ sign(B) stored in T
 
12
 * RX  rA3 : rA2:rA1:rA0:rAE resulting sign stored in rT1c.7 (rT1c.7 complemented, if B > A)
 
13
 */
 
14
 
 
15
#include "gasava.inc"
 
16
#include "fplib.inc"
 
17
 
 
18
          TEXT_SEG(fplib, __addsf3x)
 
19
          FUNCTION(__addsf3x)
 
20
 
 
21
GLOBAL(__addsf3x)
 
22
    CP      rAE,rBE         ; some high level functions use ___addsf3x
 
23
    CPC     rA0,rB0         ; directely with preset rAE,rBE
 
24
    CPC     rA1,rB1         ;
 
25
    CPC     rA2,rB2         ;
 
26
    CPC     rA3,rB3         ; A - B
 
27
    BREQ    ___addsf3x_300
 
28
    BRCC    ___addsf3x_100  ; A >= B
 
29
 
 
30
    BRTC    ___addsf3x_01   ; if T clear the A & B of same sign
 
31
    COM     rT1c            ; else complement sign
 
32
 ___addsf3x_01:
 
33
    MOV     rT0,rAE
 
34
    MOV     rAE,rBE
 
35
    MOV     rBE,rT0
 
36
    MOV     rT0,rA0
 
37
    MOV     rA0,rB0
 
38
    MOV     rB0,rT0
 
39
    MOV     rT0,rA1
 
40
    MOV     rA1,rB1
 
41
    MOV     rB1,rT0
 
42
    MOV     rT0,rA2
 
43
    MOV     rA2,rB2
 
44
    MOV     rB2,rT0
 
45
    MOV     rT0,rA3
 
46
    MOV     rA3,rB3
 
47
    MOV     rB3,rT0
 
48
 
 
49
 ; now A > B
 
50
 ___addsf3x_100:               ; denormalize lower mantissa until exponents are the same
 
51
    CLR     rTI0               ; holds mantissa extension beyond rBE
 
52
    TST     rB3                ;
 
53
    BREQ    ___addsf3x_130     ; A + 0
 
54
 
 
55
    SUB     rB3,rA3            ; get difference, rB3 negative
 
56
    BREQ    ___addsf3x_120     ; same : no shift
 
57
    CPI     rB3,LOW(-25)       ; no significant digits left after shift
 
58
    BRCS    ___addsf3x_130     ;
 
59
 ___addsf3x_110:                                                     ;
 
60
    LSR     rB2                                                      ;
 
61
    ROR     rB1                                                      ;
 
62
    ROR     rB0                                                      ;
 
63
    ROR     rBE                ; fraction >> 1                       ;
 
64
    SBCI    rTI0,0             ; mark if any overflow beyond rBE     ;
 
65
    INC     rB3                ; exponent ++
 
66
    BRNE    ___addsf3x_110     ;
 
67
 
 
68
 ___addsf3x_120:
 
69
    BRTS    ___addsf3x_200     ; branch if different sign
 
70
    ADD     rAE,rBE            ; maybe rAE and rBE are preset
 
71
    adc     rA0,rB0            ;
 
72
    adc     rA1,rB1            ;
 
73
    adc     rA2,rB2            ; add both mantissae
 
74
    BRCC    ___addsf3x_130     ; no fraction overflow if C = 0
 
75
    ROR     rA2                ; correct overflow
 
76
    ROR     rA1
 
77
    ROR     rA0
 
78
    ROR     rAE               ; fraction >> 1
 
79
    SBCI    rTI0,0            ; mark if any overflow beyond rBE
 
80
    INC     rA3               ; exponent++
 
81
 ___addsf3x_130:
 
82
    BST     rT1c,7
 
83
    MOV     rT0,rTI0
 
84
    RET
 
85
 
 
86
 ___addsf3x_200:
 
87
    SUB     rAE,rTI0          ; extended mantissa : 0 - lost bits
 
88
    CLR     rAE
 
89
    SBC     rAE,rBE           ; subtract the lower from the larger
 
90
    SBC     rA0,rB0           ; extended mantissa : if rBE == 0x80 -> rAE = 0x80
 
91
    SBC     rA1,rB1           ;
 
92
    SBC     rA2,rB2           ;
 
93
    RJMP    ___addsf3x_130    ;
 
94
 
 
95
 ; A == B
 
96
 ___addsf3x_300:
 
97
    BRTC    ___addsf3x_100    ; same sign, test for zero & add
 
98
    RJMP    _U(__fp_zerox)     ; different signs
 
99
 
 
100
          ENDFUNC
 
101
 
 
102