copied mono-api-diff.cs from mono-2-2 branch so new patch can be applied and history...
[mono.git] / mcs / class / Mono.Simd / Mono.Simd / Vector8s.cs
1 // Vector8s.cs
2 //
3 // Author:
4 //   Rodrigo Kumpera (rkumpera@novell.com)
5 //
6 // (C) 2008 Novell, Inc. (http://www.novell.com)
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining
9 // a copy of this software and associated documentation files (the
10 // "Software"), to deal in the Software without restriction, including
11 // without limitation the rights to use, copy, modify, merge, publish,
12 // distribute, sublicense, and/or sell copies of the Software, and to
13 // permit persons to whom the Software is furnished to do so, subject to
14 // the following conditions:
15 //
16 // The above copyright notice and this permission notice shall be
17 // included in all copies or substantial portions of the Software.
18 //
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 //
27 using System;
28 using System.Runtime.InteropServices;
29
30 namespace Mono.Simd
31 {
32         [StructLayout(LayoutKind.Explicit, Pack = 0, Size = 16)]
33         public struct Vector8s
34         {
35                 [ FieldOffset(0) ]
36                 internal short v0;
37                 [ FieldOffset(2) ]
38                 internal short v1;
39                 [ FieldOffset(4) ]
40                 internal short v2;
41                 [ FieldOffset(6) ]
42                 internal short v3;
43                 [ FieldOffset(8) ]
44                 internal short v4;
45                 [ FieldOffset(10) ]
46                 internal short v5;
47                 [ FieldOffset(12) ]
48                 internal short v6;
49                 [ FieldOffset(14) ]
50                 internal short v7;
51
52                 public Vector8s (short v0, short v1, short v2, short v3, short v4, short v5, short v6, short v7)
53                 {
54                         this.v0 = v0;
55                         this.v1 = v1;
56                         this.v2 = v2;
57                         this.v3 = v3;
58                         this.v4 = v4;
59                         this.v5 = v5;
60                         this.v6 = v6;
61                         this.v7 = v7;
62                 }
63                 
64                 public Vector8s (short s)
65                 {
66                         this.v0 = s;
67                         this.v1 = s;
68                         this.v2 = s;
69                         this.v3 = s;
70                         this.v4 = s;
71                         this.v5 = s;
72                         this.v6 = s;
73                         this.v7 = s;
74                 }
75
76                 public short V0 { get { return v0; } set { v0 = value; } }
77                 public short V1 { get { return v1; } set { v1 = value; } }
78                 public short V2 { get { return v2; } set { v2 = value; } }
79                 public short V3 { get { return v3; } set { v3 = value; } }
80                 public short V4 { get { return v4; } set { v4 = value; } }
81                 public short V5 { get { return v5; } set { v5 = value; } }
82                 public short V6 { get { return v6; } set { v6 = value; } }
83                 public short V7 { get { return v7; } set { v7 = value; } }
84
85                 public static Vector8s Identity
86                 {
87                         get { return  new Vector8s (1); }
88                 }
89
90                 public static Vector8s Zero
91                 {
92                         get { return  new Vector8s (0); }
93                 }
94
95                 public static Vector8s MinusOne
96                 {
97                         get { return new Vector8s (-1); }
98                 }
99
100                 [System.Runtime.CompilerServices.IndexerName ("Component")]
101                 public unsafe short this [int index]
102                 {
103                         get {
104                                 if ((index | 0x7) != 0x7) //index < 0 || index > 7
105                                         throw new ArgumentOutOfRangeException ("index");
106                                 fixed (short *v = &v0) {
107                                         return * (v + index);
108                                 }
109                         }
110                         set {
111                                 if ( (index | 0x7) != 0x7) //index < 0 || index > 7
112                                         throw new ArgumentOutOfRangeException ("index");
113                                 fixed (short *v = &v0) {
114                                         * (v + index) = value;
115                                 }
116                         }
117                 }
118
119                 [Acceleration (AccelMode.SSE2)]
120                 public static unsafe Vector8s operator + (Vector8s va, Vector8s vb)
121                 {
122                         Vector8s res = new Vector8s ();
123                         short *a = &va.v0;
124                         short *b = &vb.v0;
125                         short *c = &res.v0;
126                         for (int i = 0; i < 8; ++i)
127                                 *c++ = (short)(*a++ + *b++);
128                         return res;
129                 }
130
131                 [Acceleration (AccelMode.SSE2)]
132                 public static unsafe Vector8s operator - (Vector8s va, Vector8s vb)
133                 {
134                         Vector8s res = new Vector8s ();
135                         short *a = &va.v0;
136                         short *b = &vb.v0;
137                         short *c = &res.v0;
138                         for (int i = 0; i < 8; ++i)
139                                 *c++ = (short)(*a++ - *b++);
140                         return res;
141                 }
142
143                 [Acceleration (AccelMode.SSE2)]
144                 public static unsafe Vector8s operator * (Vector8s va, Vector8s vb)
145                 {
146                         Vector8s res = new Vector8s ();
147                         short *a = &va.v0;
148                         short *b = &vb.v0;
149                         short *c = &res.v0;
150                         for (int i = 0; i < 8; ++i)
151                                 *c++ = (short)(*a++ * (*b++));
152                         return res;
153                 }
154
155                 [Acceleration (AccelMode.SSE2)]
156                 public static unsafe Vector8s operator >> (Vector8s va, int amount)
157                 {
158                         Vector8s res = new Vector8s ();
159                         short *a = &va.v0;
160                         short *b = &res.v0;
161                         for (int i = 0; i < 8; ++i)
162                                 *b++ = (short)(*a++ >> amount);
163                         return res;
164                 }
165
166                 [Acceleration (AccelMode.SSE2)]
167                 public static unsafe Vector8s operator << (Vector8s va, int amount)
168                 {
169                         Vector8s res = new Vector8s ();
170                         short *a = &va.v0;
171                         short *b = &res.v0;
172                         for (int i = 0; i < 8; ++i)
173                                 *b++ = (short)(*a++ << amount);
174                         return res;
175                 }
176
177                 [Acceleration (AccelMode.SSE2)]
178                 public static unsafe Vector8s operator & (Vector8s va, Vector8s vb)
179                 {
180                         Vector8s res = new Vector8s ();
181                         uint *a = (uint*) &va.v0;
182                         uint *b = (uint*) &vb.v0;
183                         uint *c = (uint*) &res.v0;
184                         *c++ = *a++ & *b++;
185                         *c++ = *a++ & *b++;
186                         *c++ = *a++ & *b++;
187                         *c = *a & *b;
188                         return res;
189                 }
190
191                 [Acceleration (AccelMode.SSE2)]
192                 public static unsafe Vector8s operator | (Vector8s va, Vector8s vb)
193                 {
194                         Vector8s res = new Vector8s ();
195                         uint *a = (uint*) &va.v0;
196                         uint *b = (uint*) &vb.v0;
197                         uint *c = (uint*) &res.v0;
198                         *c++ = *a++ | *b++;
199                         *c++ = *a++ | *b++;
200                         *c++ = *a++ | *b++;
201                         *c = *a | *b;
202                         return res;
203                 }
204
205                 [Acceleration (AccelMode.SSE2)]
206                 public static unsafe Vector8s operator ^ (Vector8s va, Vector8s vb)
207                 {
208                         Vector8s res = new Vector8s ();
209                         uint *a = (uint*) &va.v0;
210                         uint *b = (uint*) &vb.v0;
211                         uint *c = (uint*) &res.v0;
212                         *c++ = *a++ ^ *b++;
213                         *c++ = *a++ ^ *b++;
214                         *c++ = *a++ ^ *b++;
215                         *c = *a ^ *b;
216                         return res;
217                 }
218
219                 [Acceleration (AccelMode.SSE2)]
220                 public unsafe static bool operator ==(Vector8s va, Vector8s vb)
221                 {
222                         short *a = &va.v0;
223                         short *b = &vb.v0;
224                         for (int i = 0; i < 8; ++i)
225                                 if (*a++ != *b++)
226                                         return false;
227                         return true;
228                 }
229
230                 [Acceleration (AccelMode.SSE2)]
231                 public unsafe static bool operator !=(Vector8s va, Vector8s vb)
232                 {
233                         short *a = &va.v0;
234                         short *b = &vb.v0;
235                         for (int i = 0; i < 8; ++i)
236                                 if (*a++ != *b++)
237                                         return true;
238                         return false;
239                 }
240
241                 [Acceleration (AccelMode.SSE1)]
242                 public static unsafe explicit operator Vector2d (Vector8s v)
243                 {
244                         Vector2d* p = (Vector2d*)&v;
245                         return *p;
246                 }
247
248                 [Acceleration (AccelMode.SSE1)]
249                 public static unsafe explicit operator Vector4f (Vector8s v)
250                 {
251                         Vector4f* p = (Vector4f*)&v;
252                         return *p;
253                 }
254
255                 [Acceleration (AccelMode.SSE1)]
256                 public static unsafe explicit operator Vector2l (Vector8s v)
257                 {
258                         Vector2l* p = (Vector2l*)&v;
259                         return *p;
260                 }
261
262                 [Acceleration (AccelMode.SSE1)]
263                 [CLSCompliant(false)]
264                 public static unsafe explicit operator Vector2ul (Vector8s v)
265                 {
266                         Vector2ul* p = (Vector2ul*)&v;
267                         return *p;
268                 }
269
270                 [Acceleration (AccelMode.SSE1)]
271                 public static unsafe explicit operator Vector4i (Vector8s v)
272                 {
273                         Vector4i* p = (Vector4i*)&v;
274                         return *p;
275                 }
276
277                 [Acceleration (AccelMode.SSE1)]
278                 [CLSCompliant(false)]
279                 public static unsafe explicit operator Vector4ui (Vector8s v)
280                 {
281                         Vector4ui* p = (Vector4ui*)&v;
282                         return *p;
283                 }
284
285                 [Acceleration (AccelMode.SSE1)]
286                 [CLSCompliant(false)]
287                 public static unsafe explicit operator Vector8us (Vector8s v)
288                 {
289                         Vector8us* p = (Vector8us*)&v;
290                         return *p;
291                 }
292
293                 [Acceleration (AccelMode.SSE1)]
294                 [CLSCompliant(false)]
295                 public static unsafe explicit operator Vector16sb (Vector8s v)
296                 {
297                         Vector16sb* p = (Vector16sb*)&v;
298                         return *p;
299                 }
300
301                 [Acceleration (AccelMode.SSE1)]
302                 public static unsafe explicit operator Vector16b (Vector8s v)
303                 {
304                         Vector16b* p = (Vector16b*)&v;
305                         return *p;
306                 }
307
308
309                 [Acceleration (AccelMode.SSE1)]
310                 public static Vector8s LoadAligned (ref Vector8s v)
311                 {
312                         return v;
313                 }
314
315                 [Acceleration (AccelMode.SSE1)]
316                 public static void StoreAligned (ref Vector8s res, Vector8s val)
317                 {
318                         res = val;
319                 }
320
321                 [CLSCompliant(false)]
322                 [Acceleration (AccelMode.SSE1)]
323                 public static unsafe Vector8s LoadAligned (Vector8s *v)
324                 {
325                         return *v;
326                 }
327
328                 [CLSCompliant(false)]
329                 [Acceleration (AccelMode.SSE1)]
330                 public static unsafe void StoreAligned (Vector8s *res, Vector8s val)
331                 {
332                         *res = val;
333                 }
334
335                 [Acceleration (AccelMode.SSE1)]
336                 [CLSCompliant(false)]
337                 public static void PrefetchTemporalAllCacheLevels (ref Vector8s res)
338                 {
339                 }
340
341                 [Acceleration (AccelMode.SSE1)]
342                 [CLSCompliant(false)]
343                 public static void PrefetchTemporal1stLevelCache (ref Vector8s res)
344                 {
345                 }
346
347                 [Acceleration (AccelMode.SSE1)]
348                 [CLSCompliant(false)]
349                 public static void PrefetchTemporal2ndLevelCache (ref Vector8s res)
350                 {
351                 }
352
353                 [Acceleration (AccelMode.SSE1)]
354                 [CLSCompliant(false)]
355                 public static void PrefetchNonTemporal (ref Vector8s res)
356                 {
357                 }
358
359                 [Acceleration (AccelMode.SSE1)]
360                 [CLSCompliant(false)]
361                 public static unsafe void PrefetchTemporalAllCacheLevels (Vector8s *res)
362                 {
363                 }
364
365                 [Acceleration (AccelMode.SSE1)]
366                 [CLSCompliant(false)]
367                 public static unsafe void PrefetchTemporal1stLevelCache (Vector8s *res)
368                 {
369                 }
370
371                 [Acceleration (AccelMode.SSE1)]
372                 [CLSCompliant(false)]
373                 public static unsafe void PrefetchTemporal2ndLevelCache (Vector8s *res)
374                 {
375                 }
376
377                 [Acceleration (AccelMode.SSE1)]
378                 [CLSCompliant(false)]
379                 public static unsafe void PrefetchNonTemporal (Vector8s *res)
380                 {
381                 }
382                 
383                 public override string ToString()
384                 {
385                         return "<" + v0 + ", " + v1 + ", " + v2 + ", " + v3 + ", " +
386                                         v4 + ", " + v5 + ", " + v6 + ", " + v7 + ">"; 
387                 }
388         }
389 }