2008-12-05 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mcs / class / Mono.Simd / Mono.Simd / Vector16sb.cs
1 // Vector16sb.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.Sequential, Pack = 0, Size = 16)]
33         [CLSCompliant(false)]
34         public struct Vector16sb
35         {
36                 private sbyte v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15;
37                 public Vector16sb (sbyte v0, sbyte v1, sbyte v2, sbyte v3, sbyte v4, sbyte v5, sbyte v6, sbyte v7, sbyte v8, sbyte v9, sbyte v10, sbyte v11, sbyte v12, sbyte v13, sbyte v14, sbyte v15)
38                 {
39                         this.v0 = v0;
40                         this.v1 = v1;
41                         this.v2 = v2;
42                         this.v3 = v3;
43                         this.v4 = v4;
44                         this.v5 = v5;
45                         this.v6 = v6;
46                         this.v7 = v7;
47                         this.v8 = v8;
48                         this.v9 = v9;
49                         this.v10 = v10;
50                         this.v11 = v11;
51                         this.v12 = v12;
52                         this.v13 = v13;
53                         this.v14 = v14;
54                         this.v15 = v15;         }
55
56                 public sbyte V0 { get { return v0; } set { v0 = value; } }
57                 public sbyte V1 { get { return v1; } set { v1 = value; } }
58                 public sbyte V2 { get { return v2; } set { v2 = value; } }
59                 public sbyte V3 { get { return v3; } set { v3 = value; } }
60                 public sbyte V4 { get { return v4; } set { v4 = value; } }
61                 public sbyte V5 { get { return v5; } set { v5 = value; } }
62                 public sbyte V6 { get { return v6; } set { v6 = value; } }
63                 public sbyte V7 { get { return v7; } set { v7 = value; } }
64                 public sbyte V8 { get { return v8; } set { v8 = value; } }
65                 public sbyte V9 { get { return v9; } set { v9 = value; } }
66                 public sbyte V10 { get { return v10; } set { v10 = value; } }
67                 public sbyte V11 { get { return v11; } set { v11 = value; } }
68                 public sbyte V12 { get { return v12; } set { v12 = value; } }
69                 public sbyte V13 { get { return v13; } set { v13 = value; } }
70                 public sbyte V14 { get { return v14; } set { v14 = value; } }
71                 public sbyte V15 { get { return v15; } set { v15 = value; } }
72
73                 [System.Runtime.CompilerServices.IndexerName ("Component")]
74                 public unsafe sbyte this [int index]
75                 {
76                         get {
77                                 if ((index | 0xF) != 0xF) //index < 0 || index > 15
78                                         throw new ArgumentOutOfRangeException ("index");
79                                 fixed (sbyte *v = &v0) {
80                                         return *(v + index);
81                                 }
82                         }
83                         set {
84                                 if ( (index | 0xF) != 0xF) //index < 0 || index > 15
85                                         throw new ArgumentOutOfRangeException ("index");
86                                 fixed (sbyte *v = &v0) {
87                                         *(v + index) = value;
88                                 }
89                         }
90                 }
91
92                 [Acceleration (AccelMode.SSE2)]
93                 public static unsafe Vector16sb operator + (Vector16sb va, Vector16sb vb)
94                 {
95                         Vector16sb res = new Vector16sb ();
96                         sbyte *a = &va.v0;
97                         sbyte *b = &vb.v0;
98                         sbyte *c = &res.v0;
99                         for (int i = 0; i < 16; ++i)
100                                 *c++ = (sbyte)(*a++ + *b++);
101                         return res;
102                 }
103
104                 [Acceleration (AccelMode.SSE2)]
105                 public static unsafe Vector16sb operator - (Vector16sb va, Vector16sb vb)
106                 {
107                         Vector16sb res = new Vector16sb ();
108                         sbyte *a = &va.v0;
109                         sbyte *b = &vb.v0;
110                         sbyte *c = &res.v0;
111                         for (int i = 0; i < 16; ++i)
112                                 *c++ = (sbyte)(*a++ - *b++);
113                         return res;
114                 }
115
116                 [Acceleration (AccelMode.SSE2)]
117                 public static unsafe Vector16sb operator & (Vector16sb va, Vector16sb vb)
118                 {
119                         Vector16sb res = new Vector16sb ();
120                         uint *a = (uint*) &va.v0;
121                         uint *b = (uint*) &vb.v0;
122                         uint *c = (uint*) &res.v0;
123                         *c++ = *a++ & *b++;
124                         *c++ = *a++ & *b++;
125                         *c++ = *a++ & *b++;
126                         *c = *a & *b;
127                         return res;
128                 }
129
130                 [Acceleration (AccelMode.SSE2)]
131                 public static unsafe Vector16sb operator | (Vector16sb va, Vector16sb vb)
132                 {
133                         Vector16sb res = new Vector16sb ();
134                         uint *a = (uint*) &va.v0;
135                         uint *b = (uint*) &vb.v0;
136                         uint *c = (uint*) &res.v0;
137                         *c++ = *a++ | *b++;
138                         *c++ = *a++ | *b++;
139                         *c++ = *a++ | *b++;
140                         *c = *a | *b;
141                         return res;
142                 }
143
144                 [Acceleration (AccelMode.SSE2)]
145                 public static unsafe Vector16sb operator ^ (Vector16sb va, Vector16sb vb)
146                 {
147                         Vector16sb res = new Vector16sb ();
148                         uint *a = (uint*) &va.v0;
149                         uint *b = (uint*) &vb.v0;
150                         uint *c = (uint*) &res.v0;
151                         *c++ = *a++ ^ *b++;
152                         *c++ = *a++ ^ *b++;
153                         *c++ = *a++ ^ *b++;
154                         *c = *a ^ *b;
155                         return res;
156                 }
157
158                 [Acceleration (AccelMode.SSE2)]
159                 public unsafe static bool operator ==(Vector16sb va, Vector16sb vb)
160                 {
161                         sbyte *a = &va.v0;
162                         sbyte *b = &vb.v0;
163                         for (int i = 0; i < 16; ++i)
164                                 if (*a++ != *b++)
165                                         return false;
166                         return true;
167                 }
168
169                 [Acceleration (AccelMode.SSE2)]
170                 public unsafe static bool operator !=(Vector16sb va, Vector16sb vb)
171                 {
172                         sbyte *a = &va.v0;
173                         sbyte *b = &vb.v0;
174                         for (int i = 0; i < 16; ++i)
175                                 if (*a++ != *b++)
176                                         return true;
177                         return false;
178                 }
179
180                 [Acceleration (AccelMode.SSE2)]
181                 public static unsafe Vector16sb UnpackLow (Vector16sb va, Vector16sb vb)
182                 {
183                         return new Vector16sb (va.v0, vb.v0, va.v1, vb.v1, va.v2, vb.v2, va.v3, vb.v3, va.v4, vb.v4, va.v5, vb.v5, va.v6, vb.v6, va.v7, vb.v7);
184                 }
185
186                 [Acceleration (AccelMode.SSE2)]
187                 public static unsafe Vector16sb UnpackHigh (Vector16sb va, Vector16sb vb)
188                 {
189                         return new Vector16sb (va.v8, vb.v8, va.v9, vb.v9, va.v10, vb.v10, va.v11, vb.v11, va.v12, vb.v12, va.v13, vb.v13, va.v14, vb.v14, va.v15, vb.v15);
190                 }
191
192                 [Acceleration (AccelMode.SSE2)]
193                 public static unsafe Vector16sb AddWithSaturation (Vector16sb va, Vector16sb vb) {
194                         Vector16sb res = new Vector16sb ();
195                         sbyte *a = &va.v0;
196                         sbyte *b = &vb.v0;
197                         sbyte *c = &res.v0;
198                         for (int i = 0; i < 16; ++i)
199                                 *c++ = (sbyte) System.Math.Max (System.Math.Min (*a++ + *b++, sbyte.MaxValue), sbyte.MinValue);
200                         return res;
201                 }
202
203                 [Acceleration (AccelMode.SSE2)]
204                 public static unsafe Vector16sb SubtractWithSaturation (Vector16sb va, Vector16sb vb) {
205                         Vector16sb res = new Vector16sb ();
206                         sbyte *a = &va.v0;
207                         sbyte *b = &vb.v0;
208                         sbyte *c = &res.v0;
209                         for (int i = 0; i < 16; ++i)
210                                 *c++ = (sbyte) System.Math.Max (System.Math.Min (*a++ - *b++, sbyte.MaxValue), sbyte.MinValue);
211                         return res;
212                 }
213
214                 [Acceleration (AccelMode.SSE41)]
215                 public static unsafe Vector16sb Max (Vector16sb va, Vector16sb vb) {
216                         Vector16sb res = new Vector16sb ();
217                         sbyte *a = &va.v0;
218                         sbyte *b = &vb.v0;
219                         sbyte *c = &res.v0;
220                         for (int i = 0; i < 16; ++i)
221                                 *c++ = (sbyte) System.Math.Max (*a++, *b++);
222                         return res;
223                 }
224
225                 [Acceleration (AccelMode.SSE41)]
226                 public static unsafe Vector16sb Min (Vector16sb va, Vector16sb vb) {
227                         Vector16sb res = new Vector16sb ();
228                         sbyte *a = &va.v0;
229                         sbyte *b = &vb.v0;
230                         sbyte *c = &res.v0;
231                         for (int i = 0; i < 16; ++i)
232                                 *c++ = (sbyte) System.Math.Min(*a++, *b++);
233                         return res;
234                 }
235
236                 [Acceleration (AccelMode.SSE2)]
237                 public static unsafe int ExtractByteMask (Vector16sb va) {
238                         int res = 0;
239                         sbyte *a = (sbyte*)&va;
240                         for (int i = 0; i < 16; ++i)
241                                 res |= (*a++ & 0x80) >> 7 << i;
242                         return res;
243                 }
244
245                 [Acceleration (AccelMode.SSE2)]
246                 public static unsafe Vector16sb CompareEqual (Vector16sb va, Vector16sb vb) {
247                         Vector16sb res = new Vector16sb ();
248                         sbyte *a = &va.v0;
249                         sbyte *b = &vb.v0;
250                         sbyte *c = &res.v0;
251                         for (int i = 0; i < 16; ++i)
252                                 *c++ = (sbyte) (*a++ == *b++ ? -1 : 0);
253                         return res;
254                 }
255
256                 [Acceleration (AccelMode.SSE2)]
257                 public static unsafe Vector16sb CompareGreaterThan (Vector16sb va, Vector16sb vb) {
258                         Vector16sb res = new Vector16sb ();
259                         sbyte *a = &va.v0;
260                         sbyte *b = &vb.v0;
261                         sbyte *c = &res.v0;
262                         for (int i = 0; i < 16; ++i)
263                                 *c++ = (sbyte) (*a++ > *b++ ? -1 : 0);
264                         return res;
265                 }
266
267                 [Acceleration (AccelMode.SSE1)]
268                 public static unsafe explicit operator Vector2d (Vector16sb v)
269                 {
270                         Vector2d* p = (Vector2d*)&v;
271                         return *p;
272                 }
273
274                 [Acceleration (AccelMode.SSE1)]
275                 public static unsafe explicit operator Vector4f (Vector16sb v)
276                 {
277                         Vector4f* p = (Vector4f*)&v;
278                         return *p;
279                 }
280
281                 [Acceleration (AccelMode.SSE1)]
282                 public static unsafe explicit operator Vector2l (Vector16sb v)
283                 {
284                         Vector2l* p = (Vector2l*)&v;
285                         return *p;
286                 }
287
288                 [Acceleration (AccelMode.SSE1)]
289                 public static unsafe explicit operator Vector2ul (Vector16sb v)
290                 {
291                         Vector2ul* p = (Vector2ul*)&v;
292                         return *p;
293                 }
294
295                 [Acceleration (AccelMode.SSE1)]
296                 public static unsafe explicit operator Vector4i (Vector16sb v)
297                 {
298                         Vector4i* p = (Vector4i*)&v;
299                         return *p;
300                 }
301
302                 [Acceleration (AccelMode.SSE1)]
303                 public static unsafe explicit operator Vector4ui (Vector16sb v)
304                 {
305                         Vector4ui* p = (Vector4ui*)&v;
306                         return *p;
307                 }
308
309                 [Acceleration (AccelMode.SSE1)]
310                 public static unsafe explicit operator Vector8s (Vector16sb v)
311                 {
312                         Vector8s* p = (Vector8s*)&v;
313                         return *p;
314                 }
315
316                 [Acceleration (AccelMode.SSE1)]
317                 public static unsafe explicit operator Vector8us (Vector16sb v)
318                 {
319                         Vector8us* p = (Vector8us*)&v;
320                         return *p;
321                 }
322
323                 [Acceleration (AccelMode.SSE1)]
324                 public static unsafe explicit operator Vector16b (Vector16sb v)
325                 {
326                         Vector16b* p = (Vector16b*)&v;
327                         return *p;
328                 }
329
330                 [Acceleration (AccelMode.SSE1)]
331                 public static Vector16sb LoadAligned (ref Vector16sb v)
332                 {
333                         return v;
334                 }
335
336                 [Acceleration (AccelMode.SSE1)]
337                 public static void StoreAligned (ref Vector16sb res, Vector16sb val)
338                 {
339                         res = val;
340                 }
341
342                 [Acceleration (AccelMode.SSE1)]
343                 public static unsafe Vector16sb LoadAligned (Vector16sb *v)
344                 {
345                         return *v;
346                 }
347
348                 [Acceleration (AccelMode.SSE1)]
349                 public static unsafe void StoreAligned (Vector16sb *res, Vector16sb val)
350                 {
351                         *res = val;
352                 }
353
354                 [Acceleration (AccelMode.SSE1)]
355                 [CLSCompliant(false)]
356                 public static void PrefetchTemporalAllCacheLevels (ref Vector16sb res)
357                 {
358                 }
359
360                 [Acceleration (AccelMode.SSE1)]
361                 [CLSCompliant(false)]
362                 public static void PrefetchTemporal1stLevelCache (ref Vector16sb res)
363                 {
364                 }
365
366                 [Acceleration (AccelMode.SSE1)]
367                 [CLSCompliant(false)]
368                 public static void PrefetchTemporal2ndLevelCache (ref Vector16sb res)
369                 {
370                 }
371
372                 [Acceleration (AccelMode.SSE1)]
373                 [CLSCompliant(false)]
374                 public static void PrefetchNonTemporal (ref Vector16sb res)
375                 {
376                 }
377
378                 [Acceleration (AccelMode.SSE1)]
379                 [CLSCompliant(false)]
380                 public static unsafe void PrefetchTemporalAllCacheLevels (Vector16sb *res)
381                 {
382                 }
383
384                 [Acceleration (AccelMode.SSE1)]
385                 [CLSCompliant(false)]
386                 public static unsafe void PrefetchTemporal1stLevelCache (Vector16sb *res)
387                 {
388                 }
389
390                 [Acceleration (AccelMode.SSE1)]
391                 [CLSCompliant(false)]
392                 public static unsafe void PrefetchTemporal2ndLevelCache (Vector16sb *res)
393                 {
394                 }
395
396                 [Acceleration (AccelMode.SSE1)]
397                 [CLSCompliant(false)]
398                 public static unsafe void PrefetchNonTemporal (Vector16sb *res)
399                 {
400                 }
401         }
402 }