OSDN Git Service

2006-10-31 Javier Miranda <miranda@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-fatgen.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                       S Y S T E M . F A T _ G E N                        --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2005 Free Software Foundation, Inc.          --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
19 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
20 -- Boston, MA 02110-1301, USA.                                              --
21 --                                                                          --
22 -- As a special exception,  if other files  instantiate  generics from this --
23 -- unit, or you link  this unit with other files  to produce an executable, --
24 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
25 -- covered  by the  GNU  General  Public  License.  This exception does not --
26 -- however invalidate  any other reasons why  the executable file  might be --
27 -- covered by the  GNU Public License.                                      --
28 --                                                                          --
29 -- GNAT was originally developed  by the GNAT team at  New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 --  This generic package provides a target independent implementation of the
35 --  floating-point attributes that denote functions. The implementations here
36 --  are portable, but very slow. The runtime contains a set of instantiations
37 --  of this package for all predefined floating-point types, and these should
38 --  be replaced by efficient assembly language code where possible.
39
40 generic
41     type T is digits <>;
42
43 package System.Fat_Gen is
44    pragma Pure;
45
46    subtype UI is Integer;
47    --  The runtime representation of universal integer for the purposes of
48    --  this package is integer. The expander generates conversions for the
49    --  actual type used. For functions returning universal integer, there
50    --  is no problem, since the result always is in range of integer. For
51    --  input arguments, the expander has to do some special casing to deal
52    --  with the (very annoying!) cases of out of range values. If we used
53    --  Long_Long_Integer to represent universal, then there would be no
54    --  problem, but the resulting inefficiency would be annoying.
55
56    function Adjacent          (X, Towards : T)              return T;
57
58    function Ceiling           (X : T)                       return T;
59
60    function Compose           (Fraction : T; Exponent : UI) return T;
61
62    function Copy_Sign         (Value, Sign : T)             return T;
63
64    function Exponent          (X : T)                       return UI;
65
66    function Floor             (X : T)                       return T;
67
68    function Fraction          (X : T)                       return T;
69
70    function Leading_Part      (X : T; Radix_Digits : UI)    return T;
71
72    function Machine           (X : T)                       return T;
73
74    function Machine_Rounding  (X : T)                       return T;
75
76    function Model             (X : T)                       return T;
77
78    function Pred              (X : T)                       return T;
79
80    function Remainder         (X, Y : T)                    return T;
81
82    function Rounding          (X : T)                       return T;
83
84    function Scaling           (X : T; Adjustment : UI)      return T;
85
86    function Succ              (X : T)                       return T;
87
88    function Truncation        (X : T)                       return T;
89
90    function Unbiased_Rounding (X : T)                       return T;
91
92    function Valid (X : access T) return Boolean;
93    --  This function checks if the object of type T referenced by X
94    --  is valid, and returns True/False accordingly. The parameter is
95    --  passed by reference (access) here, as the object of type T may
96    --  be an abnormal value that cannot be passed in a floating-point
97    --  register, and the whole point of 'Valid is to prevent exceptions.
98    --  Note that the object of type T must have the natural alignment
99    --  for type T. See Unaligned_Valid for further discussion.
100    --
101    --  Note: this routine does not work for Vax_Float ???
102
103    function Unaligned_Valid (A : System.Address) return Boolean;
104    --  This version of Valid is used if the floating-point value to
105    --  be checked is not known to be aligned (for example it appears
106    --  in a packed record). In this case, we cannot call Valid since
107    --  Valid assumes proper full alignment. Instead Unaligned_Valid
108    --  performs the same processing for a possibly unaligned float,
109    --  by first doing a copy and then calling Valid. One might think
110    --  that the front end could simply do a copy to an aligned temp,
111    --  but remember that we may have an abnormal value that cannot
112    --  be copied into a floating-point register, so things are a bit
113    --  trickier than one might expect.
114    --
115    --  Note: Unaligned_Valid is never called for a target which does
116    --  not require strict alignment (e.g. the ia32/x86), since on a
117    --  target not requiring strict alignment, it is fine to pass a
118    --  non-aligned value to the standard Valid routine.
119    --
120    --  Note: this routine does not work for Vax_Float ???
121
122 private
123    pragma Inline (Machine);
124    pragma Inline (Model);
125
126    --  Note: previously the validity checking subprograms (Unaligned_Valid and
127    --  Valid) were also inlined, but this was changed since there were some
128    --  problems with this inlining in optimized mode, and in any case it seems
129    --  better to avoid this inlining (space and robustness considerations).
130
131 end System.Fat_Gen;