1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- G N A T . A L T I V E C . C O N V E R S I O N S --
9 -- Copyright (C) 2005, Free Software Foundation, Inc. --
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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
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. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 with Ada.Unchecked_Conversion;
36 with System; use System;
38 with GNAT.Altivec.Low_Level_Interface; use GNAT.Altivec.Low_Level_Interface;
39 with GNAT.Altivec.Low_Level_Vectors; use GNAT.Altivec.Low_Level_Vectors;
41 package body GNAT.Altivec.Conversions is
43 function To_Varray_unsigned_char is
44 new Ada.Unchecked_Conversion (Varray_signed_char,
45 Varray_unsigned_char);
47 function To_Varray_unsigned_char is
48 new Ada.Unchecked_Conversion (Varray_bool_char,
49 Varray_unsigned_char);
51 function To_Varray_unsigned_short is
52 new Ada.Unchecked_Conversion (Varray_signed_short,
53 Varray_unsigned_short);
55 function To_Varray_unsigned_short is
56 new Ada.Unchecked_Conversion (Varray_bool_short,
57 Varray_unsigned_short);
59 function To_Varray_unsigned_short is
60 new Ada.Unchecked_Conversion (Varray_pixel,
61 Varray_unsigned_short);
63 function To_Varray_unsigned_int is
64 new Ada.Unchecked_Conversion (Varray_signed_int,
67 function To_Varray_unsigned_int is
68 new Ada.Unchecked_Conversion (Varray_bool_int,
71 function To_Varray_unsigned_int is
72 new Ada.Unchecked_Conversion (Varray_float,
75 function To_Varray_signed_char is
76 new Ada.Unchecked_Conversion (Varray_unsigned_char,
79 function To_Varray_bool_char is
80 new Ada.Unchecked_Conversion (Varray_unsigned_char,
83 function To_Varray_signed_short is
84 new Ada.Unchecked_Conversion (Varray_unsigned_short,
87 function To_Varray_bool_short is
88 new Ada.Unchecked_Conversion (Varray_unsigned_short,
91 function To_Varray_pixel is
92 new Ada.Unchecked_Conversion (Varray_unsigned_short,
95 function To_Varray_signed_int is
96 new Ada.Unchecked_Conversion (Varray_unsigned_int,
99 function To_Varray_bool_int is
100 new Ada.Unchecked_Conversion (Varray_unsigned_int,
103 function To_Varray_float is
104 new Ada.Unchecked_Conversion (Varray_unsigned_int,
107 function To_VUC is new Ada.Unchecked_Conversion (VUC_View, VUC);
108 function To_VSC is new Ada.Unchecked_Conversion (VSC_View, VSC);
109 function To_VBC is new Ada.Unchecked_Conversion (VBC_View, VBC);
110 function To_VUS is new Ada.Unchecked_Conversion (VUS_View, VUS);
111 function To_VSS is new Ada.Unchecked_Conversion (VSS_View, VSS);
112 function To_VBS is new Ada.Unchecked_Conversion (VBS_View, VBS);
113 function To_VUI is new Ada.Unchecked_Conversion (VUI_View, VUI);
114 function To_VSI is new Ada.Unchecked_Conversion (VSI_View, VSI);
115 function To_VBI is new Ada.Unchecked_Conversion (VBI_View, VBI);
116 function To_VF is new Ada.Unchecked_Conversion (VF_View, VF);
117 function To_VP is new Ada.Unchecked_Conversion (VP_View, VP);
119 function To_VUC_View is new Ada.Unchecked_Conversion (VUC, VUC_View);
120 function To_VSC_View is new Ada.Unchecked_Conversion (VSC, VSC_View);
121 function To_VBC_View is new Ada.Unchecked_Conversion (VBC, VBC_View);
122 function To_VUS_View is new Ada.Unchecked_Conversion (VUS, VUS_View);
123 function To_VSS_View is new Ada.Unchecked_Conversion (VSS, VSS_View);
124 function To_VBS_View is new Ada.Unchecked_Conversion (VBS, VBS_View);
125 function To_VUI_View is new Ada.Unchecked_Conversion (VUI, VUI_View);
126 function To_VSI_View is new Ada.Unchecked_Conversion (VSI, VSI_View);
127 function To_VBI_View is new Ada.Unchecked_Conversion (VBI, VBI_View);
128 function To_VF_View is new Ada.Unchecked_Conversion (VF, VF_View);
129 function To_VP_View is new Ada.Unchecked_Conversion (VP, VP_View);
131 pragma Warnings (Off, Default_Bit_Order);
137 function To_Vector (S : VSC_View) return VSC is
139 if Default_Bit_Order = High_Order_First then
144 VS : constant VUC_View :=
145 (Values => To_Varray_unsigned_char (S.Values));
147 Result := To_Vector (VS);
148 return To_LL_VSC (Result);
153 function To_Vector (S : VBC_View) return VBC is
155 if Default_Bit_Order = High_Order_First then
160 VS : constant VUC_View :=
161 (Values => To_Varray_unsigned_char (S.Values));
163 Result := To_Vector (VS);
164 return To_LL_VBC (Result);
169 function To_Vector (S : VSS_View) return VSS is
171 if Default_Bit_Order = High_Order_First then
176 VS : constant VUS_View :=
177 (Values => To_Varray_unsigned_short (S.Values));
179 Result := To_Vector (VS);
180 return VSS (To_LL_VSS (Result));
185 function To_Vector (S : VBS_View) return VBS is
187 if Default_Bit_Order = High_Order_First then
192 VS : constant VUS_View :=
193 (Values => To_Varray_unsigned_short (S.Values));
195 Result := To_Vector (VS);
196 return To_LL_VBS (Result);
201 function To_Vector (S : VP_View) return VP is
203 if Default_Bit_Order = High_Order_First then
208 VS : constant VUS_View :=
209 (Values => To_Varray_unsigned_short (S.Values));
211 Result := To_Vector (VS);
212 return To_LL_VP (Result);
217 function To_Vector (S : VSI_View) return VSI is
219 if Default_Bit_Order = High_Order_First then
224 VS : constant VUI_View :=
225 (Values => To_Varray_unsigned_int (S.Values));
227 Result := To_Vector (VS);
228 return To_LL_VSI (Result);
233 function To_Vector (S : VBI_View) return VBI is
235 if Default_Bit_Order = High_Order_First then
240 VS : constant VUI_View :=
241 (Values => To_Varray_unsigned_int (S.Values));
243 Result := To_Vector (VS);
244 return To_LL_VBI (Result);
249 function To_Vector (S : VF_View) return VF is
251 if Default_Bit_Order = High_Order_First then
256 VS : constant VUI_View :=
257 (Values => To_Varray_unsigned_int (S.Values));
259 Result := To_Vector (VS);
260 return To_LL_VF (Result);
265 function To_Vector (S : VUC_View) return VUC is
267 if Default_Bit_Order = High_Order_First then
273 for J in Vchar_Range'Range loop
275 S.Values (Vchar_Range'Last - J + Vchar_Range'First);
277 return To_VUC (Result);
282 function To_Vector (S : VUS_View) return VUS is
284 if Default_Bit_Order = High_Order_First then
290 for J in Vshort_Range'Range loop
292 S.Values (Vshort_Range'Last - J + Vshort_Range'First);
294 return To_VUS (Result);
299 function To_Vector (S : VUI_View) return VUI is
301 if Default_Bit_Order = High_Order_First then
307 for J in Vint_Range'Range loop
309 S.Values (Vint_Range'Last - J + Vint_Range'First);
311 return To_VUI (Result);
320 function To_View (S : VSC) return VSC_View is
322 if Default_Bit_Order = High_Order_First then
323 return To_VSC_View (S);
328 Result := To_View (To_LL_VUC (S));
329 return (Values => To_Varray_signed_char (Result.Values));
334 function To_View (S : VBC) return VBC_View is
336 if Default_Bit_Order = High_Order_First then
337 return To_VBC_View (S);
342 Result := To_View (To_LL_VUC (S));
343 return (Values => To_Varray_bool_char (Result.Values));
348 function To_View (S : VSS) return VSS_View is
350 if Default_Bit_Order = High_Order_First then
351 return To_VSS_View (S);
356 Result := To_View (To_LL_VUS (S));
357 return (Values => To_Varray_signed_short (Result.Values));
362 function To_View (S : VBS) return VBS_View is
364 if Default_Bit_Order = High_Order_First then
365 return To_VBS_View (S);
370 Result := To_View (To_LL_VUS (S));
371 return (Values => To_Varray_bool_short (Result.Values));
376 function To_View (S : VP) return VP_View is
378 if Default_Bit_Order = High_Order_First then
379 return To_VP_View (S);
384 Result := To_View (To_LL_VUS (S));
385 return (Values => To_Varray_pixel (Result.Values));
390 function To_View (S : VSI) return VSI_View is
392 if Default_Bit_Order = High_Order_First then
393 return To_VSI_View (S);
398 Result := To_View (To_LL_VUI (S));
399 return (Values => To_Varray_signed_int (Result.Values));
404 function To_View (S : VBI) return VBI_View is
406 if Default_Bit_Order = High_Order_First then
407 return To_VBI_View (S);
412 Result := To_View (To_LL_VUI (S));
413 return (Values => To_Varray_bool_int (Result.Values));
418 function To_View (S : VF) return VF_View is
420 if Default_Bit_Order = High_Order_First then
421 return To_VF_View (S);
426 Result := To_View (To_LL_VUI (S));
427 return (Values => To_Varray_float (Result.Values));
432 function To_View (S : VUC) return VUC_View is
434 if Default_Bit_Order = High_Order_First then
435 return To_VUC_View (S);
438 VS : constant VUC_View := To_VUC_View (S);
441 for J in Vchar_Range'Range loop
443 VS.Values (Vchar_Range'Last - J + Vchar_Range'First);
450 function To_View (S : VUS) return VUS_View is
452 if Default_Bit_Order = High_Order_First then
453 return To_VUS_View (S);
456 VS : constant VUS_View := To_VUS_View (S);
459 for J in Vshort_Range'Range loop
461 VS.Values (Vshort_Range'Last - J + Vshort_Range'First);
468 function To_View (S : VUI) return VUI_View is
470 if Default_Bit_Order = High_Order_First then
471 return To_VUI_View (S);
474 VS : constant VUI_View := To_VUI_View (S);
477 for J in Vint_Range'Range loop
479 VS.Values (Vint_Range'Last - J + Vint_Range'First);
486 end GNAT.Altivec.Conversions;