Fix XMM scanning on Mac x86.
[mono.git] / mcs / class / dlr / Runtime / Microsoft.Dynamic / Interpreter / Instructions / ShrInstruction.cs
1 // 
2 // ShrInstruction.cs:
3 //
4 // Authors: Marek Safar (marek.safar@gmail.com)
5 //     
6 // Copyright 2014 Xamarin Inc
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 //
28
29 using System;
30 using System.Diagnostics;
31 using Microsoft.Scripting.Runtime;
32 using Microsoft.Scripting.Utils;
33
34 namespace Microsoft.Scripting.Interpreter {
35     internal abstract class ShrInstruction : ArithmeticInstruction {
36         private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64;
37         private static Instruction _Int16Lifted, _Int32Lifted, _Int64Lifted, _UInt16Lifted, _UInt32Lifted, _UInt64Lifted;
38
39         private ShrInstruction() {
40         }
41
42         internal sealed class ShrInt32 : ShrInstruction {
43             protected override object Calculate (object l, object r)
44             {
45                 return ScriptingRuntimeHelpers.Int32ToObject((Int32)l >> (Int32)r);
46             }
47         }
48
49         internal sealed class ShrInt16 : ShrInstruction {
50             protected override object Calculate (object l, object r)
51             {
52                 return (Int32)((Int16)l >> (Int32)r);
53             }
54         }
55
56         internal sealed class ShrInt64 : ShrInstruction {
57             protected override object Calculate (object l, object r)
58             {
59                 return (Int64)((Int64)l >> (Int32)r);
60             }
61         }
62
63         internal sealed class ShrUInt16 : ShrInstruction {
64             protected override object Calculate (object l, object r)
65             {
66                 return (Int32)((UInt16)l >> (Int32)r);
67             }
68         }
69
70         internal sealed class ShrUInt32 : ShrInstruction {
71             protected override object Calculate (object l, object r)
72             {
73                 return (UInt32)((UInt32)l >> (Int32)r);
74             }
75         }
76
77         internal sealed class ShrUInt64 : ShrInstruction {
78             protected override object Calculate (object l, object r)
79             {
80                 return (UInt64)((UInt64)l >> (Int32)r);
81             }
82         }
83
84         internal sealed class ShrInt32Lifted : ShrInstruction {
85             protected override object Calculate (object l, object r)
86             {
87                 return (Int32?)((Int32?)l >> (Int32?)r);
88             }
89         }
90
91         internal sealed class ShrInt16Lifted : ShrInstruction {
92             protected override object Calculate (object l, object r)
93             {
94                 return (Int32)((Int16?)l >> (Int32?)r);
95             }
96         }
97
98         internal sealed class ShrInt64Lifted : ShrInstruction {
99             protected override object Calculate (object l, object r)
100             {
101                 return (Int64?)((Int64?)l >> (Int32?)r);
102             }
103         }
104
105         internal sealed class ShrUInt16Lifted : ShrInstruction {
106             protected override object Calculate (object l, object r)
107             {
108                 return (Int32?)((UInt16?)l >> (Int32?)r);
109             }
110         }
111
112         internal sealed class ShrUInt32Lifted : ShrInstruction {
113             protected override object Calculate (object l, object r)
114             {
115                 return (UInt32?)((UInt32?)l >> (Int32?)r);
116             }
117         }
118
119         internal sealed class ShrUInt64Lifted : ShrInstruction {
120             protected override object Calculate (object l, object r)
121             {
122                 return (UInt64?)((UInt64?)l >> (Int32?)r);
123             }
124         }
125
126         public static Instruction Create(Type type) {
127             Debug.Assert(!type.IsEnum());
128             switch (type.GetTypeCode()) {
129                 case TypeCode.Int16: return _Int16 ?? (_Int16 = new ShrInt16());
130                 case TypeCode.Int32: return _Int32 ?? (_Int32 = new ShrInt32());
131                 case TypeCode.Int64: return _Int64 ?? (_Int64 = new ShrInt64());
132                 case TypeCode.UInt16: return _UInt16 ?? (_UInt16 = new ShrUInt16());
133                 case TypeCode.UInt32: return _UInt32 ?? (_UInt32 = new ShrUInt32());
134                 case TypeCode.UInt64: return _UInt64 ?? (_UInt64 = new ShrUInt64());
135
136                 default:
137                     throw Assert.Unreachable;
138             }
139         }
140
141         public static Instruction CreateLifted(Type type) {
142             Debug.Assert(!type.IsEnum());
143             switch (type.GetTypeCode()) {
144                 case TypeCode.Int16: return _Int16Lifted ?? (_Int16Lifted = new ShrInt16Lifted());
145                 case TypeCode.Int32: return _Int32Lifted ?? (_Int32Lifted = new ShrInt32Lifted());
146                 case TypeCode.Int64: return _Int64Lifted ?? (_Int64Lifted = new ShrInt64Lifted());
147                 case TypeCode.UInt16: return _UInt16Lifted ?? (_UInt16Lifted = new ShrUInt16Lifted());
148                 case TypeCode.UInt32: return _UInt32Lifted ?? (_UInt32Lifted = new ShrUInt32Lifted());
149                 case TypeCode.UInt64: return _UInt64Lifted ?? (_UInt64Lifted = new ShrUInt64Lifted());
150
151                 default:
152                     throw Assert.Unreachable;
153             }
154         }
155
156         public override string ToString() {
157             return "Shr()";
158         }
159     }
160 }