2008-11-03 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mcs / class / Mono.Simd / Mono.Simd / Vector2l.cs
1 // Vector2l.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         public struct Vector2l
34         {
35                 private long x;
36                 private long y;
37
38                 public long X { get { return x; } set { x = value; } }
39                 public long Y { get { return y; } set { y = value; } }
40
41                 public Vector2l (long x, long y)
42                 {
43                         this.x = x;
44                         this.y = y;
45                 }
46
47                 [Acceleration (AccelMode.SSE2)]
48                 public static Vector2l operator + (Vector2l v1, Vector2l v2)
49                 {
50                         return new Vector2l (v1.x + v2.x, v1.y + v2.y);
51                 }
52
53                 [Acceleration (AccelMode.SSE2)]
54                 public static Vector2l operator - (Vector2l v1, Vector2l v2)
55                 {
56                         return new Vector2l (v1.x - v2.x, v1.y - v2.y);
57                 }
58
59                 [Acceleration (AccelMode.SSE2)]
60                 public static unsafe Vector2l operator << (Vector2l v1, int amount)
61                 {
62                         return new Vector2l (v1.x << amount, v1.y << amount);
63                 }
64
65                 [Acceleration (AccelMode.SSE2)]
66                 public static Vector2l operator & (Vector2l v1, Vector2l v2)
67                 {
68                         return new Vector2l (v1.x & v2.x, v1.y & v2.y);
69                 }
70
71                 [Acceleration (AccelMode.SSE2)]
72                 public static Vector2l operator | (Vector2l v1, Vector2l v2)
73                 {
74                         return new Vector2l (v1.x | v2.x, v1.y | v2.y);
75                 }
76
77                 [Acceleration (AccelMode.SSE2)]
78                 public static Vector2l operator ^ (Vector2l v1, Vector2l v2)
79                 {
80                         return new Vector2l (v1.x ^ v2.x, v1.y ^ v2.y);
81                 }
82
83                 [Acceleration (AccelMode.SSE2)]
84                 public static Vector2l UnpackLow (Vector2l v1, Vector2l v2)
85                 {
86                         return new Vector2l (v1.x, v2.x);
87                 }
88
89                 [Acceleration (AccelMode.SSE2)]
90                 public static Vector2l UnpackHigh (Vector2l v1, Vector2l v2)
91                 {
92                         return new Vector2l (v1.y, v2.y);
93                 }
94
95                 [Acceleration (AccelMode.SSE2)]
96                 public static unsafe Vector2l ShiftRightLogic (Vector2l v1, int amount)
97                 {
98                         return new Vector2l ((long)((ulong)(v1.x) >> amount), (long)((ulong)(v1.y) >> amount));
99                 }
100
101                 [Acceleration (AccelMode.SSE2)]
102                 public static unsafe long ExtractByteMask (Vector2l va) {
103                         int res = 0;
104                         byte *a = (byte*)&va;
105                         for (int i = 0; i < 16; ++i)
106                                 res |= (*a++ & 0x80) >> 7 << i;
107                         return res;
108                 }
109
110                 [Acceleration (AccelMode.SSE41)]
111                 public static Vector2l CompareEqual (Vector2l v1, Vector2l v2)
112                 {
113                         return new Vector2l ((long)(v1.x ==  v2.x ? -1 : 0), (long)(v1.y ==  v2.y ? -1 : 0));
114                 }
115
116                 [Acceleration (AccelMode.SSE41)]
117                 public static Vector2l CompareGreaterThan (Vector2l v1, Vector2l v2)
118                 {
119                         return new Vector2l ((long)(v1.x > v2.x ? -1 : 0), (long)(v1.y >  v2.y ? -1 : 0));
120                 }
121
122                 [Acceleration (AccelMode.SSE1)]
123                 public static unsafe explicit operator Vector2d (Vector2l v)
124                 {
125                         Vector2d* p = (Vector2d*)&v;
126                         return *p;
127                 }
128
129                 [Acceleration (AccelMode.SSE1)]
130                 public static unsafe explicit operator Vector4f (Vector2l v)
131                 {
132                         Vector4f* p = (Vector4f*)&v;
133                         return *p;
134                 }
135
136                 [Acceleration (AccelMode.SSE1)]
137                 [CLSCompliant(false)]
138                 public static unsafe explicit operator Vector2ul (Vector2l v)
139                 {
140                         Vector2ul* p = (Vector2ul*)&v;
141                         return *p;
142                 }
143
144                 [Acceleration (AccelMode.SSE1)]
145                 public static unsafe explicit operator Vector4i (Vector2l v)
146                 {
147                         Vector4i* p = (Vector4i*)&v;
148                         return *p;
149                 }
150
151                 [Acceleration (AccelMode.SSE1)]
152                 [CLSCompliant(false)]
153                 public static unsafe explicit operator Vector4ui (Vector2l v)
154                 {
155                         Vector4ui* p = (Vector4ui*)&v;
156                         return *p;
157                 }
158
159                 [Acceleration (AccelMode.SSE1)]
160                 public static unsafe explicit operator Vector8s (Vector2l v)
161                 {
162                         Vector8s* p = (Vector8s*)&v;
163                         return *p;
164                 }
165
166                 [Acceleration (AccelMode.SSE1)]
167                 [CLSCompliant(false)]
168                 public static unsafe explicit operator Vector8us (Vector2l v)
169                 {
170                         Vector8us* p = (Vector8us*)&v;
171                         return *p;
172                 }
173
174                 [Acceleration (AccelMode.SSE1)]
175                 [CLSCompliant(false)]
176                 public static unsafe explicit operator Vector16sb (Vector2l v)
177                 {
178                         Vector16sb* p = (Vector16sb*)&v;
179                         return *p;
180                 }
181
182                 [Acceleration (AccelMode.SSE1)]
183                 public static unsafe explicit operator Vector16b (Vector2l v)
184                 {
185                         Vector16b* p = (Vector16b*)&v;
186                         return *p;
187                 }
188
189                 [Acceleration (AccelMode.SSE1)]
190                 public static Vector2l LoadAligned (ref Vector2l v)
191                 {
192                         return v;
193                 }
194
195                 [Acceleration (AccelMode.SSE1)]
196                 public static void StoreAligned (ref Vector2l res, Vector2l val)
197                 {
198                         res = val;
199                 }
200
201                 [CLSCompliant(false)]
202                 [Acceleration (AccelMode.SSE1)]
203                 public static unsafe Vector2l LoadAligned (Vector2l *v)
204                 {
205                         return *v;
206                 }
207
208                 [CLSCompliant(false)]
209                 [Acceleration (AccelMode.SSE1)]
210                 public static unsafe void StoreAligned (Vector2l *res, Vector2l val)
211                 {
212                         *res = val;
213                 }
214
215                 [Acceleration (AccelMode.SSE1)]
216                 [CLSCompliant(false)]
217                 public static void Prefetch0 (ref Vector2l res)
218                 {
219                 }
220
221                 [Acceleration (AccelMode.SSE1)]
222                 [CLSCompliant(false)]
223                 public static void Prefetch1 (ref Vector2l res)
224                 {
225                 }
226
227                 [Acceleration (AccelMode.SSE1)]
228                 [CLSCompliant(false)]
229                 public static void Prefetch2 (ref Vector2l res)
230                 {
231                 }
232
233                 [Acceleration (AccelMode.SSE1)]
234                 [CLSCompliant(false)]
235                 public static void PrefetchNTA (ref Vector2l res)
236                 {
237                 }
238
239                 [Acceleration (AccelMode.SSE1)]
240                 [CLSCompliant(false)]
241                 public static unsafe void Prefetch0 (Vector2l *res)
242                 {
243                 }
244
245                 [Acceleration (AccelMode.SSE1)]
246                 [CLSCompliant(false)]
247                 public static unsafe void Prefetch1 (Vector2l *res)
248                 {
249                 }
250
251                 [Acceleration (AccelMode.SSE1)]
252                 [CLSCompliant(false)]
253                 public static unsafe void Prefetch2 (Vector2l *res)
254                 {
255                 }
256
257                 [Acceleration (AccelMode.SSE1)]
258                 [CLSCompliant(false)]
259                 public static unsafe void PrefetchNTA (Vector2l *res)
260                 {
261                 }
262         }
263 }