be19f3cdc5fbc1fdf9c55b13dc5b1d86b86c7e04
[mono.git] / mcs / class / Mono.Simd / Mono.Simd / Vector4ui.cs
1 // Vector4ui.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;\r
28 using System.Runtime.InteropServices;\r
29 \r
30 namespace Mono.Simd\r
31 {\r
32         [StructLayout(LayoutKind.Sequential, Pack = 0, Size = 16)]
33         [CLSCompliant(false)]\r
34         public struct Vector4ui\r
35         {\r
36                 private uint x;\r
37                 private uint y;\r
38                 private uint z;\r
39                 private uint w;\r
40 \r
41                 public uint X { get { return x; } set { x = value; } }\r
42                 public uint Y { get { return y; } set { y = value; } }\r
43                 public uint Z { get { return z; } set { z = value; } }\r
44                 public uint W { get { return w; } set { w = value; } }\r
45 \r
46                 public Vector4ui (uint x, uint y, uint z, uint w)\r
47                 {\r
48                         this.x = x;\r
49                         this.y = y;\r
50                         this.z = z;\r
51                         this.w = w;\r
52                 }
53
54                 public static Vector4ui operator + (Vector4ui v1, Vector4ui v2)\r
55                 {\r
56                         return new Vector4ui (v1.x + v2.x, v1.y + v2.y, v1.z + v2.z, v1.w + v2.w);\r
57                 }
58
59                 public static Vector4ui operator - (Vector4ui v1, Vector4ui v2)\r
60                 {\r
61                         return new Vector4ui (v1.x - v2.x, v1.y - v2.y, v1.z - v2.z, v1.w - v2.w);\r
62                 }
63
64                 /*
65                  * Requires SSE 4.1
66                  */
67                 public static Vector4ui operator * (Vector4ui v1, Vector4ui v2)\r
68                 {\r
69                         return new Vector4ui (v1.x * v2.x, v1.y * v2.y, v1.z * v2.z, v1.w * v2.w);\r
70                 }
71
72                 public static unsafe Vector4ui operator << (Vector4ui v1, int amount)\r
73                 {\r
74                         return new Vector4ui (v1.x << amount, v1.y << amount, v1.z << amount, v1.w << amount);\r
75                 }
76
77                 public static unsafe Vector4ui operator >> (Vector4ui v1, int amount)\r
78                 {\r
79                         return new Vector4ui (v1.x >> amount, v1.y >> amount, v1.z >> amount, v1.w >> amount);\r
80                 }
81
82 \r
83                 public static Vector4ui operator & (Vector4ui v1, Vector4ui v2)\r
84                 {\r
85                         return new Vector4ui (v1.x & v2.x, v1.y & v2.y, v1.z & v2.z, v1.w & v2.w);\r
86                 }
87
88                 public static Vector4ui operator | (Vector4ui v1, Vector4ui v2)\r
89                 {\r
90                         return new Vector4ui (v1.x | v2.x, v1.y | v2.y, v1.z | v2.z, v1.w | v2.w);\r
91                 }\r
92 \r
93                 public static Vector4ui operator ^ (Vector4ui v1, Vector4ui v2)\r
94                 {\r
95                         return new Vector4ui (v1.x ^ v2.x, v1.y ^ v2.y, v1.z ^ v2.z, v1.w ^ v2.w);\r
96                 }\r
97
98                 public static unsafe Vector4ui UnpackLow (Vector4ui v1, Vector4ui v2)
99                 {
100                         return new Vector4ui (v1.x, v2.x, v1.y, v2.y);
101                 }
102
103                 public static unsafe Vector4ui UnpackHigh (Vector4ui v1, Vector4ui v2)
104                 {
105                         return new Vector4ui (v1.z, v2.z, v1.w, v2.w);
106                 }
107
108                 public static unsafe Vector4ui ShiftRightArithmetic (Vector4ui v1, int amount)\r
109                 {\r
110                         Vector4ui res = new Vector4ui ();
111                         uint *a = &v1.x;
112                         uint *b = &res.x;
113                         for (int i = 0; i < 4; ++i)
114                                 *b++ = (uint)((int)(*a++) >> amount);
115                         return res;\r
116                 }
117
118                 public static unsafe explicit operator Vector4f (Vector4ui v1)\r
119                 {\r
120                         Vector4f* p = (Vector4f*)&v1;\r
121                         return *p;\r
122                 }
123
124                 public static Vector4ui LoadAligned (ref Vector4ui v)\r
125                 {\r
126                         return v;\r
127                 }\r
128 \r
129                 public static void StoreAligned (ref Vector4ui res, Vector4ui val)\r
130                 {\r
131                         res = val;\r
132                 }
133
134         }\r
135 }\r