1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- S Y S T E M . V A X _ F L O A T _ O P E R A T I O N S --
10 -- Copyright (C) 1997-2000 Free Software Foundation, Inc. --
11 -- (Version for Alpha OpenVMS) --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
31 -- GNAT was originally developed by the GNAT team at New York University. --
32 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
34 ------------------------------------------------------------------------------
36 with System
.IO
; use System
.IO
;
37 with System
.Machine_Code
; use System
.Machine_Code
;
39 package body System
.Vax_Float_Operations
is
41 -- Ensure this gets compiled with -O to avoid extra (and possibly
42 -- improper) memory stores.
44 pragma Optimize
(Time
);
46 -- Declare the functions that do the conversions between floating-point
47 -- formats. Call the operands IEEE float so they get passed in
50 function Cvt_G_T
(X
: T
) return T
;
51 function Cvt_T_G
(X
: T
) return T
;
52 function Cvt_T_F
(X
: T
) return S
;
54 pragma Import
(C
, Cvt_G_T
, "OTS$CVT_FLOAT_G_T");
55 pragma Import
(C
, Cvt_T_G
, "OTS$CVT_FLOAT_T_G");
56 pragma Import
(C
, Cvt_T_F
, "OTS$CVT_FLOAT_T_F");
58 -- In each of the conversion routines that are done with OTS calls,
59 -- we define variables of the corresponding IEEE type so that they are
60 -- passed and kept in the proper register class.
66 function D_To_G
(X
: D
) return G
is
71 Asm
("ldg %0,%1", T
'Asm_Output ("=f", A
), D
'Asm_Input ("m", X
));
72 Asm
("cvtdg %1,%0", T
'Asm_Output ("=f", B
), T
'Asm_Input ("f", A
));
73 Asm
("stg %1,%0", G
'Asm_Output ("=m", C
), T
'Asm_Input ("f", B
));
81 function F_To_G
(X
: F
) return G
is
86 Asm
("ldf %0,%1", T
'Asm_Output ("=f", A
), F
'Asm_Input ("m", X
));
87 Asm
("stg %1,%0", G
'Asm_Output ("=m", B
), T
'Asm_Input ("f", A
));
95 function F_To_S
(X
: F
) return S
is
100 -- Because converting to a wider FP format is a no-op, we say
101 -- A is 64-bit even though we are loading 32 bits into it.
102 Asm
("ldf %0,%1", T
'Asm_Output ("=f", A
), F
'Asm_Input ("m", X
));
104 B
:= S
(Cvt_G_T
(A
));
112 function G_To_D
(X
: G
) return D
is
117 Asm
("ldg %0,%1", T
'Asm_Output ("=f", A
), G
'Asm_Input ("m", X
));
118 Asm
("cvtgd %1,%0", T
'Asm_Output ("=f", B
), T
'Asm_Input ("f", A
));
119 Asm
("stg %1,%0", D
'Asm_Output ("=m", C
), T
'Asm_Input ("f", B
));
127 function G_To_F
(X
: G
) return F
is
133 Asm
("ldg %0,%1", T
'Asm_Output ("=f", A
), G
'Asm_Input ("m", X
));
134 Asm
("cvtgf %1,%0", S
'Asm_Output ("=f", B
), T
'Asm_Input ("f", A
));
135 Asm
("stf %1,%0", F
'Asm_Output ("=m", C
), S
'Asm_Input ("f", B
));
143 function G_To_Q
(X
: G
) return Q
is
148 Asm
("ldg %0,%1", T
'Asm_Output ("=f", A
), G
'Asm_Input ("m", X
));
149 Asm
("cvtgq %1,%0", Q
'Asm_Output ("=f", B
), T
'Asm_Input ("f", A
));
157 function G_To_T
(X
: G
) return T
is
161 Asm
("ldg %0,%1", T
'Asm_Output ("=f", A
), G
'Asm_Input ("m", X
));
170 function F_To_Q
(X
: F
) return Q
is
172 return G_To_Q
(F_To_G
(X
));
179 function Q_To_F
(X
: Q
) return F
is
184 Asm
("cvtqf %1,%0", S
'Asm_Output ("=f", A
), Q
'Asm_Input ("f", X
));
185 Asm
("stf %1,%0", F
'Asm_Output ("=m", B
), S
'Asm_Input ("f", A
));
193 function Q_To_G
(X
: Q
) return G
is
198 Asm
("cvtqg %1,%0", T
'Asm_Output ("=f", A
), Q
'Asm_Input ("f", X
));
199 Asm
("stg %1,%0", G
'Asm_Output ("=m", B
), T
'Asm_Input ("f", A
));
207 function S_To_F
(X
: S
) return F
is
212 A
:= Cvt_T_F
(T
(X
));
213 Asm
("stf %1,%0", F
'Asm_Output ("=m", B
), S
'Asm_Input ("f", A
));
221 function T_To_D
(X
: T
) return D
is
223 return G_To_D
(T_To_G
(X
));
230 function T_To_G
(X
: T
) return G
is
236 Asm
("stg %1,%0", G
'Asm_Output ("=m", B
), T
'Asm_Input ("f", A
));
244 function Abs_F
(X
: F
) return F
is
249 Asm
("ldf %0,%1", S
'Asm_Output ("=f", A
), F
'Asm_Input ("m", X
));
250 Asm
("cpys $f31,%1,%0", S
'Asm_Output ("=f", B
), S
'Asm_Input ("f", A
));
251 Asm
("stf %1,%0", F
'Asm_Output ("=m", C
), S
'Asm_Input ("f", B
));
259 function Abs_G
(X
: G
) return G
is
264 Asm
("ldg %0,%1", T
'Asm_Output ("=f", A
), G
'Asm_Input ("m", X
));
265 Asm
("cpys $f31,%1,%0", T
'Asm_Output ("=f", B
), T
'Asm_Input ("f", A
));
266 Asm
("stg %1,%0", G
'Asm_Output ("=m", C
), T
'Asm_Input ("f", B
));
274 function Add_F
(X
, Y
: F
) return F
is
279 Asm
("ldf %0,%1", S
'Asm_Output ("=f", X1
), F
'Asm_Input ("m", X
));
280 Asm
("ldf %0,%1", S
'Asm_Output ("=f", Y1
), F
'Asm_Input ("m", Y
));
281 Asm
("addf %1,%2,%0", S
'Asm_Output ("=f", R
),
282 (S
'Asm_Input ("f", X1
), S
'Asm_Input ("f", Y1
)));
283 Asm
("stf %1,%0", F
'Asm_Output ("=m", R1
), S
'Asm_Input ("f", R
));
291 function Add_G
(X
, Y
: G
) return G
is
296 Asm
("ldg %0,%1", T
'Asm_Output ("=f", X1
), G
'Asm_Input ("m", X
));
297 Asm
("ldg %0,%1", T
'Asm_Output ("=f", Y1
), G
'Asm_Input ("m", Y
));
298 Asm
("addg %1,%2,%0", T
'Asm_Output ("=f", R
),
299 (T
'Asm_Input ("f", X1
), T
'Asm_Input ("f", Y1
)));
300 Asm
("stg %1,%0", G
'Asm_Output ("=m", R1
), T
'Asm_Input ("f", R
));
308 procedure Debug_Output_D
(Arg
: D
) is
317 procedure Debug_Output_F
(Arg
: F
) is
326 procedure Debug_Output_G
(Arg
: G
) is
335 Debug_String_Buffer
: String (1 .. 32);
336 -- Buffer used by all Debug_String_x routines for returning result
338 function Debug_String_D
(Arg
: D
) return System
.Address
is
339 Image_String
: constant String := D
'Image (Arg
) & ASCII
.NUL
;
340 Image_Size
: constant Integer := Image_String
'Length;
343 Debug_String_Buffer
(1 .. Image_Size
) := Image_String
;
344 return Debug_String_Buffer
(1)'Address;
351 function Debug_String_F
(Arg
: F
) return System
.Address
is
352 Image_String
: constant String := F
'Image (Arg
) & ASCII
.NUL
;
353 Image_Size
: constant Integer := Image_String
'Length;
356 Debug_String_Buffer
(1 .. Image_Size
) := Image_String
;
357 return Debug_String_Buffer
(1)'Address;
364 function Debug_String_G
(Arg
: G
) return System
.Address
is
365 Image_String
: constant String := G
'Image (Arg
) & ASCII
.NUL
;
366 Image_Size
: constant Integer := Image_String
'Length;
369 Debug_String_Buffer
(1 .. Image_Size
) := Image_String
;
370 return Debug_String_Buffer
(1)'Address;
377 function Div_F
(X
, Y
: F
) return F
is
382 Asm
("ldf %0,%1", S
'Asm_Output ("=f", X1
), F
'Asm_Input ("m", X
));
383 Asm
("ldf %0,%1", S
'Asm_Output ("=f", Y1
), F
'Asm_Input ("m", Y
));
384 Asm
("divf %1,%2,%0", S
'Asm_Output ("=f", R
),
385 (S
'Asm_Input ("f", X1
), S
'Asm_Input ("f", Y1
)));
386 Asm
("stf %1,%0", F
'Asm_Output ("=m", R1
), S
'Asm_Input ("f", R
));
394 function Div_G
(X
, Y
: G
) return G
is
399 Asm
("ldg %0,%1", T
'Asm_Output ("=f", X1
), G
'Asm_Input ("m", X
));
400 Asm
("ldg %0,%1", T
'Asm_Output ("=f", Y1
), G
'Asm_Input ("m", Y
));
401 Asm
("divg %1,%2,%0", T
'Asm_Output ("=f", R
),
402 (T
'Asm_Input ("f", X1
), T
'Asm_Input ("f", Y1
)));
403 Asm
("stg %1,%0", G
'Asm_Output ("=m", R1
), T
'Asm_Input ("f", R
));
411 function Eq_F
(X
, Y
: F
) return Boolean is
415 Asm
("ldf %0,%1", S
'Asm_Output ("=f", X1
), F
'Asm_Input ("m", X
));
416 Asm
("ldf %0,%1", S
'Asm_Output ("=f", Y1
), F
'Asm_Input ("m", Y
));
417 Asm
("cmpgeq %1,%2,%0", S
'Asm_Output ("=f", R
),
418 (S
'Asm_Input ("f", X1
), S
'Asm_Input ("f", Y1
)));
426 function Eq_G
(X
, Y
: G
) return Boolean is
430 Asm
("ldg %0,%1", T
'Asm_Output ("=f", X1
), G
'Asm_Input ("m", X
));
431 Asm
("ldg %0,%1", T
'Asm_Output ("=f", Y1
), G
'Asm_Input ("m", Y
));
432 Asm
("cmpgeq %1,%2,%0", T
'Asm_Output ("=f", R
),
433 (T
'Asm_Input ("f", X1
), T
'Asm_Input ("f", Y1
)));
441 function Le_F
(X
, Y
: F
) return Boolean is
445 Asm
("ldf %0,%1", S
'Asm_Output ("=f", X1
), F
'Asm_Input ("m", X
));
446 Asm
("ldf %0,%1", S
'Asm_Output ("=f", Y1
), F
'Asm_Input ("m", Y
));
447 Asm
("cmpgle %1,%2,%0", S
'Asm_Output ("=f", R
),
448 (S
'Asm_Input ("f", X1
), S
'Asm_Input ("f", Y1
)));
456 function Le_G
(X
, Y
: G
) return Boolean is
460 Asm
("ldg %0,%1", T
'Asm_Output ("=f", X1
), G
'Asm_Input ("m", X
));
461 Asm
("ldg %0,%1", T
'Asm_Output ("=f", Y1
), G
'Asm_Input ("m", Y
));
462 Asm
("cmpgle %1,%2,%0", T
'Asm_Output ("=f", R
),
463 (T
'Asm_Input ("f", X1
), T
'Asm_Input ("f", Y1
)));
471 function Lt_F
(X
, Y
: F
) return Boolean is
475 Asm
("ldf %0,%1", S
'Asm_Output ("=f", X1
), F
'Asm_Input ("m", X
));
476 Asm
("ldf %0,%1", S
'Asm_Output ("=f", Y1
), F
'Asm_Input ("m", Y
));
477 Asm
("cmpglt %1,%2,%0", S
'Asm_Output ("=f", R
),
478 (S
'Asm_Input ("f", X1
), S
'Asm_Input ("f", Y1
)));
486 function Lt_G
(X
, Y
: G
) return Boolean is
490 Asm
("ldg %0,%1", T
'Asm_Output ("=f", X1
), G
'Asm_Input ("m", X
));
491 Asm
("ldg %0,%1", T
'Asm_Output ("=f", Y1
), G
'Asm_Input ("m", Y
));
492 Asm
("cmpglt %1,%2,%0", T
'Asm_Output ("=f", R
),
493 (T
'Asm_Input ("f", X1
), T
'Asm_Input ("f", Y1
)));
501 function Mul_F
(X
, Y
: F
) return F
is
506 Asm
("ldf %0,%1", S
'Asm_Output ("=f", X1
), F
'Asm_Input ("m", X
));
507 Asm
("ldf %0,%1", S
'Asm_Output ("=f", Y1
), F
'Asm_Input ("m", Y
));
508 Asm
("mulf %1,%2,%0", S
'Asm_Output ("=f", R
),
509 (S
'Asm_Input ("f", X1
), S
'Asm_Input ("f", Y1
)));
510 Asm
("stf %1,%0", F
'Asm_Output ("=m", R1
), S
'Asm_Input ("f", R
));
518 function Mul_G
(X
, Y
: G
) return G
is
523 Asm
("ldg %0,%1", T
'Asm_Output ("=f", X1
), G
'Asm_Input ("m", X
));
524 Asm
("ldg %0,%1", T
'Asm_Output ("=f", Y1
), G
'Asm_Input ("m", Y
));
525 Asm
("mulg %1,%2,%0", T
'Asm_Output ("=f", R
),
526 (T
'Asm_Input ("f", X1
), T
'Asm_Input ("f", Y1
)));
527 Asm
("stg %1,%0", G
'Asm_Output ("=m", R1
), T
'Asm_Input ("f", R
));
535 function Neg_F
(X
: F
) return F
is
540 Asm
("ldf %0,%1", S
'Asm_Output ("=f", A
), F
'Asm_Input ("m", X
));
541 Asm
("cpysn %1,%1,%0", S
'Asm_Output ("=f", B
), S
'Asm_Input ("f", A
));
542 Asm
("stf %1,%0", F
'Asm_Output ("=m", C
), S
'Asm_Input ("f", B
));
550 function Neg_G
(X
: G
) return G
is
555 Asm
("ldg %0,%1", T
'Asm_Output ("=f", A
), G
'Asm_Input ("m", X
));
556 Asm
("cpysn %1,%1,%0", T
'Asm_Output ("=f", B
), T
'Asm_Input ("f", A
));
557 Asm
("stg %1,%0", G
'Asm_Output ("=m", C
), T
'Asm_Input ("f", B
));
565 procedure pd
(Arg
: D
) is
567 Put_Line
(D
'Image (Arg
));
574 procedure pf
(Arg
: F
) is
576 Put_Line
(F
'Image (Arg
));
583 procedure pg
(Arg
: G
) is
585 Put_Line
(G
'Image (Arg
));
592 function Sub_F
(X
, Y
: F
) return F
is
597 Asm
("ldf %0,%1", S
'Asm_Output ("=f", X1
), F
'Asm_Input ("m", X
));
598 Asm
("ldf %0,%1", S
'Asm_Output ("=f", Y1
), F
'Asm_Input ("m", Y
));
599 Asm
("subf %1,%2,%0", S
'Asm_Output ("=f", R
),
600 (S
'Asm_Input ("f", X1
), S
'Asm_Input ("f", Y1
)));
601 Asm
("stf %1,%0", F
'Asm_Output ("=m", R1
), S
'Asm_Input ("f", R
));
609 function Sub_G
(X
, Y
: G
) return G
is
614 Asm
("ldg %0,%1", T
'Asm_Output ("=f", X1
), G
'Asm_Input ("m", X
));
615 Asm
("ldg %0,%1", T
'Asm_Output ("=f", Y1
), G
'Asm_Input ("m", Y
));
616 Asm
("subg %1,%2,%0", T
'Asm_Output ("=f", R
),
617 (T
'Asm_Input ("f", X1
), T
'Asm_Input ("f", Y1
)));
618 Asm
("stg %1,%0", G
'Asm_Output ("=m", R1
), T
'Asm_Input ("f", R
));
622 end System
.Vax_Float_Operations
;