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 --
9 -- Copyright (C) 1997-2005, Free Software Foundation, Inc. --
10 -- (Version for Alpha OpenVMS) --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
21 -- Boston, MA 02110-1301, USA. --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
30 -- GNAT was originally developed by the GNAT team at New York University. --
31 -- Extensive contributions were provided by Ada Core Technologies Inc. --
33 ------------------------------------------------------------------------------
35 with System.IO; use System.IO;
36 with System.Machine_Code; use System.Machine_Code;
38 package body System.Vax_Float_Operations is
40 -- Ensure this gets compiled with -O to avoid extra (and possibly
41 -- improper) memory stores.
43 pragma Optimize (Time);
45 -- Declare the functions that do the conversions between floating-point
46 -- formats. Call the operands IEEE float so they get passed in
49 function Cvt_G_T (X : T) return T;
50 function Cvt_T_G (X : T) return T;
51 function Cvt_T_F (X : T) return S;
53 pragma Import (C, Cvt_G_T, "OTS$CVT_FLOAT_G_T");
54 pragma Import (C, Cvt_T_G, "OTS$CVT_FLOAT_T_G");
55 pragma Import (C, Cvt_T_F, "OTS$CVT_FLOAT_T_F");
57 -- In each of the conversion routines that are done with OTS calls,
58 -- we define variables of the corresponding IEEE type so that they are
59 -- passed and kept in the proper register class.
61 Debug_String_Buffer : String (1 .. 32);
62 -- Buffer used by all Debug_String_x routines for returning result
68 function D_To_G (X : D) return G is
72 Asm ("ldg %0,%1", T'Asm_Output ("=f", A), D'Asm_Input ("m", X));
73 Asm ("cvtdg %1,%0", T'Asm_Output ("=f", B), T'Asm_Input ("f", A));
74 Asm ("stg %1,%0", G'Asm_Output ("=m", C), T'Asm_Input ("f", B));
82 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.
103 Asm ("ldf %0,%1", T'Asm_Output ("=f", A), F'Asm_Input ("m", X));
105 B := S (Cvt_G_T (A));
113 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
132 Asm ("ldg %0,%1", T'Asm_Output ("=f", A), G'Asm_Input ("m", X));
133 Asm ("cvtgf %1,%0", S'Asm_Output ("=f", B), T'Asm_Input ("f", A));
134 Asm ("stf %1,%0", F'Asm_Output ("=m", C), S'Asm_Input ("f", B));
142 function G_To_Q (X : G) return Q is
146 Asm ("ldg %0,%1", T'Asm_Output ("=f", A), G'Asm_Input ("m", X));
147 Asm ("cvtgq %1,%0", Q'Asm_Output ("=f", B), T'Asm_Input ("f", A));
155 function G_To_T (X : G) return T is
158 Asm ("ldg %0,%1", T'Asm_Output ("=f", A), G'Asm_Input ("m", X));
167 function F_To_Q (X : F) return Q is
169 return G_To_Q (F_To_G (X));
176 function Q_To_F (X : Q) return F is
180 Asm ("cvtqf %1,%0", S'Asm_Output ("=f", A), Q'Asm_Input ("f", X));
181 Asm ("stf %1,%0", F'Asm_Output ("=m", B), S'Asm_Input ("f", A));
189 function Q_To_G (X : Q) return G is
193 Asm ("cvtqg %1,%0", T'Asm_Output ("=f", A), Q'Asm_Input ("f", X));
194 Asm ("stg %1,%0", G'Asm_Output ("=m", B), T'Asm_Input ("f", A));
202 function S_To_F (X : S) return F is
206 A := Cvt_T_F (T (X));
207 Asm ("stf %1,%0", F'Asm_Output ("=m", B), S'Asm_Input ("f", A));
215 function T_To_D (X : T) return D is
217 return G_To_D (T_To_G (X));
224 function T_To_G (X : T) return G is
229 Asm ("stg %1,%0", G'Asm_Output ("=m", B), T'Asm_Input ("f", A));
237 function Abs_F (X : F) return F is
241 Asm ("ldf %0,%1", S'Asm_Output ("=f", A), F'Asm_Input ("m", X));
242 Asm ("cpys $f31,%1,%0", S'Asm_Output ("=f", B), S'Asm_Input ("f", A));
243 Asm ("stf %1,%0", F'Asm_Output ("=m", C), S'Asm_Input ("f", B));
251 function Abs_G (X : G) return G is
255 Asm ("ldg %0,%1", T'Asm_Output ("=f", A), G'Asm_Input ("m", X));
256 Asm ("cpys $f31,%1,%0", T'Asm_Output ("=f", B), T'Asm_Input ("f", A));
257 Asm ("stg %1,%0", G'Asm_Output ("=m", C), T'Asm_Input ("f", B));
265 function Add_F (X, Y : F) return F is
269 Asm ("ldf %0,%1", S'Asm_Output ("=f", X1), F'Asm_Input ("m", X));
270 Asm ("ldf %0,%1", S'Asm_Output ("=f", Y1), F'Asm_Input ("m", Y));
271 Asm ("addf %1,%2,%0", S'Asm_Output ("=f", R),
272 (S'Asm_Input ("f", X1), S'Asm_Input ("f", Y1)));
273 Asm ("stf %1,%0", F'Asm_Output ("=m", R1), S'Asm_Input ("f", R));
281 function Add_G (X, Y : G) return G is
285 Asm ("ldg %0,%1", T'Asm_Output ("=f", X1), G'Asm_Input ("m", X));
286 Asm ("ldg %0,%1", T'Asm_Output ("=f", Y1), G'Asm_Input ("m", Y));
287 Asm ("addg %1,%2,%0", T'Asm_Output ("=f", R),
288 (T'Asm_Input ("f", X1), T'Asm_Input ("f", Y1)));
289 Asm ("stg %1,%0", G'Asm_Output ("=m", R1), T'Asm_Input ("f", R));
297 procedure Debug_Output_D (Arg : D) is
306 procedure Debug_Output_F (Arg : F) is
315 procedure Debug_Output_G (Arg : G) is
324 function Debug_String_D (Arg : D) return System.Address is
325 Image_String : constant String := D'Image (Arg) & ASCII.NUL;
326 Image_Size : constant Integer := Image_String'Length;
328 Debug_String_Buffer (1 .. Image_Size) := Image_String;
329 return Debug_String_Buffer (1)'Address;
336 function Debug_String_F (Arg : F) return System.Address is
337 Image_String : constant String := F'Image (Arg) & ASCII.NUL;
338 Image_Size : constant Integer := Image_String'Length;
340 Debug_String_Buffer (1 .. Image_Size) := Image_String;
341 return Debug_String_Buffer (1)'Address;
348 function Debug_String_G (Arg : G) return System.Address is
349 Image_String : constant String := G'Image (Arg) & ASCII.NUL;
350 Image_Size : constant Integer := Image_String'Length;
352 Debug_String_Buffer (1 .. Image_Size) := Image_String;
353 return Debug_String_Buffer (1)'Address;
360 function Div_F (X, Y : F) return F is
364 Asm ("ldf %0,%1", S'Asm_Output ("=f", X1), F'Asm_Input ("m", X));
365 Asm ("ldf %0,%1", S'Asm_Output ("=f", Y1), F'Asm_Input ("m", Y));
366 Asm ("divf %1,%2,%0", S'Asm_Output ("=f", R),
367 (S'Asm_Input ("f", X1), S'Asm_Input ("f", Y1)));
368 Asm ("stf %1,%0", F'Asm_Output ("=m", R1), S'Asm_Input ("f", R));
376 function Div_G (X, Y : G) return G is
380 Asm ("ldg %0,%1", T'Asm_Output ("=f", X1), G'Asm_Input ("m", X));
381 Asm ("ldg %0,%1", T'Asm_Output ("=f", Y1), G'Asm_Input ("m", Y));
382 Asm ("divg %1,%2,%0", T'Asm_Output ("=f", R),
383 (T'Asm_Input ("f", X1), T'Asm_Input ("f", Y1)));
384 Asm ("stg %1,%0", G'Asm_Output ("=m", R1), T'Asm_Input ("f", R));
392 function Eq_F (X, Y : F) return Boolean is
395 Asm ("ldf %0,%1", S'Asm_Output ("=f", X1), F'Asm_Input ("m", X));
396 Asm ("ldf %0,%1", S'Asm_Output ("=f", Y1), F'Asm_Input ("m", Y));
397 Asm ("cmpgeq %1,%2,%0", S'Asm_Output ("=f", R),
398 (S'Asm_Input ("f", X1), S'Asm_Input ("f", Y1)));
406 function Eq_G (X, Y : G) return Boolean is
409 Asm ("ldg %0,%1", T'Asm_Output ("=f", X1), G'Asm_Input ("m", X));
410 Asm ("ldg %0,%1", T'Asm_Output ("=f", Y1), G'Asm_Input ("m", Y));
411 Asm ("cmpgeq %1,%2,%0", T'Asm_Output ("=f", R),
412 (T'Asm_Input ("f", X1), T'Asm_Input ("f", Y1)));
420 function Le_F (X, Y : F) return Boolean is
423 Asm ("ldf %0,%1", S'Asm_Output ("=f", X1), F'Asm_Input ("m", X));
424 Asm ("ldf %0,%1", S'Asm_Output ("=f", Y1), F'Asm_Input ("m", Y));
425 Asm ("cmpgle %1,%2,%0", S'Asm_Output ("=f", R),
426 (S'Asm_Input ("f", X1), S'Asm_Input ("f", Y1)));
434 function Le_G (X, Y : G) return Boolean is
437 Asm ("ldg %0,%1", T'Asm_Output ("=f", X1), G'Asm_Input ("m", X));
438 Asm ("ldg %0,%1", T'Asm_Output ("=f", Y1), G'Asm_Input ("m", Y));
439 Asm ("cmpgle %1,%2,%0", T'Asm_Output ("=f", R),
440 (T'Asm_Input ("f", X1), T'Asm_Input ("f", Y1)));
448 function Lt_F (X, Y : F) return Boolean is
451 Asm ("ldf %0,%1", S'Asm_Output ("=f", X1), F'Asm_Input ("m", X));
452 Asm ("ldf %0,%1", S'Asm_Output ("=f", Y1), F'Asm_Input ("m", Y));
453 Asm ("cmpglt %1,%2,%0", S'Asm_Output ("=f", R),
454 (S'Asm_Input ("f", X1), S'Asm_Input ("f", Y1)));
462 function Lt_G (X, Y : G) return Boolean is
465 Asm ("ldg %0,%1", T'Asm_Output ("=f", X1), G'Asm_Input ("m", X));
466 Asm ("ldg %0,%1", T'Asm_Output ("=f", Y1), G'Asm_Input ("m", Y));
467 Asm ("cmpglt %1,%2,%0", T'Asm_Output ("=f", R),
468 (T'Asm_Input ("f", X1), T'Asm_Input ("f", Y1)));
476 function Mul_F (X, Y : F) return F is
480 Asm ("ldf %0,%1", S'Asm_Output ("=f", X1), F'Asm_Input ("m", X));
481 Asm ("ldf %0,%1", S'Asm_Output ("=f", Y1), F'Asm_Input ("m", Y));
482 Asm ("mulf %1,%2,%0", S'Asm_Output ("=f", R),
483 (S'Asm_Input ("f", X1), S'Asm_Input ("f", Y1)));
484 Asm ("stf %1,%0", F'Asm_Output ("=m", R1), S'Asm_Input ("f", R));
492 function Mul_G (X, Y : G) return G is
496 Asm ("ldg %0,%1", T'Asm_Output ("=f", X1), G'Asm_Input ("m", X));
497 Asm ("ldg %0,%1", T'Asm_Output ("=f", Y1), G'Asm_Input ("m", Y));
498 Asm ("mulg %1,%2,%0", T'Asm_Output ("=f", R),
499 (T'Asm_Input ("f", X1), T'Asm_Input ("f", Y1)));
500 Asm ("stg %1,%0", G'Asm_Output ("=m", R1), T'Asm_Input ("f", R));
508 function Ne_F (X, Y : F) return Boolean is
511 Asm ("ldf %0,%1", S'Asm_Output ("=f", X1), F'Asm_Input ("m", X));
512 Asm ("ldf %0,%1", S'Asm_Output ("=f", Y1), F'Asm_Input ("m", Y));
513 Asm ("cmpgeq %1,%2,%0", S'Asm_Output ("=f", R),
514 (S'Asm_Input ("f", X1), S'Asm_Input ("f", Y1)));
522 function Ne_G (X, Y : G) return Boolean is
525 Asm ("ldg %0,%1", T'Asm_Output ("=f", X1), G'Asm_Input ("m", X));
526 Asm ("ldg %0,%1", T'Asm_Output ("=f", Y1), G'Asm_Input ("m", Y));
527 Asm ("cmpgeq %1,%2,%0", T'Asm_Output ("=f", R),
528 (T'Asm_Input ("f", X1), T'Asm_Input ("f", Y1)));
536 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
554 Asm ("ldg %0,%1", T'Asm_Output ("=f", A), G'Asm_Input ("m", X));
555 Asm ("cpysn %1,%1,%0", T'Asm_Output ("=f", B), T'Asm_Input ("f", A));
556 Asm ("stg %1,%0", G'Asm_Output ("=m", C), T'Asm_Input ("f", B));
564 procedure pd (Arg : D) is
566 Put_Line (D'Image (Arg));
573 procedure pf (Arg : F) is
575 Put_Line (F'Image (Arg));
582 procedure pg (Arg : G) is
584 Put_Line (G'Image (Arg));
591 function Sub_F (X, Y : F) return F is
596 Asm ("ldf %0,%1", S'Asm_Output ("=f", X1), F'Asm_Input ("m", X));
597 Asm ("ldf %0,%1", S'Asm_Output ("=f", Y1), F'Asm_Input ("m", Y));
598 Asm ("subf %1,%2,%0", S'Asm_Output ("=f", R),
599 (S'Asm_Input ("f", X1), S'Asm_Input ("f", Y1)));
600 Asm ("stf %1,%0", F'Asm_Output ("=m", R1), S'Asm_Input ("f", R));
608 function Sub_G (X, Y : G) return G is
612 Asm ("ldg %0,%1", T'Asm_Output ("=f", X1), G'Asm_Input ("m", X));
613 Asm ("ldg %0,%1", T'Asm_Output ("=f", Y1), G'Asm_Input ("m", Y));
614 Asm ("subg %1,%2,%0", T'Asm_Output ("=f", R),
615 (T'Asm_Input ("f", X1), T'Asm_Input ("f", Y1)));
616 Asm ("stg %1,%0", G'Asm_Output ("=m", R1), T'Asm_Input ("f", R));
624 -- For now, convert to IEEE and do Valid test on result. This is not quite
625 -- accurate, but is good enough in practice.
627 function Valid_D (Arg : D) return Boolean is
628 Val : constant T := G_To_T (D_To_G (Arg));
637 -- For now, convert to IEEE and do Valid test on result. This is not quite
638 -- accurate, but is good enough in practice.
640 function Valid_F (Arg : F) return Boolean is
641 Val : constant S := F_To_S (Arg);
650 -- For now, convert to IEEE and do Valid test on result. This is not quite
651 -- accurate, but is good enough in practice.
653 function Valid_G (Arg : G) return Boolean is
654 Val : constant T := G_To_T (Arg);
659 end System.Vax_Float_Operations;