OSDN Git Service

2006-10-31 Javier Miranda <miranda@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / g-altcon.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --             G N A T . A L T I V E C . C O N V E R S I O N S              --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --            Copyright (C) 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,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, 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 with Ada.Unchecked_Conversion;
35
36 with System; use System;
37
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;
40
41 package body GNAT.Altivec.Conversions is
42
43    function To_Varray_unsigned_char is
44      new Ada.Unchecked_Conversion (Varray_signed_char,
45                                    Varray_unsigned_char);
46
47    function To_Varray_unsigned_char is
48      new Ada.Unchecked_Conversion (Varray_bool_char,
49                                    Varray_unsigned_char);
50
51    function To_Varray_unsigned_short is
52      new Ada.Unchecked_Conversion (Varray_signed_short,
53                                    Varray_unsigned_short);
54
55    function To_Varray_unsigned_short is
56      new Ada.Unchecked_Conversion (Varray_bool_short,
57                                    Varray_unsigned_short);
58
59    function To_Varray_unsigned_short is
60       new Ada.Unchecked_Conversion (Varray_pixel,
61                                     Varray_unsigned_short);
62
63    function To_Varray_unsigned_int is
64      new Ada.Unchecked_Conversion (Varray_signed_int,
65                                    Varray_unsigned_int);
66
67    function To_Varray_unsigned_int is
68      new Ada.Unchecked_Conversion (Varray_bool_int,
69                                    Varray_unsigned_int);
70
71    function To_Varray_unsigned_int is
72       new Ada.Unchecked_Conversion (Varray_float,
73                                     Varray_unsigned_int);
74
75    function To_Varray_signed_char is
76      new Ada.Unchecked_Conversion (Varray_unsigned_char,
77                                    Varray_signed_char);
78
79    function To_Varray_bool_char is
80      new Ada.Unchecked_Conversion (Varray_unsigned_char,
81                                    Varray_bool_char);
82
83    function To_Varray_signed_short is
84      new Ada.Unchecked_Conversion (Varray_unsigned_short,
85                                    Varray_signed_short);
86
87    function To_Varray_bool_short is
88      new Ada.Unchecked_Conversion (Varray_unsigned_short,
89                                    Varray_bool_short);
90
91    function To_Varray_pixel is
92      new Ada.Unchecked_Conversion (Varray_unsigned_short,
93                                    Varray_pixel);
94
95    function To_Varray_signed_int is
96      new Ada.Unchecked_Conversion (Varray_unsigned_int,
97                                    Varray_signed_int);
98
99    function To_Varray_bool_int is
100      new Ada.Unchecked_Conversion (Varray_unsigned_int,
101                                    Varray_bool_int);
102
103    function To_Varray_float is
104      new Ada.Unchecked_Conversion (Varray_unsigned_int,
105                                    Varray_float);
106
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);
118
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);
130
131    pragma Warnings (Off, Default_Bit_Order);
132
133    ---------------
134    -- To_Vector --
135    ---------------
136
137    function To_Vector (S : VSC_View) return VSC is
138    begin
139       if Default_Bit_Order = High_Order_First then
140          return To_VSC (S);
141       else
142          declare
143             Result : LL_VUC;
144             VS     : constant VUC_View :=
145                        (Values => To_Varray_unsigned_char (S.Values));
146          begin
147             Result := To_Vector (VS);
148             return To_LL_VSC (Result);
149          end;
150       end if;
151    end To_Vector;
152
153    function To_Vector (S : VBC_View) return VBC is
154    begin
155       if Default_Bit_Order = High_Order_First then
156          return To_VBC (S);
157       else
158          declare
159             Result : LL_VUC;
160             VS     : constant VUC_View :=
161                        (Values => To_Varray_unsigned_char (S.Values));
162          begin
163             Result := To_Vector (VS);
164             return To_LL_VBC (Result);
165          end;
166       end if;
167    end To_Vector;
168
169    function To_Vector (S : VSS_View) return VSS is
170    begin
171       if Default_Bit_Order = High_Order_First then
172          return To_VSS (S);
173       else
174          declare
175             Result : LL_VUS;
176             VS     : constant VUS_View :=
177                        (Values => To_Varray_unsigned_short (S.Values));
178          begin
179             Result := To_Vector (VS);
180             return VSS (To_LL_VSS (Result));
181          end;
182       end if;
183    end To_Vector;
184
185    function To_Vector (S : VBS_View) return VBS is
186    begin
187       if Default_Bit_Order = High_Order_First then
188          return To_VBS (S);
189       else
190          declare
191             Result : LL_VUS;
192             VS     : constant VUS_View :=
193                        (Values => To_Varray_unsigned_short (S.Values));
194          begin
195             Result := To_Vector (VS);
196             return To_LL_VBS (Result);
197          end;
198       end if;
199    end To_Vector;
200
201    function To_Vector (S : VP_View) return VP is
202    begin
203       if Default_Bit_Order = High_Order_First then
204          return To_VP (S);
205       else
206          declare
207             Result : LL_VUS;
208             VS     : constant VUS_View :=
209                        (Values => To_Varray_unsigned_short (S.Values));
210          begin
211             Result := To_Vector (VS);
212             return To_LL_VP (Result);
213          end;
214       end if;
215    end To_Vector;
216
217    function To_Vector (S : VSI_View) return VSI is
218    begin
219       if Default_Bit_Order = High_Order_First then
220          return To_VSI (S);
221       else
222          declare
223             Result : LL_VUI;
224             VS     : constant VUI_View :=
225                        (Values => To_Varray_unsigned_int (S.Values));
226          begin
227             Result := To_Vector (VS);
228             return To_LL_VSI (Result);
229          end;
230       end if;
231    end To_Vector;
232
233    function To_Vector (S : VBI_View) return VBI is
234    begin
235       if Default_Bit_Order = High_Order_First then
236          return To_VBI (S);
237       else
238          declare
239             Result : LL_VUI;
240             VS     : constant VUI_View :=
241                        (Values => To_Varray_unsigned_int (S.Values));
242          begin
243             Result := To_Vector (VS);
244             return To_LL_VBI (Result);
245          end;
246       end if;
247    end To_Vector;
248
249    function To_Vector (S : VF_View) return VF is
250    begin
251       if Default_Bit_Order = High_Order_First then
252          return To_VF (S);
253       else
254          declare
255             Result : LL_VUI;
256             VS     : constant VUI_View :=
257                        (Values => To_Varray_unsigned_int (S.Values));
258          begin
259             Result := To_Vector (VS);
260             return To_LL_VF (Result);
261          end;
262       end if;
263    end To_Vector;
264
265    function To_Vector (S : VUC_View) return VUC is
266    begin
267       if Default_Bit_Order = High_Order_First then
268          return To_VUC (S);
269       else
270          declare
271             Result : VUC_View;
272          begin
273             for J in Vchar_Range'Range loop
274                Result.Values (J) :=
275                  S.Values (Vchar_Range'Last - J + Vchar_Range'First);
276             end loop;
277             return To_VUC (Result);
278          end;
279       end if;
280    end To_Vector;
281
282    function To_Vector (S : VUS_View) return VUS is
283    begin
284       if Default_Bit_Order = High_Order_First then
285          return To_VUS (S);
286       else
287          declare
288             Result : VUS_View;
289          begin
290             for J in Vshort_Range'Range loop
291                Result.Values (J) :=
292                  S.Values (Vshort_Range'Last - J + Vshort_Range'First);
293             end loop;
294             return To_VUS (Result);
295          end;
296       end if;
297    end To_Vector;
298
299    function To_Vector (S : VUI_View) return VUI is
300    begin
301       if Default_Bit_Order = High_Order_First then
302          return To_VUI (S);
303       else
304          declare
305             Result : VUI_View;
306          begin
307             for J in Vint_Range'Range loop
308                Result.Values (J) :=
309                  S.Values (Vint_Range'Last - J + Vint_Range'First);
310             end loop;
311             return To_VUI (Result);
312          end;
313       end if;
314    end To_Vector;
315
316    --------------
317    -- To_View --
318    --------------
319
320    function To_View (S : VSC) return VSC_View is
321    begin
322       if Default_Bit_Order = High_Order_First then
323          return To_VSC_View (S);
324       else
325          declare
326             Result : VUC_View;
327          begin
328             Result := To_View (To_LL_VUC (S));
329             return (Values => To_Varray_signed_char (Result.Values));
330          end;
331       end if;
332    end To_View;
333
334    function To_View (S : VBC) return VBC_View is
335    begin
336       if Default_Bit_Order = High_Order_First then
337          return To_VBC_View (S);
338       else
339          declare
340             Result : VUC_View;
341          begin
342             Result := To_View (To_LL_VUC (S));
343             return (Values => To_Varray_bool_char (Result.Values));
344          end;
345       end if;
346    end To_View;
347
348    function To_View (S : VSS) return VSS_View is
349    begin
350       if Default_Bit_Order = High_Order_First then
351          return To_VSS_View (S);
352       else
353          declare
354             Result : VUS_View;
355          begin
356             Result := To_View (To_LL_VUS (S));
357             return (Values => To_Varray_signed_short (Result.Values));
358          end;
359       end if;
360    end To_View;
361
362    function To_View (S : VBS) return VBS_View is
363    begin
364       if Default_Bit_Order = High_Order_First then
365          return To_VBS_View (S);
366       else
367          declare
368             Result : VUS_View;
369          begin
370             Result := To_View (To_LL_VUS (S));
371             return (Values => To_Varray_bool_short (Result.Values));
372          end;
373       end if;
374    end To_View;
375
376    function To_View (S : VP) return VP_View is
377    begin
378       if Default_Bit_Order = High_Order_First then
379          return To_VP_View (S);
380       else
381          declare
382             Result : VUS_View;
383          begin
384             Result := To_View (To_LL_VUS (S));
385             return (Values => To_Varray_pixel (Result.Values));
386          end;
387       end if;
388    end To_View;
389
390    function To_View (S : VSI) return VSI_View is
391    begin
392       if Default_Bit_Order = High_Order_First then
393          return To_VSI_View (S);
394       else
395          declare
396             Result : VUI_View;
397          begin
398             Result := To_View (To_LL_VUI (S));
399             return (Values => To_Varray_signed_int (Result.Values));
400          end;
401       end if;
402    end To_View;
403
404    function To_View (S : VBI) return VBI_View is
405    begin
406       if Default_Bit_Order = High_Order_First then
407          return To_VBI_View (S);
408       else
409          declare
410             Result : VUI_View;
411          begin
412             Result := To_View (To_LL_VUI (S));
413             return (Values => To_Varray_bool_int (Result.Values));
414          end;
415       end if;
416    end To_View;
417
418    function To_View (S : VF) return VF_View is
419    begin
420       if Default_Bit_Order = High_Order_First then
421          return To_VF_View (S);
422       else
423          declare
424             Result : VUI_View;
425          begin
426             Result := To_View (To_LL_VUI (S));
427             return (Values => To_Varray_float (Result.Values));
428          end;
429       end if;
430    end To_View;
431
432    function To_View (S : VUC) return VUC_View is
433    begin
434       if Default_Bit_Order = High_Order_First then
435          return To_VUC_View (S);
436       else
437          declare
438             VS     : constant VUC_View := To_VUC_View (S);
439             Result : VUC_View;
440          begin
441             for J in Vchar_Range'Range loop
442                Result.Values (J) :=
443                  VS.Values (Vchar_Range'Last - J + Vchar_Range'First);
444             end loop;
445             return Result;
446          end;
447       end if;
448    end To_View;
449
450    function To_View (S : VUS) return VUS_View is
451    begin
452       if Default_Bit_Order = High_Order_First then
453          return To_VUS_View (S);
454       else
455          declare
456             VS     : constant VUS_View := To_VUS_View (S);
457             Result : VUS_View;
458          begin
459             for J in Vshort_Range'Range loop
460                Result.Values (J) :=
461                  VS.Values (Vshort_Range'Last - J + Vshort_Range'First);
462             end loop;
463             return Result;
464          end;
465       end if;
466    end To_View;
467
468    function To_View (S : VUI) return VUI_View is
469    begin
470       if Default_Bit_Order = High_Order_First then
471          return To_VUI_View (S);
472       else
473          declare
474             VS     : constant VUI_View := To_VUI_View (S);
475             Result : VUI_View;
476          begin
477             for J in Vint_Range'Range loop
478                Result.Values (J) :=
479                  VS.Values (Vint_Range'Last - J + Vint_Range'First);
480             end loop;
481             return Result;
482          end;
483       end if;
484    end To_View;
485
486 end GNAT.Altivec.Conversions;