4 // Rodrigo Kumpera (rkumpera@novell.com)
6 // (C) 2008 Novell, Inc. (http://www.novell.com)
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:
16 // The above copyright notice and this permission notice shall be
17 // included in all copies or substantial portions of the Software.
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.
28 using System.Runtime.InteropServices;
32 [StructLayout(LayoutKind.Sequential, Pack = 0, Size = 16)]
34 public struct Vector16sb
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)
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; } }
73 [Acceleration (AccelMode.SSE2)]
74 public static unsafe Vector16sb operator + (Vector16sb va, Vector16sb vb)
76 Vector16sb res = new Vector16sb ();
80 for (int i = 0; i < 16; ++i)
81 *c++ = (sbyte)(*a++ + *b++);
85 [Acceleration (AccelMode.SSE2)]
86 public static unsafe Vector16sb operator - (Vector16sb va, Vector16sb vb)
88 Vector16sb res = new Vector16sb ();
92 for (int i = 0; i < 16; ++i)
93 *c++ = (sbyte)(*a++ - *b++);
97 [Acceleration (AccelMode.SSE2)]
98 public static unsafe Vector16sb operator & (Vector16sb va, Vector16sb vb)
100 Vector16sb res = new Vector16sb ();
104 for (int i = 0; i < 16; ++i)
105 *c++ = (sbyte)(*a++ & *b++);
109 [Acceleration (AccelMode.SSE2)]
110 public static unsafe Vector16sb operator | (Vector16sb va, Vector16sb vb)
112 Vector16sb res = new Vector16sb ();
116 for (int i = 0; i < 16; ++i)
117 *c++ = (sbyte)((uint)*a++ | (uint)*b++);
121 [Acceleration (AccelMode.SSE2)]
122 public static unsafe Vector16sb operator ^ (Vector16sb va, Vector16sb vb)
124 Vector16sb res = new Vector16sb ();
128 for (int i = 0; i < 16; ++i)
129 *c++ = (sbyte)(*a++ ^ *b++);
133 [Acceleration (AccelMode.SSE2)]
134 public static unsafe Vector16sb UnpackLow (Vector16sb va, Vector16sb vb)
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);
139 [Acceleration (AccelMode.SSE2)]
140 public static unsafe Vector16sb UnpackHigh (Vector16sb va, Vector16sb vb)
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);
145 [Acceleration (AccelMode.SSE2)]
146 public static unsafe Vector16sb AddWithSaturation (Vector16sb va, Vector16sb vb) {
147 Vector16sb res = new Vector16sb ();
151 for (int i = 0; i < 16; ++i)
152 *c++ = (sbyte) System.Math.Max (System.Math.Min (*a++ + *b++, sbyte.MaxValue), sbyte.MinValue);
156 [Acceleration (AccelMode.SSE2)]
157 public static unsafe Vector16sb SubWithSaturation (Vector16sb va, Vector16sb vb) {
158 Vector16sb res = new Vector16sb ();
162 for (int i = 0; i < 16; ++i)
163 *c++ = (sbyte) System.Math.Max (System.Math.Min (*a++ - *b++, sbyte.MaxValue), sbyte.MinValue);
167 [Acceleration (AccelMode.SSE41)]
168 public static unsafe Vector16sb Max (Vector16sb va, Vector16sb vb) {
169 Vector16sb res = new Vector16sb ();
173 for (int i = 0; i < 16; ++i)
174 *c++ = (sbyte) System.Math.Max (*a++, *b++);
178 [Acceleration (AccelMode.SSE41)]
179 public static unsafe Vector16sb Min (Vector16sb va, Vector16sb vb) {
180 Vector16sb res = new Vector16sb ();
184 for (int i = 0; i < 16; ++i)
185 *c++ = (sbyte) System.Math.Min(*a++, *b++);
189 [Acceleration (AccelMode.SSE2)]
190 public static unsafe int ExtractByteMask (Vector16sb va) {
192 sbyte *a = (sbyte*)&va;
193 for (int i = 0; i < 16; ++i)
194 res |= (*a++ & 0x80) >> 7 << i;
198 [Acceleration (AccelMode.SSE2)]
199 public static unsafe Vector16sb CompareEqual (Vector16sb va, Vector16sb vb) {
200 Vector16sb res = new Vector16sb ();
204 for (int i = 0; i < 16; ++i)
205 *c++ = (sbyte) (*a++ == *b++ ? -1 : 0);
209 [Acceleration (AccelMode.SSE2)]
210 public static unsafe Vector16sb CompareGreaterThan (Vector16sb va, Vector16sb vb) {
211 Vector16sb res = new Vector16sb ();
215 for (int i = 0; i < 16; ++i)
216 *c++ = (sbyte) (*a++ > *b++ ? -1 : 0);
220 [Acceleration (AccelMode.SSE1)]
221 public static unsafe explicit operator Vector2d (Vector16sb v)
223 Vector2d* p = (Vector2d*)&v;
227 [Acceleration (AccelMode.SSE1)]
228 public static unsafe explicit operator Vector4f (Vector16sb v)
230 Vector4f* p = (Vector4f*)&v;
234 [Acceleration (AccelMode.SSE1)]
235 public static unsafe explicit operator Vector2l (Vector16sb v)
237 Vector2l* p = (Vector2l*)&v;
241 [Acceleration (AccelMode.SSE1)]
242 public static unsafe explicit operator Vector2ul (Vector16sb v)
244 Vector2ul* p = (Vector2ul*)&v;
248 [Acceleration (AccelMode.SSE1)]
249 public static unsafe explicit operator Vector4i (Vector16sb v)
251 Vector4i* p = (Vector4i*)&v;
255 [Acceleration (AccelMode.SSE1)]
256 public static unsafe explicit operator Vector4ui (Vector16sb v)
258 Vector4ui* p = (Vector4ui*)&v;
262 [Acceleration (AccelMode.SSE1)]
263 public static unsafe explicit operator Vector8s (Vector16sb v)
265 Vector8s* p = (Vector8s*)&v;
269 [Acceleration (AccelMode.SSE1)]
270 public static unsafe explicit operator Vector8us (Vector16sb v)
272 Vector8us* p = (Vector8us*)&v;
276 [Acceleration (AccelMode.SSE1)]
277 public static unsafe explicit operator Vector16b (Vector16sb v)
279 Vector16b* p = (Vector16b*)&v;
283 [Acceleration (AccelMode.SSE1)]
284 public static Vector16sb LoadAligned (ref Vector16sb v)
289 [Acceleration (AccelMode.SSE1)]
290 public static void StoreAligned (ref Vector16sb res, Vector16sb val)
295 [Acceleration (AccelMode.SSE1)]
296 public static unsafe Vector16sb LoadAligned (Vector16sb *v)
301 [Acceleration (AccelMode.SSE1)]
302 public static unsafe void StoreAligned (Vector16sb *res, Vector16sb val)