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