2008-11-12 Cedric Vivier <cedricv@neonux.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                         ulong *a = (ulong*) &va.v0;
121                         ulong *b = (ulong*) &vb.v0;
122                         ulong *c = (ulong*) &res.v0;
123                         *c++ = (ulong)(*a++ & *b++);
124                         *c = (ulong)(*a & *b);
125                         return res;
126                 }
127
128                 [Acceleration (AccelMode.SSE2)]
129                 public static unsafe Vector16sb operator | (Vector16sb va, Vector16sb vb)
130                 {
131                         Vector16sb res = new Vector16sb ();
132                         ulong *a = (ulong*) &va.v0;
133                         ulong *b = (ulong*) &vb.v0;
134                         ulong *c = (ulong*) &res.v0;
135                         *c++ = (ulong)(*a++ | *b++);
136                         *c = (ulong)(*a | *b);
137                         return res;
138                 }
139
140                 [Acceleration (AccelMode.SSE2)]
141                 public static unsafe Vector16sb operator ^ (Vector16sb va, Vector16sb vb)
142                 {
143                         Vector16sb res = new Vector16sb ();
144                         ulong *a = (ulong*) &va.v0;
145                         ulong *b = (ulong*) &vb.v0;
146                         ulong *c = (ulong*) &res.v0;
147                         *c++ = (ulong)(*a++ ^ *b++);
148                         *c = (ulong)(*a ^ *b);
149                         return res;
150                 }
151
152                 [Acceleration (AccelMode.SSE2)]
153                 public static unsafe Vector16sb UnpackLow (Vector16sb va, Vector16sb vb)
154                 {
155                         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);
156                 }
157
158                 [Acceleration (AccelMode.SSE2)]
159                 public static unsafe Vector16sb UnpackHigh (Vector16sb va, Vector16sb vb)
160                 {
161                         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);
162                 }
163
164                 [Acceleration (AccelMode.SSE2)]
165                 public static unsafe Vector16sb AddWithSaturation (Vector16sb va, Vector16sb vb) {
166                         Vector16sb res = new Vector16sb ();
167                         sbyte *a = &va.v0;
168                         sbyte *b = &vb.v0;
169                         sbyte *c = &res.v0;
170                         for (int i = 0; i < 16; ++i)
171                                 *c++ = (sbyte) System.Math.Max (System.Math.Min (*a++ + *b++, sbyte.MaxValue), sbyte.MinValue);
172                         return res;
173                 }
174
175                 [Acceleration (AccelMode.SSE2)]
176                 public static unsafe Vector16sb SubWithSaturation (Vector16sb va, Vector16sb vb) {
177                         Vector16sb res = new Vector16sb ();
178                         sbyte *a = &va.v0;
179                         sbyte *b = &vb.v0;
180                         sbyte *c = &res.v0;
181                         for (int i = 0; i < 16; ++i)
182                                 *c++ = (sbyte) System.Math.Max (System.Math.Min (*a++ - *b++, sbyte.MaxValue), sbyte.MinValue);
183                         return res;
184                 }
185
186                 [Acceleration (AccelMode.SSE41)]
187                 public static unsafe Vector16sb Max (Vector16sb va, Vector16sb vb) {
188                         Vector16sb res = new Vector16sb ();
189                         sbyte *a = &va.v0;
190                         sbyte *b = &vb.v0;
191                         sbyte *c = &res.v0;
192                         for (int i = 0; i < 16; ++i)
193                                 *c++ = (sbyte) System.Math.Max (*a++, *b++);
194                         return res;
195                 }
196
197                 [Acceleration (AccelMode.SSE41)]
198                 public static unsafe Vector16sb Min (Vector16sb va, Vector16sb vb) {
199                         Vector16sb res = new Vector16sb ();
200                         sbyte *a = &va.v0;
201                         sbyte *b = &vb.v0;
202                         sbyte *c = &res.v0;
203                         for (int i = 0; i < 16; ++i)
204                                 *c++ = (sbyte) System.Math.Min(*a++, *b++);
205                         return res;
206                 }
207
208                 [Acceleration (AccelMode.SSE2)]
209                 public static unsafe int ExtractByteMask (Vector16sb va) {
210                         int res = 0;
211                         sbyte *a = (sbyte*)&va;
212                         for (int i = 0; i < 16; ++i)
213                                 res |= (*a++ & 0x80) >> 7 << i;
214                         return res;
215                 }
216
217                 [Acceleration (AccelMode.SSE2)]
218                 public static unsafe Vector16sb CompareEqual (Vector16sb va, Vector16sb vb) {
219                         Vector16sb res = new Vector16sb ();
220                         sbyte *a = &va.v0;
221                         sbyte *b = &vb.v0;
222                         sbyte *c = &res.v0;
223                         for (int i = 0; i < 16; ++i)
224                                 *c++ = (sbyte) (*a++ == *b++ ? -1 : 0);
225                         return res;
226                 }
227
228                 [Acceleration (AccelMode.SSE2)]
229                 public static unsafe Vector16sb CompareGreaterThan (Vector16sb va, Vector16sb vb) {
230                         Vector16sb res = new Vector16sb ();
231                         sbyte *a = &va.v0;
232                         sbyte *b = &vb.v0;
233                         sbyte *c = &res.v0;
234                         for (int i = 0; i < 16; ++i)
235                                 *c++ = (sbyte) (*a++ > *b++ ? -1 : 0);
236                         return res;
237                 }
238
239                 [Acceleration (AccelMode.SSE1)]
240                 public static unsafe explicit operator Vector2d (Vector16sb v)
241                 {
242                         Vector2d* p = (Vector2d*)&v;
243                         return *p;
244                 }
245
246                 [Acceleration (AccelMode.SSE1)]
247                 public static unsafe explicit operator Vector4f (Vector16sb v)
248                 {
249                         Vector4f* p = (Vector4f*)&v;
250                         return *p;
251                 }
252
253                 [Acceleration (AccelMode.SSE1)]
254                 public static unsafe explicit operator Vector2l (Vector16sb v)
255                 {
256                         Vector2l* p = (Vector2l*)&v;
257                         return *p;
258                 }
259
260                 [Acceleration (AccelMode.SSE1)]
261                 public static unsafe explicit operator Vector2ul (Vector16sb v)
262                 {
263                         Vector2ul* p = (Vector2ul*)&v;
264                         return *p;
265                 }
266
267                 [Acceleration (AccelMode.SSE1)]
268                 public static unsafe explicit operator Vector4i (Vector16sb v)
269                 {
270                         Vector4i* p = (Vector4i*)&v;
271                         return *p;
272                 }
273
274                 [Acceleration (AccelMode.SSE1)]
275                 public static unsafe explicit operator Vector4ui (Vector16sb v)
276                 {
277                         Vector4ui* p = (Vector4ui*)&v;
278                         return *p;
279                 }
280
281                 [Acceleration (AccelMode.SSE1)]
282                 public static unsafe explicit operator Vector8s (Vector16sb v)
283                 {
284                         Vector8s* p = (Vector8s*)&v;
285                         return *p;
286                 }
287
288                 [Acceleration (AccelMode.SSE1)]
289                 public static unsafe explicit operator Vector8us (Vector16sb v)
290                 {
291                         Vector8us* p = (Vector8us*)&v;
292                         return *p;
293                 }
294
295                 [Acceleration (AccelMode.SSE1)]
296                 public static unsafe explicit operator Vector16b (Vector16sb v)
297                 {
298                         Vector16b* p = (Vector16b*)&v;
299                         return *p;
300                 }
301
302                 [Acceleration (AccelMode.SSE1)]
303                 public static Vector16sb LoadAligned (ref Vector16sb v)
304                 {
305                         return v;
306                 }
307
308                 [Acceleration (AccelMode.SSE1)]
309                 public static void StoreAligned (ref Vector16sb res, Vector16sb val)
310                 {
311                         res = val;
312                 }
313
314                 [Acceleration (AccelMode.SSE1)]
315                 public static unsafe Vector16sb LoadAligned (Vector16sb *v)
316                 {
317                         return *v;
318                 }
319
320                 [Acceleration (AccelMode.SSE1)]
321                 public static unsafe void StoreAligned (Vector16sb *res, Vector16sb val)
322                 {
323                         *res = val;
324                 }
325
326                 [Acceleration (AccelMode.SSE1)]
327                 [CLSCompliant(false)]
328                 public static void PrefetchTemporalAllCacheLevels (ref Vector16sb res)
329                 {
330                 }
331
332                 [Acceleration (AccelMode.SSE1)]
333                 [CLSCompliant(false)]
334                 public static void PrefetchTemporal1stLevelCache (ref Vector16sb res)
335                 {
336                 }
337
338                 [Acceleration (AccelMode.SSE1)]
339                 [CLSCompliant(false)]
340                 public static void PrefetchTemporal2ndLevelCache (ref Vector16sb res)
341                 {
342                 }
343
344                 [Acceleration (AccelMode.SSE1)]
345                 [CLSCompliant(false)]
346                 public static void PrefetchNonTemporal (ref Vector16sb res)
347                 {
348                 }
349
350                 [Acceleration (AccelMode.SSE1)]
351                 [CLSCompliant(false)]
352                 public static unsafe void PrefetchTemporalAllCacheLevels (Vector16sb *res)
353                 {
354                 }
355
356                 [Acceleration (AccelMode.SSE1)]
357                 [CLSCompliant(false)]
358                 public static unsafe void PrefetchTemporal1stLevelCache (Vector16sb *res)
359                 {
360                 }
361
362                 [Acceleration (AccelMode.SSE1)]
363                 [CLSCompliant(false)]
364                 public static unsafe void PrefetchTemporal2ndLevelCache (Vector16sb *res)
365                 {
366                 }
367
368                 [Acceleration (AccelMode.SSE1)]
369                 [CLSCompliant(false)]
370                 public static unsafe void PrefetchNonTemporal (Vector16sb *res)
371                 {
372                 }
373         }
374 }