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

« back to all changes in this revision

Viewing changes to libm/fplib/modf.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
    modf.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
 * A = modf(A,&B) *B = integral part of A
 
9
 *                 A = fractional part of A
 
10
 */
 
11
 
 
12
#include "gasava.inc"
 
13
#include "fplib.inc"
 
14
 
 
15
          TEXT_SEG(fplib, modf)
 
16
          FUNCTION(modf)
 
17
 
 
18
GLOBAL(modf)
 
19
        BST     rA3,7
 
20
        RCALL   _U(__fp_split1) ; clears rAE
 
21
 
 
22
        PUSH    YL
 
23
        PUSH    YH
 
24
        MOV     YH,rPH
 
25
        MOV     YL,rPL          ; pointer to double
 
26
        CLR     rB3
 
27
        CLR     rB2
 
28
        CLR     rB1
 
29
        CLR     rB0             ; preset zero integral part
 
30
 
 
31
        TST     rA3             ; if zero return zero for *int and mantissa
 
32
        BREQ    _modf_200
 
33
        CPI     rA3,0x7F        ; Exp < 0x7F -> arg < 1.0 -> no integer part
 
34
        BRCS    _modf_200       ;
 
35
 
 
36
 _modf_100:
 
37
        MOV     rTI0,rA3        ; keep temporarily
 
38
        RCALL   _U(__fp_merge)  ; rT0 must not be cleared : rAE=0 no rounding anyway
 
39
        MOV     rB3,rA3
 
40
        MOV     rB2,rA2
 
41
        MOV     rB1,rA1
 
42
        MOV     rB0,rA0
 
43
 
 
44
        CPI     rTI0,0x96       ; rA3 >= 0x96 -> no fractional part
 
45
        BRCC    _modf_150       ;
 
46
        RCALL   _U(__fixsfsi)   ;
 
47
        RCALL   _U(__floatsisf) ;
 
48
        CPI     YL,0
 
49
        CPC     YL,YH
 
50
        BREQ    _modf_130
 
51
        ST      Y+,rA0
 
52
        ST      Y+,rA1
 
53
        ST      Y+,rA2
 
54
        ST      Y+,rA3          ; A = integer part
 
55
 _modf_130:
 
56
        SUBI    rA3,0x80        ; A = -int(x)
 
57
        POP     YH
 
58
        POP     YL
 
59
        RJMP    _U(__addsf3)
 
60
 _modf_150:
 
61
        CLR     rA3
 
62
        CLR     rA2
 
63
        CLR     rA1
 
64
        CLR     rA0
 
65
 _modf_200:
 
66
        CPI     YL,0
 
67
        CPC     YL,YH
 
68
        BREQ    _modf_250
 
69
        ST      Y+,rB0
 
70
        ST      Y+,rB1
 
71
        ST      Y+,rB2
 
72
        ST      Y+,rB3          ; no fractional part
 
73
 _modf_250:
 
74
        POP     YH
 
75
        POP     YL
 
76
        RJMP    _U(__fp_merge)  ; rT0 must not be cleared : rAE=0 no rounding anyway
 
77
 
 
78
          ENDFUNC
 
79
 
 
80