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)]
33 public struct Vector2l
38 public long X { get { return x; } set { x = value; } }
39 public long Y { get { return y; } set { y = value; } }
41 public Vector2l (long x, long y)
47 [Acceleration (AccelMode.SSE2)]
48 public static Vector2l operator + (Vector2l v1, Vector2l v2)
50 return new Vector2l (v1.x + v2.x, v1.y + v2.y);
53 [Acceleration (AccelMode.SSE2)]
54 public static Vector2l operator - (Vector2l v1, Vector2l v2)
56 return new Vector2l (v1.x - v2.x, v1.y - v2.y);
59 [Acceleration (AccelMode.SSE2)]
60 public static unsafe Vector2l operator << (Vector2l v1, int amount)
62 return new Vector2l (v1.x << amount, v1.y << amount);
65 [Acceleration (AccelMode.SSE2)]
66 public static Vector2l operator & (Vector2l v1, Vector2l v2)
68 return new Vector2l (v1.x & v2.x, v1.y & v2.y);
71 [Acceleration (AccelMode.SSE2)]
72 public static Vector2l operator | (Vector2l v1, Vector2l v2)
74 return new Vector2l (v1.x | v2.x, v1.y | v2.y);
77 [Acceleration (AccelMode.SSE2)]
78 public static Vector2l operator ^ (Vector2l v1, Vector2l v2)
80 return new Vector2l (v1.x ^ v2.x, v1.y ^ v2.y);
83 [Acceleration (AccelMode.SSE2)]
84 public static Vector2l UnpackLow (Vector2l v1, Vector2l v2)
86 return new Vector2l (v1.x, v2.x);
89 [Acceleration (AccelMode.SSE2)]
90 public static Vector2l UnpackHigh (Vector2l v1, Vector2l v2)
92 return new Vector2l (v1.y, v2.y);
95 [Acceleration (AccelMode.SSE2)]
96 public static unsafe Vector2l ShiftRightLogic (Vector2l v1, int amount)
98 return new Vector2l ((long)((ulong)(v1.x) >> amount), (long)((ulong)(v1.y) >> amount));
101 [Acceleration (AccelMode.SSE2)]
102 public static unsafe long ExtractByteMask (Vector2l va) {
104 byte *a = (byte*)&va;
105 for (int i = 0; i < 16; ++i)
106 res |= (*a++ & 0x80) >> 7 << i;
110 [Acceleration (AccelMode.SSE41)]
111 public static Vector2l CompareEqual (Vector2l v1, Vector2l v2)
113 return new Vector2l ((long)(v1.x == v2.x ? -1 : 0), (long)(v1.y == v2.y ? -1 : 0));
116 [Acceleration (AccelMode.SSE41)]
117 public static Vector2l CompareGreaterThan (Vector2l v1, Vector2l v2)
119 return new Vector2l ((long)(v1.x > v2.x ? -1 : 0), (long)(v1.y > v2.y ? -1 : 0));
122 [Acceleration (AccelMode.SSE1)]
123 public static unsafe explicit operator Vector2d (Vector2l v)
125 Vector2d* p = (Vector2d*)&v;
129 [Acceleration (AccelMode.SSE1)]
130 public static unsafe explicit operator Vector4f (Vector2l v)
132 Vector4f* p = (Vector4f*)&v;
136 [Acceleration (AccelMode.SSE1)]
137 [CLSCompliant(false)]
138 public static unsafe explicit operator Vector2ul (Vector2l v)
140 Vector2ul* p = (Vector2ul*)&v;
144 [Acceleration (AccelMode.SSE1)]
145 public static unsafe explicit operator Vector4i (Vector2l v)
147 Vector4i* p = (Vector4i*)&v;
151 [Acceleration (AccelMode.SSE1)]
152 [CLSCompliant(false)]
153 public static unsafe explicit operator Vector4ui (Vector2l v)
155 Vector4ui* p = (Vector4ui*)&v;
159 [Acceleration (AccelMode.SSE1)]
160 public static unsafe explicit operator Vector8s (Vector2l v)
162 Vector8s* p = (Vector8s*)&v;
166 [Acceleration (AccelMode.SSE1)]
167 [CLSCompliant(false)]
168 public static unsafe explicit operator Vector8us (Vector2l v)
170 Vector8us* p = (Vector8us*)&v;
174 [Acceleration (AccelMode.SSE1)]
175 [CLSCompliant(false)]
176 public static unsafe explicit operator Vector16sb (Vector2l v)
178 Vector16sb* p = (Vector16sb*)&v;
182 [Acceleration (AccelMode.SSE1)]
183 public static unsafe explicit operator Vector16b (Vector2l v)
185 Vector16b* p = (Vector16b*)&v;
189 [Acceleration (AccelMode.SSE1)]
190 public static Vector2l LoadAligned (ref Vector2l v)
195 [Acceleration (AccelMode.SSE1)]
196 public static void StoreAligned (ref Vector2l res, Vector2l val)
201 [CLSCompliant(false)]
202 [Acceleration (AccelMode.SSE1)]
203 public static unsafe Vector2l LoadAligned (Vector2l *v)
208 [CLSCompliant(false)]
209 [Acceleration (AccelMode.SSE1)]
210 public static unsafe void StoreAligned (Vector2l *res, Vector2l val)
215 [Acceleration (AccelMode.SSE1)]
216 [CLSCompliant(false)]
217 public static void Prefetch0 (ref Vector2l res)
221 [Acceleration (AccelMode.SSE1)]
222 [CLSCompliant(false)]
223 public static void Prefetch1 (ref Vector2l res)
227 [Acceleration (AccelMode.SSE1)]
228 [CLSCompliant(false)]
229 public static void Prefetch2 (ref Vector2l res)
233 [Acceleration (AccelMode.SSE1)]
234 [CLSCompliant(false)]
235 public static void PrefetchNTA (ref Vector2l res)
239 [Acceleration (AccelMode.SSE1)]
240 [CLSCompliant(false)]
241 public static unsafe void Prefetch0 (Vector2l *res)
245 [Acceleration (AccelMode.SSE1)]
246 [CLSCompliant(false)]
247 public static unsafe void Prefetch1 (Vector2l *res)
251 [Acceleration (AccelMode.SSE1)]
252 [CLSCompliant(false)]
253 public static unsafe void Prefetch2 (Vector2l *res)
257 [Acceleration (AccelMode.SSE1)]
258 [CLSCompliant(false)]
259 public static unsafe void PrefetchNTA (Vector2l *res)