Native EOL
[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                 [Acceleration (AccelMode.SSE2)]
74                 public static unsafe Vector16sb operator + (Vector16sb va, Vector16sb vb)
75                 {
76                         Vector16sb res = new Vector16sb ();
77                         sbyte *a = &va.v0;
78                         sbyte *b = &vb.v0;
79                         sbyte *c = &res.v0;
80                         for (int i = 0; i < 16; ++i)
81                                 *c++ = (sbyte)(*a++ + *b++);
82                         return res;
83                 }
84
85                 [Acceleration (AccelMode.SSE2)]
86                 public static unsafe Vector16sb operator - (Vector16sb va, Vector16sb vb)
87                 {
88                         Vector16sb res = new Vector16sb ();
89                         sbyte *a = &va.v0;
90                         sbyte *b = &vb.v0;
91                         sbyte *c = &res.v0;
92                         for (int i = 0; i < 16; ++i)
93                                 *c++ = (sbyte)(*a++ - *b++);
94                         return res;
95                 }
96
97                 [Acceleration (AccelMode.SSE2)]
98                 public static unsafe Vector16sb operator & (Vector16sb va, Vector16sb vb)
99                 {
100                         Vector16sb res = new Vector16sb ();
101                         sbyte *a = &va.v0;
102                         sbyte *b = &vb.v0;
103                         sbyte *c = &res.v0;
104                         for (int i = 0; i < 16; ++i)
105                                 *c++ = (sbyte)(*a++ & *b++);
106                         return res;
107                 }
108
109                 [Acceleration (AccelMode.SSE2)]
110                 public static unsafe Vector16sb operator | (Vector16sb va, Vector16sb vb)
111                 {
112                         Vector16sb res = new Vector16sb ();
113                         sbyte *a = &va.v0;
114                         sbyte *b = &vb.v0;
115                         sbyte *c = &res.v0;
116                         for (int i = 0; i < 16; ++i)
117                                 *c++ = (sbyte)((uint)*a++ | (uint)*b++);
118                         return res;
119                 }
120
121                 [Acceleration (AccelMode.SSE2)]
122                 public static unsafe Vector16sb operator ^ (Vector16sb va, Vector16sb vb)
123                 {
124                         Vector16sb res = new Vector16sb ();
125                         sbyte *a = &va.v0;
126                         sbyte *b = &vb.v0;
127                         sbyte *c = &res.v0;
128                         for (int i = 0; i < 16; ++i)
129                                 *c++ = (sbyte)(*a++ ^ *b++);
130                         return res;
131                 }
132
133                 [Acceleration (AccelMode.SSE2)]
134                 public static unsafe Vector16sb UnpackLow (Vector16sb va, Vector16sb vb)
135                 {
136                         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);
137                 }
138
139                 [Acceleration (AccelMode.SSE2)]
140                 public static unsafe Vector16sb UnpackHigh (Vector16sb va, Vector16sb vb)
141                 {
142                         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);
143                 }
144
145                 [Acceleration (AccelMode.SSE2)]
146                 public static unsafe Vector16sb AddWithSaturation (Vector16sb va, Vector16sb vb) {
147                         Vector16sb res = new Vector16sb ();
148                         sbyte *a = &va.v0;
149                         sbyte *b = &vb.v0;
150                         sbyte *c = &res.v0;
151                         for (int i = 0; i < 16; ++i)
152                                 *c++ = (sbyte) System.Math.Max (System.Math.Min (*a++ + *b++, sbyte.MaxValue), sbyte.MinValue);
153                         return res;
154                 }
155
156                 [Acceleration (AccelMode.SSE2)]
157                 public static unsafe Vector16sb SubWithSaturation (Vector16sb va, Vector16sb vb) {
158                         Vector16sb res = new Vector16sb ();
159                         sbyte *a = &va.v0;
160                         sbyte *b = &vb.v0;
161                         sbyte *c = &res.v0;
162                         for (int i = 0; i < 16; ++i)
163                                 *c++ = (sbyte) System.Math.Max (System.Math.Min (*a++ - *b++, sbyte.MaxValue), sbyte.MinValue);
164                         return res;
165                 }
166
167                 [Acceleration (AccelMode.SSE41)]
168                 public static unsafe Vector16sb Max (Vector16sb va, Vector16sb vb) {
169                         Vector16sb res = new Vector16sb ();
170                         sbyte *a = &va.v0;
171                         sbyte *b = &vb.v0;
172                         sbyte *c = &res.v0;
173                         for (int i = 0; i < 16; ++i)
174                                 *c++ = (sbyte) System.Math.Max (*a++, *b++);
175                         return res;
176                 }
177
178                 [Acceleration (AccelMode.SSE41)]
179                 public static unsafe Vector16sb Min (Vector16sb va, Vector16sb vb) {
180                         Vector16sb res = new Vector16sb ();
181                         sbyte *a = &va.v0;
182                         sbyte *b = &vb.v0;
183                         sbyte *c = &res.v0;
184                         for (int i = 0; i < 16; ++i)
185                                 *c++ = (sbyte) System.Math.Min(*a++, *b++);
186                         return res;
187                 }
188
189                 [Acceleration (AccelMode.SSE2)]
190                 public static unsafe int ExtractByteMask (Vector16sb va) {
191                         int res = 0;
192                         sbyte *a = (sbyte*)&va;
193                         for (int i = 0; i < 16; ++i)
194                                 res |= (*a++ & 0x80) >> 7 << i;
195                         return res;
196                 }
197
198                 [Acceleration (AccelMode.SSE2)]
199                 public static unsafe Vector16sb CompareEqual (Vector16sb va, Vector16sb vb) {
200                         Vector16sb res = new Vector16sb ();
201                         sbyte *a = &va.v0;
202                         sbyte *b = &vb.v0;
203                         sbyte *c = &res.v0;
204                         for (int i = 0; i < 16; ++i)
205                                 *c++ = (sbyte) (*a++ == *b++ ? -1 : 0);
206                         return res;
207                 }
208
209                 [Acceleration (AccelMode.SSE2)]
210                 public static unsafe Vector16sb CompareGreaterThan (Vector16sb va, Vector16sb vb) {
211                         Vector16sb res = new Vector16sb ();
212                         sbyte *a = &va.v0;
213                         sbyte *b = &vb.v0;
214                         sbyte *c = &res.v0;
215                         for (int i = 0; i < 16; ++i)
216                                 *c++ = (sbyte) (*a++ > *b++ ? -1 : 0);
217                         return res;
218                 }
219
220                 [Acceleration (AccelMode.SSE1)]
221                 public static unsafe explicit operator Vector2d (Vector16sb v)
222                 {
223                         Vector2d* p = (Vector2d*)&v;
224                         return *p;
225                 }
226
227                 [Acceleration (AccelMode.SSE1)]
228                 public static unsafe explicit operator Vector4f (Vector16sb v)
229                 {
230                         Vector4f* p = (Vector4f*)&v;
231                         return *p;
232                 }
233
234                 [Acceleration (AccelMode.SSE1)]
235                 public static unsafe explicit operator Vector2l (Vector16sb v)
236                 {
237                         Vector2l* p = (Vector2l*)&v;
238                         return *p;
239                 }
240
241                 [Acceleration (AccelMode.SSE1)]
242                 public static unsafe explicit operator Vector2ul (Vector16sb v)
243                 {
244                         Vector2ul* p = (Vector2ul*)&v;
245                         return *p;
246                 }
247
248                 [Acceleration (AccelMode.SSE1)]
249                 public static unsafe explicit operator Vector4i (Vector16sb v)
250                 {
251                         Vector4i* p = (Vector4i*)&v;
252                         return *p;
253                 }
254
255                 [Acceleration (AccelMode.SSE1)]
256                 public static unsafe explicit operator Vector4ui (Vector16sb v)
257                 {
258                         Vector4ui* p = (Vector4ui*)&v;
259                         return *p;
260                 }
261
262                 [Acceleration (AccelMode.SSE1)]
263                 public static unsafe explicit operator Vector8s (Vector16sb v)
264                 {
265                         Vector8s* p = (Vector8s*)&v;
266                         return *p;
267                 }
268
269                 [Acceleration (AccelMode.SSE1)]
270                 public static unsafe explicit operator Vector8us (Vector16sb v)
271                 {
272                         Vector8us* p = (Vector8us*)&v;
273                         return *p;
274                 }
275
276                 [Acceleration (AccelMode.SSE1)]
277                 public static unsafe explicit operator Vector16b (Vector16sb v)
278                 {
279                         Vector16b* p = (Vector16b*)&v;
280                         return *p;
281                 }
282
283                 [Acceleration (AccelMode.SSE1)]
284                 public static Vector16sb LoadAligned (ref Vector16sb v)
285                 {
286                         return v;
287                 }
288
289                 [Acceleration (AccelMode.SSE1)]
290                 public static void StoreAligned (ref Vector16sb res, Vector16sb val)
291                 {
292                         res = val;
293                 }
294
295                 [Acceleration (AccelMode.SSE1)]
296                 public static unsafe Vector16sb LoadAligned (Vector16sb *v)
297                 {
298                         return *v;
299                 }
300
301                 [Acceleration (AccelMode.SSE1)]
302                 public static unsafe void StoreAligned (Vector16sb *res, Vector16sb val)
303                 {
304                         *res = val;
305                 }
306         }
307 }