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