~ubuntu-branches/ubuntu/wily/avr-libc/wily-proposed

« back to all changes in this revision

Viewing changes to libm/fplib/ceil.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
    ceil.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 = ceil(A)
 
9
 *
 
10
 * gr��ter ganzzahliger Wert, der nicht kleiner als arg ist
 
11
 * f�r X > 4B 7F FF FF : X = X (Zahlen haben keinen Bruchteil mehr)
 
12
 *     X >= 0
 
13
 *      X == (float)(long)X   X = X (Zahlen hat keinen Bruchteil)
 
14
 *      X != (float)(long)X   X = (float)(long)X+1 (Zahlen hat einen Bruchteil)
 
15
 *     X <  0 then
 
16
 *      X =  (float)(long)X
 
17
 *
 
18
 * comments on ceil & floor
 
19
 * 1.0       =  7F:80 00 00 00 ->
 
20
 * denormalize to LSB of mantissa == 1.0
 
21
 *              96:00 00 01
 
22
 * 2.0       =  80:80 00 00 00 ->
 
23
 *              96:00 00 02
 
24
 */
 
25
 
 
26
#include "gasava.inc"
 
27
#include "fplib.inc"
 
28
 
 
29
          TEXT_SEG(fplib, ceil)
 
30
          FUNCTION(ceil)
 
31
 
 
32
GLOBAL(ceil)
 
33
    BST     rA3,7
 
34
    RCALL   _U(__fp_split1)   ; split up in sign : exp : fraction   : fraction extention
 
35
                              ;          x  T      R19   R18:rSI0:R16: R1
 
36
    CPI     rA3,0x7F          ; Exp >= 0x7F -> arg >= 1.0
 
37
    BRCC    _ceil_100         ;
 
38
    BRTS    _ceil_01          ; |arg| < 1.0 -> ceil  = / 1.0  f�r X >  0.0
 
39
    TST     rA3               ;                        \ 0.0  f�r X <= 0.0
 
40
    BREQ    _ceil_01
 
41
    LDI     rA3,0x3F
 
42
    LDI     rA2,0x80
 
43
    CLR     rA1
 
44
    CLR     rA0
 
45
    RET
 
46
 _ceil_01:
 
47
    RJMP    _U(__fp_zero)
 
48
 _ceil_100_1:
 
49
    LSR     rA2        ;
 
50
    ROR     rA1        ; shift out fractional bits to the right
 
51
    ROR     rA0        ; until mantissa is a normalized unsigned
 
52
    adc     rAE,rT1c   ; rAE cleard by fp_split1, rT1c = __zero_reg__
 
53
    INC     rA3        ;
 
54
    ; |arg| >= 1.0
 
55
 _ceil_100:            ; |arg| >= 1.0
 
56
    CPI     rA3,0x96   ;
 
57
    BRCS    _ceil_100_1;
 
58
 
 
59
 _ceil_200:
 
60
    BRTS    _ceil_300  ; LSB now is exactely 1 or greater
 
61
    TST     rAE        ; any bit shiftet out? if LSB > 1 then rAE is zero
 
62
    BREQ    _ceil_300  ; no!
 
63
    SUBI    rA0,0xFF   ; else next bigger value
 
64
    SBCI    rA1,0xFF
 
65
    SBCI    rA2,0xFF
 
66
 _ceil_300:
 
67
    CLR     rAE        ; rT0 must not be cleared : rAE=0 no rounding anyway
 
68
    RJMP    _U(__fp_merge)
 
69
 
 
70
          ENDFUNC
 
71
 
 
72