+++ /dev/null
-// #define ARCH_32
-
-/* This is _NOT_ set by Xamarin.iOS. We can enable it in order to make sure
- * methods are intrinsified (by throwing NotImplementedException), but some
- * methods aren't intrinsified by JIT/interp. For example, conversion to
- * decimal. Therefore JIT/interp should fall back to managed implementation.
- */
-// #define NINT_JIT_OPTIMIZED
-
-using System;
-using System.Diagnostics;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Collections.Generic;
-
-
-public class BuiltinTests {
- static int test_0_nint_ctor ()
- {
- var x = new nint (10);
- var y = new nint (x);
- var z = new nint (new nint (20));
- if ((int)x != 10)
- return 1;
- if ((int)y != 10)
- return 2;
- if ((int)z != 20)
- return 3;
- return 0;
- }
-
- static int test_0_nint_casts ()
- {
- var x = (nint)10;
- var y = (nint)20L;
- int z = 30;
-
- if ((int)x != 10)
- return 1;
- if ((long)x != 10L)
- return 2;
- if ((int)y != 20)
- return 3;
- if ((long)y != 20L)
- return 4;
- if ((nint)z != 30)
- return 5;
- return 0;
- }
-
- static int test_0_nint_plus ()
- {
- var x = (nint)10;
- var z = +x;
- if ((int)z != 10)
- return 1;
- return 0;
- }
-
- static int test_0_nint_neg ()
- {
- var x = (nint)10;
- var z = -x;
- if ((int)z != -10)
- return 1;
- return 0;
- }
-
- static int test_0_nint_comp ()
- {
- var x = (nint)10;
- var z = ~x;
- if ((int)z != ~10)
- return 1;
- return 0;
- }
-
- static int test_0_nint_inc ()
- {
- var x = (nint)10;
- ++x;
- if ((int)x != 11)
- return 1;
- return 0;
- }
-
- static int test_0_nint_dec ()
- {
- var x = (nint)10;
- --x;
- if ((int)x != 9)
- return 1;
- return 0;
- }
-
- static int test_0_nint_add ()
- {
- var x = (nint)10;
- var y = (nint)20;
- var z = x + y;
- if ((int)z != 30)
- return 1;
- return 0;
- }
-
- static int test_0_nint_sub ()
- {
- var x = (nint)10;
- var y = (nint)20;
- var z = x - y;
- if ((int)z != -10)
- return 1;
- return 0;
- }
-
- static int test_0_nint_mul ()
- {
- var x = (nint)10;
- var y = (nint)20;
- var z = x * y;
- if ((int)z != 200)
- return 1;
- return 0;
- }
-
- static int test_0_nint_div ()
- {
- var x = (nint)30;
- var y = (nint)3;
- var z = x / y;
- if ((int)z != 10)
- return 1;
- return 0;
- }
-
- static int test_0_nint_rem ()
- {
- var x = (nint)22;
- var y = (nint)10;
- var z = x % y;
- if ((int)z != 2)
- return 1;
- return 0;
- }
-
- static int test_0_nint_and ()
- {
- var x = (nint)0x30;
- var y = (nint)0x11;
- var z = x & y;
- if ((int)z != 0x10)
- return 1;
- return 0;
- }
-
- static int test_0_nint_or ()
- {
- var x = (nint)0x0F;
- var y = (nint)0xF0;
- var z = x | y;
- if ((int)z != 0xFF)
- return 1;
- return 0;
- }
-
- static int test_0_nint_xor ()
- {
- var x = (nint)0xFF;
- var y = (nint)0xF0;
- var z = x ^ y;
- if ((int)z != 0x0F)
- return 1;
- return 0;
- }
-
- static int test_0_nint_shl ()
- {
- var x = (nint)10;
- var z = x << 2;
- if ((int)z != 40)
- return 1;
- return 0;
- }
-
- static int test_0_nint_shr ()
- {
- var x = (nint)10;
- var z = x >> 2;
- if ((int)z != 2)
- return 1;
- return 0;
- }
-
- static int test_0_nint_cmp_same_val ()
- {
- var x = (nint)10;
- var y = (nint)10;
- if (!(x == y))
- return 1;
- if (x != y)
- return 2;
- if (x < y)
- return 3;
- if (x > y)
- return 4;
- if (!(x <= y))
- return 5;
- if (!(x >= y))
- return 6;
- return 0;
- }
-
- static int test_0_nint_cmp_small_val ()
- {
- var x = (nint)5;
- var y = (nint)10;
- if (x == y)
- return 1;
- if (!(x != y))
- return 2;
- if (!(x < y))
- return 3;
- if (x > y)
- return 4;
- if (!(x <= y))
- return 5;
- if (x >= y)
- return 6;
- return 0;
- }
-
- static int test_0_nint_cmp_large_val ()
- {
- var x = (nint)20;
- var y = (nint)10;
- if (x == y)
- return 1;
- if (!(x != y))
- return 2;
- if (x < y)
- return 3;
- if (!(x > y))
- return 4;
- if (x <= y)
- return 1;
- if (!(x >= y))
- return 1;
- return 0;
- }
-
- static int test_0_nint_compareto ()
- {
- if (((nint) 0).CompareTo ((nint) 0) != 0)
- return 1;
- if (((nint) 0).CompareTo ((nint) 1) != -1)
- return 2;
- if (((nint) 1).CompareTo ((nint) 0) != 1)
- return 3;
-
- if (((nint) 0).CompareTo ((object)(nint) 0) != 0)
- return 4;
- if (((nint) 0).CompareTo ((object)(nint) 1) != -1)
- return 5;
- if (((nint) 1).CompareTo ((object)(nint) 0) != 1)
- return 6;
-
- if (((nint) 1).CompareTo (null) != 1)
- return 7;
-
- return 0;
- }
-
- static int test_0_nint_call_boxed_equals ()
- {
- object x = new nint (10);
- object y = new nint (10);
- if (!x.Equals (y))
- return 1;
- return 0;
- }
-
- static int test_0_nint_equals ()
- {
- if (!((nint) 0).Equals ((nint) 0))
- return 1;
- if (!((nint) 0).Equals ((object) (nint) 0))
- return 2;
- if (((nint) 0).Equals (null))
- return 3;
- return 0;
- }
-
- private sealed class MyGenericEqualityComparer<T> : EqualityComparer<T> where T : IEquatable<T>
- {
- public sealed override bool Equals(T x, T y) {
- if (x != null) {
- if (y != null)
- return x.Equals (y);
- return false;
- }
- if (y != null)
- return false;
- return true;
- }
-
- public sealed override int GetHashCode(T obj)
- {
- if (obj == null)
- return 0;
- return obj.GetHashCode ();
- }
- }
-
- static int test_0_nint_genequals ()
- {
- MyGenericEqualityComparer<nint> cmp = new MyGenericEqualityComparer<nint> ();
- if (cmp.Equals ((nint) 1, (nint) 2))
- return 1;
- if (!cmp.Equals ((nint) 4, (nint) 4))
- return 2;
- return 0;
- }
-
- static int test_0_nint_call_boxed_funs ()
- {
- object x = new nint (10);
- object y = new nint (10);
- if (x.GetHashCode () == 0)
- return 2;
- if (x.ToString () != "10")
- return 3;
- return 0;
- }
-
- static int test_0_nint_tostring ()
- {
- int x = 1337;
- if (((nint) x).ToString () != "1337")
- return 1;
- x = -1337;
- if (((nint) x).ToString () != "-1337")
- return 2;
-
- return 0;
- }
-
- [MethodImplAttribute (MethodImplOptions.NoInlining)]
- static bool decimal_cmp (decimal a, decimal b)
- {
- return a == b;
- }
-
- static bool decimal_cmp_can_inline (decimal a, decimal b)
- {
- return a == b;
- }
-
- static int test_0_nint_implicit_decimal ()
- {
- nint a = new nint (10);
- nint b = new nint (9);
- if (decimal_cmp (a, b))
- return 1;
- b++;
- if (!decimal_cmp (a, b))
- return 2;
- if (!decimal_cmp ((nint) 10, b))
- return 3;
- if (!decimal_cmp (a, (nint) 10))
- return 4;
- return 0;
- }
-
- static int test_0_nint_unboxed_member_calls ()
- {
- var x = (nint)10;
-#if FALSE
- if (!x.Equals (x))
- return 1;
-#endif
- if (x != nint.Parse ("10"))
- return 2;
- return 0;
- }
-
- struct SomeNativeStructWithNint {
- public nint a;
- public static nint b;
-
- public SomeNativeStructWithNint (nint a)
- {
- this.a = a;
- b = a + 1;
- }
-
- public static nint GetAStatic (SomeNativeStructWithNint x)
- {
- return x.a;
- }
-
- public nint GetA ()
- {
- return a;
- }
- }
-
- class SomeClassWithNint {
- public nint a;
-
- public SomeClassWithNint (nint a)
- {
- this.a = a;
- }
-
- public virtual nint GetAVirtual ()
- {
- return a;
- }
- }
-
- static int test_0_nint_fieldload ()
- {
- var x = new SomeNativeStructWithNint ((nint) 20f);
-
- if ((float) x.a != 20f)
- return 1;
-
- if ((int) x.a != 20)
- return 2;
-
- if ((float) SomeNativeStructWithNint.GetAStatic (x) != 20f)
- return 3;
-
- if ((float) x.GetA () != 20f)
- return 4;
-
- if ((int) SomeNativeStructWithNint.GetAStatic (x) != 20)
- return 5;
-
- if ((int) x.GetA () != 20)
- return 6;
-
- if ((float) SomeNativeStructWithNint.b != 21f)
- return 7;
-
- if ((int) SomeNativeStructWithNint.b != 21)
- return 8;
-
- SomeClassWithNint y = new SomeClassWithNint ((nint) 30f);
-
- if ((int) y.GetAVirtual () != 30)
- return 9;
-
- if ((float) y.GetAVirtual () != 30f)
- return 10;
-
- return 0;
- }
-
- static int NuintConstructor (nuint cap)
- {
- if (cap > (ulong) nint.MaxValue)
- return 1;
- return 0;
- }
-
- /* resembles https://github.com/xamarin/xamarin-macios/blob/bc492585d137d8c3d3a2ffc827db3cdaae3cc869/tests/monotouch-test/Foundation/MutableDataTest.cs#L62-L89 */
- static int test_0_nint_maxintcmp ()
- {
- /* does not work on 32bit */
- if (IntPtr.Size == 4)
- return 0;
-
- uint cap = (uint) Int32.MaxValue + 2;
- return NuintConstructor (cap);
- }
-
-
- static int test_0_nuint_ctor ()
- {
- var x = new nuint (10u);
- var y = new nuint (x);
- var z = new nuint (new nuint (20u));
- if ((uint)x != 10)
- return 1;
- if ((uint)y != 10)
- return 2;
- if ((uint)z != 20)
- return 3;
- return 0;
- }
-
- static int test_0_nuint_casts ()
- {
- var x = (nuint)10;
- var y = (nuint)20L;
- int z = 30;
-
- if ((uint)x != 10)
- return 1;
- if ((ulong)x != 10L)
- return 2;
- if ((uint)y != 20)
- return 3;
- if ((ulong)y != 20L)
- return 4;
- if ((nuint)z != 30)
- return 5;
- return 0;
- }
-
- static int test_0_nuint_plus ()
- {
- var x = (nuint)10;
- var z = +x;
- if ((uint)z != 10)
- return 1;
- return 0;
- }
-
- // static int test_0_nuint_neg ()
- // {
- // var x = (nuint)10;
- // var z = -x;
- // if ((uint)z != -10)
- // return 1;
- // return 0;
- // }
-
- static int test_0_nuint_comp ()
- {
- var x = (nuint)10;
- var z = ~x;
- if ((uint)z != ~10u)
- return 1;
- return 0;
- }
-
- static int test_0_nuint_inc ()
- {
- var x = (nuint)10;
- ++x;
- if ((uint)x != 11)
- return 1;
- return 0;
- }
-
- static int test_0_nuint_dec ()
- {
- var x = (nuint)10;
- --x;
- if ((uint)x != 9)
- return 1;
- return 0;
- }
-
- static int test_0_nuint_add ()
- {
- var x = (nuint)10;
- var y = (nuint)20;
- var z = x + y;
- if ((uint)z != 30)
- return 1;
- return 0;
- }
-
- static int test_0_nuint_sub ()
- {
- var x = (nuint)20;
- var y = (nuint)5;
- var z = x - y;
- if ((uint)z != 15)
- return 1;
- return 0;
- }
-
- static int test_0_nuint_mul ()
- {
- var x = (nuint)10;
- var y = (nuint)20;
- var z = x * y;
- if ((uint)z != 200)
- return 1;
- return 0;
- }
-
- static int test_0_nuint_div ()
- {
- var x = (nuint)30;
- var y = (nuint)3;
- var z = x / y;
- if ((uint)z != 10)
- return 1;
- return 0;
- }
-
- static int test_0_nuint_rem ()
- {
- var x = (nuint)22;
- var y = (nuint)10;
- var z = x % y;
- if ((uint)z != 2)
- return 1;
- return 0;
- }
-
- static int test_0_nuint_and ()
- {
- var x = (nuint)0x30;
- var y = (nuint)0x11;
- var z = x & y;
- if ((uint)z != 0x10)
- return 1;
- return 0;
- }
-
- static int test_0_nuint_or ()
- {
- var x = (nuint)0x0F;
- var y = (nuint)0xF0;
- var z = x | y;
- if ((uint)z != 0xFF)
- return 1;
- return 0;
- }
-
- static int test_0_nuint_xor ()
- {
- var x = (nuint)0xFF;
- var y = (nuint)0xF0;
- var z = x ^ y;
- if ((uint)z != 0x0F)
- return 1;
- return 0;
- }
-
- static int test_0_nuint_shl ()
- {
- var x = (nuint)10;
- var z = x << 2;
- if ((uint)z != 40)
- return 1;
- return 0;
- }
-
- static int test_0_nuint_shr ()
- {
- var x = (nuint)10;
- var z = x >> 2;
- if ((uint)z != 2)
- return 1;
- return 0;
- }
-
- static int test_0_nuint_cmp_same_val ()
- {
- var x = (nuint)10;
- var y = (nuint)10;
- if (!(x == y))
- return 1;
- if (x != y)
- return 2;
- if (x < y)
- return 3;
- if (x > y)
- return 4;
- if (!(x <= y))
- return 5;
- if (!(x >= y))
- return 6;
- return 0;
- }
-
- static int test_0_nuint_cmp_small_val ()
- {
- var x = (nuint)5;
- var y = (nuint)10;
- if (x == y)
- return 1;
- if (!(x != y))
- return 2;
- if (!(x < y))
- return 3;
- if (x > y)
- return 4;
- if (!(x <= y))
- return 5;
- if (x >= y)
- return 6;
- return 0;
- }
-
- static int test_0_nuint_cmp_large_val ()
- {
- var x = (nuint)20;
- var y = (nuint)10;
- if (x == y)
- return 1;
- if (!(x != y))
- return 2;
- if (x < y)
- return 3;
- if (!(x > y))
- return 4;
- if (x <= y)
- return 1;
- if (!(x >= y))
- return 1;
- return 0;
- }
-
- static int test_0_nuint_compareto ()
- {
- if (((nuint) 0).CompareTo ((nuint) 0) != 0)
- return 1;
- if (((nuint) 0).CompareTo ((nuint) 1) != -1)
- return 2;
- if (((nuint) 1).CompareTo ((nuint) 0) != 1)
- return 3;
-
- if (((nuint) 0).CompareTo ((object)(nuint) 0) != 0)
- return 4;
- if (((nuint) 0).CompareTo ((object)(nuint) 1) != -1)
- return 5;
- if (((nuint) 1).CompareTo ((object)(nuint) 0) != 1)
- return 6;
-
- if (((nuint) 1).CompareTo (null) != 1)
- return 7;
-
- return 0;
- }
-
- static int test_0_nuint_call_boxed_equals ()
- {
- object x = new nuint (10);
- object y = new nuint (10);
- if (!x.Equals (y))
- return 1;
- return 0;
- }
-
- static int test_0_nuint_equals ()
- {
- if (!((nuint) 0).Equals ((nuint) 0))
- return 1;
- if (!((nuint) 0).Equals ((object) (nuint) 0))
- return 2;
- if (((nuint) 0).Equals (null))
- return 3;
- return 0;
- }
-
- static int test_0_nuint_call_boxed_funs ()
- {
- object x = new nuint (10u);
- object y = new nuint (10u);
- if (x.GetHashCode () == 0)
- return 2;
- if (x.ToString () != "10")
- return 3;
- return 0;
- }
-
- static int test_0_nuint_tostring ()
- {
- int x = 1337;
- if (((nuint) x).ToString () != "1337")
- return 1;
- x = -1337;
- if (((nuint) x).ToString () == "-1337")
- return 2;
-
- return 0;
- }
-
- static int test_0_nuint_implicit_decimal ()
- {
- nuint a = new nuint (10);
- nuint b = new nuint (9);
- if (decimal_cmp (a, b))
- return 1;
- b++;
- if (!decimal_cmp (a, b))
- return 2;
- if (!decimal_cmp ((nuint) 10, b))
- return 3;
- if (!decimal_cmp (a, (nuint) 10))
- return 4;
- return 0;
- }
-
- static int test_0_nuint_unboxed_member_calls ()
- {
- var x = (nuint)10;
-#if FALSE
- if (!x.Equals (x))
- return 1;
-#endif
- if (x != nuint.Parse ("10"))
- return 2;
- return 0;
- }
-
- struct SomeNativeStructWithNuint {
- public nuint a;
- public static nuint b;
-
- public SomeNativeStructWithNuint (nuint a)
- {
- this.a = a;
- b = a + 1;
- }
-
- public static nuint GetAStatic (SomeNativeStructWithNuint x)
- {
- return x.a;
- }
-
- public nuint GetA ()
- {
- return a;
- }
- }
-
- class SomeClassWithNuint {
- public nuint a;
-
- public SomeClassWithNuint (nuint a)
- {
- this.a = a;
- }
-
- public virtual nuint GetAVirtual ()
- {
- return a;
- }
- }
-
- static int test_0_nuint_fieldload ()
- {
- var x = new SomeNativeStructWithNuint ((nuint) 20f);
-
- if ((float) x.a != 20f)
- return 1;
-
- if ((int) x.a != 20)
- return 2;
-
- if ((float) SomeNativeStructWithNuint.GetAStatic (x) != 20f)
- return 3;
-
- if ((float) x.GetA () != 20f)
- return 4;
-
- if ((int) SomeNativeStructWithNuint.GetAStatic (x) != 20)
- return 5;
-
- if ((int) x.GetA () != 20)
- return 6;
-
- if (!decimal_cmp_can_inline ((int) x.GetA (), 20))
- return 66;
-
- if ((float) SomeNativeStructWithNuint.b != 21f)
- return 7;
-
- if ((int) SomeNativeStructWithNuint.b != 21)
- return 8;
-
- SomeClassWithNuint y = new SomeClassWithNuint ((nuint) 30f);
-
- if ((int) y.GetAVirtual () != 30)
- return 9;
-
- if ((float) y.GetAVirtual () != 30f)
- return 10;
-
- return 0;
- }
-
- static int test_0_nfloat_ctor ()
- {
- var x = new nfloat (10.0f);
- var y = new nfloat (x);
- var z = new nfloat (new nfloat (20f));
- if ((float)x != 10f)
- return 1;
- if ((float)y != 10f)
- return 2;
- if ((float)z != 20f)
- return 3;
- return 0;
- }
-
- static int test_0_nfloat_casts ()
- {
- var x = (nfloat)10f;
-
- if ((float)x != 10f)
- return 1;
- if ((double)x != 10)
- return 2;
-#if FALSE
- var y = (nfloat)20;
- if ((float)y != 20f)
- return 3;
- if ((double)y != 20)
- return 4;
-#endif
- int z = 30;
- if ((nfloat) z != 30f)
- return 5;
-
- if ((int) x != 10)
- return 6;
- return 0;
- }
-
- static int test_0_nfloat_plus ()
- {
- var x = (nfloat)10f;
- var z = +x;
- if ((float)z != 10f)
- return 1;
- return 0;
- }
-
- static int test_0_nfloat_neg ()
- {
- var x = (nfloat)10f;
- var z = -x;
- if ((float)z != -10f)
- return 1;
- return 0;
- }
-
-#if FALSE
- static int test_0_nfloat_inc ()
- {
- var x = (nfloat)10f;
- ++x;
- if ((float)x != 11f) {
- Console.WriteLine ((float)x);
- return 1;
- }
- return 0;
- }
-
- static int test_0_nfloat_dec ()
- {
- var x = (nfloat)10f;
- --x;
- if ((float)x != 9f) {
- Console.WriteLine ((float)x);
- return 1;
- }
- return 0;
- }
-#endif
-
- static int test_0_nfloat_add ()
- {
- var x = (nfloat)10f;
- var y = (nfloat)20f;
- var z = x + y;
- if ((float)z != 30f)
- return 1;
- return 0;
- }
-
- static int test_0_nfloat_sub ()
- {
- var x = (nfloat)10f;
- var y = (nfloat)20f;
- var z = x - y;
- if ((float)z != -10f)
- return 1;
- return 0;
- }
-
- static int test_0_nfloat_mul ()
- {
- var x = (nfloat)10f;
- var y = (nfloat)20f;
- var z = x * y;
- if ((float)z != 200f)
- return 1;
- return 0;
- }
-
- static int test_0_nfloat_div ()
- {
- var x = (nfloat)30f;
- var y = (nfloat)3f;
- var z = x / y;
- if ((float)z != 10f)
- return 1;
- return 0;
- }
-
- static int test_0_nfloat_rem ()
- {
- var x = (nfloat)22f;
- var y = (nfloat)10f;
- var z = x % y;
- if ((float)z != 2f)
- return 1;
- return 0;
- }
-
- static int test_0_nfloat_cmp_same_val ()
- {
- var x = (nfloat)10f;
- var y = (nfloat)10f;
- if (!(x == y))
- return 1;
- if (x != y)
- return 2;
- if (x < y)
- return 3;
- if (x > y)
- return 4;
- if (!(x <= y))
- return 5;
- if (!(x >= y))
- return 6;
- return 0;
- }
-
- static int test_0_nfloat_cmp_small_val ()
- {
- var x = (nfloat)5f;
- var y = (nfloat)10f;
- if (x == y)
- return 1;
- if (!(x != y))
- return 2;
- if (!(x < y))
- return 3;
- if (x > y)
- return 4;
- if (!(x <= y))
- return 5;
- if (x >= y)
- return 6;
- return 0;
- }
-
- static int test_0_nfloat_cmp_large_val ()
- {
- var x = (nfloat)20f;
- var y = (nfloat)10f;
- if (x == y)
- return 1;
- if (!(x != y))
- return 2;
- if (x < y)
- return 3;
- if (!(x > y))
- return 4;
- if (x <= y)
- return 1;
- if (!(x >= y))
- return 1;
- return 0;
- }
-
- /* fails on arm64 */
- static int test_0_nfloat_cmp_left_nan ()
- {
- var x = (nfloat)float.NaN;
- var y = (nfloat)10f;
- if (x == y)
- return 1;
- if (!(x != y))
- return 2;
- if (x < y)
- return 3;
- if (x > y)
- return 4;
- if (x <= y)
- return 5;
- if (x >= y)
- return 6;
- return 0;
- }
-
-
- static int test_0_nfloat_cmp_right_nan ()
- {
- var x = (nfloat)10f;
- var y = (nfloat)float.NaN;
- if (x == y)
- return 1;
- if (!(x != y))
- return 2;
- if (x < y)
- return 3;
- if (x > y)
- return 4;
- if (x <= y)
- return 5;
- if (x >= y)
- return 6;
- return 0;
- }
-
- static int test_0_nfloat_isinfinity ()
- {
- var x = (nfloat) float.NaN;
- if (nfloat.IsInfinity (x))
- return 1;
- if (nfloat.IsInfinity (12))
- return 2;
- if (!nfloat.IsInfinity (nfloat.PositiveInfinity))
- return 3;
- if (!nfloat.IsInfinity (nfloat.NegativeInfinity))
- return 4;
-
- return 0;
- }
-
- static int test_0_nfloat_isnegativeinfinity ()
- {
- var x = (nfloat) float.NaN;
- if (nfloat.IsNegativeInfinity (x))
- return 1;
- if (nfloat.IsNegativeInfinity (12))
- return 2;
- if (nfloat.IsNegativeInfinity (nfloat.PositiveInfinity))
- return 3;
- if (!nfloat.IsNegativeInfinity (nfloat.NegativeInfinity))
- return 4;
-
- float f = float.NegativeInfinity;
- nfloat n = (nfloat) f;
- if (!nfloat.IsNegativeInfinity (n))
- return 5;
-
- double d = double.NegativeInfinity;
- n = (nfloat) d;
- if (!nfloat.IsNegativeInfinity (n))
- return 6;
-
- return 0;
- }
-
- static int test_0_nfloat_ispositiveinfinity ()
- {
- var x = (nfloat) float.NaN;
- if (nfloat.IsPositiveInfinity (x))
- return 1;
- if (nfloat.IsPositiveInfinity (12))
- return 2;
- if (!nfloat.IsPositiveInfinity (nfloat.PositiveInfinity))
- return 3;
- if (nfloat.IsPositiveInfinity (nfloat.NegativeInfinity))
- return 4;
-
- float f = float.PositiveInfinity;
- nfloat n = (nfloat) f;
- if (!nfloat.IsPositiveInfinity (n))
- return 5;
-
- double d = double.PositiveInfinity;
- n = (nfloat) d;
- if (!nfloat.IsPositiveInfinity (n))
- return 6;
-
- return 0;
- }
-
- static int test_0_nfloat_isnan ()
- {
- var x = (nfloat) float.NaN;
- if (!nfloat.IsNaN (x))
- return 1;
- if (nfloat.IsNaN (12))
- return 2;
- if (nfloat.IsNaN (nfloat.PositiveInfinity))
- return 3;
- if (nfloat.IsNaN (nfloat.NegativeInfinity))
- return 4;
-
- float f = float.NaN;
- nfloat n = (nfloat) f;
- if (!nfloat.IsNaN (n))
- return 5;
-
- double d = double.NaN;
- n = (nfloat) d;
- if (!nfloat.IsNaN (n))
- return 6;
-
- return 0;
- }
-
- static int test_0_nfloat_compareto ()
- {
- if (((nfloat) 0).CompareTo ((nfloat) 0) != 0)
- return 1;
- if (((nfloat) 0).CompareTo ((nfloat) 1) != -1)
- return 2;
- if (((nfloat) 1).CompareTo ((nfloat) 0) != 1)
- return 3;
-
- if (((nfloat) 0).CompareTo ((object)(nfloat) 0) != 0)
- return 4;
- if (((nfloat) 0).CompareTo ((object)(nfloat) 1) != -1)
- return 5;
- if (((nfloat) 1).CompareTo ((object)(nfloat) 0) != 1)
- return 6;
-
- if (((nfloat) 1).CompareTo (null) != 1)
- return 7;
-
- return 0;
- }
-
- static int test_0_nfloat_call_boxed_equals ()
- {
- object x = new nfloat (10f);
- object y = new nfloat (10f);
- if (!x.Equals (y))
- return 1;
- return 0;
- }
-
- static int test_0_nfloat_equals ()
- {
- if (!((nfloat) 0).Equals ((nfloat) 0))
- return 1;
- if (!((nfloat) 0).Equals ((object) (nfloat) 0))
- return 2;
- if (((nfloat) 0).Equals (null))
- return 3;
- return 0;
- }
-
- static int test_0_nfloat_call_boxed_funs ()
- {
- object x = new nfloat (10f);
- object y = new nfloat (10f);
- if (x.GetHashCode () == 0)
- return 2;
- if (x.ToString () != "10")
- return 3;
- return 0;
- }
-
- static int test_0_nfloat_tostring ()
- {
- float x = 1337.0f;
- nfloat y = (nfloat) x;
- if (y.ToString () != "1337")
- return 1;
- x = -1337.0f;
- if (((nfloat) x).ToString () != "-1337")
- return 2;
-
- return 0;
- }
-
- static int test_0_nfloat_explicit_decimal ()
- {
- nfloat a = new nfloat (10);
- nfloat b = new nfloat (9);
- if (decimal_cmp ((decimal) a, (decimal) b))
- return 1;
- b += 1.0f;
- if (!decimal_cmp ((decimal) a, (decimal) b))
- return 2;
- if (!decimal_cmp ((decimal) (nfloat) 10.0f, (decimal) b))
- return 3;
- if (!decimal_cmp ((decimal) a, (decimal) (nfloat) 10.0f))
- return 4;
- return 0;
- }
-
- static int test_0_nfloat_unboxed_member_calls ()
- {
- var x = (nfloat)10f;
-#if FALSE
- if (!x.Equals (x))
- return 1;
-#endif
- if (x != nfloat.Parse ("10"))
- return 2;
- return 0;
- }
-
- struct SomeNativeStructWithNfloat {
- public nfloat a;
- public static nfloat b;
-
- public SomeNativeStructWithNfloat (nfloat a)
- {
- this.a = a;
- b = a + 1;
- }
-
- public static nfloat GetAStatic (SomeNativeStructWithNfloat x)
- {
- return x.a;
- }
-
- public nfloat GetA ()
- {
- return a;
- }
- }
-
- class SomeClassWithNfloat {
- public nfloat a;
-
- public SomeClassWithNfloat (nfloat a)
- {
- this.a = a;
- }
-
- public virtual nfloat GetAVirtual ()
- {
- return a;
- }
- }
-
- static int test_0_nfloat_fieldload ()
- {
- var x = new SomeNativeStructWithNfloat ((nfloat) 20f);
-
- if ((float) x.a != 20f)
- return 1;
-
- if ((int) x.a != 20)
- return 2;
-
- if ((float) SomeNativeStructWithNfloat.GetAStatic (x) != 20f)
- return 3;
-
- if ((float) x.GetA () != 20f)
- return 4;
-
- if ((int) SomeNativeStructWithNfloat.GetAStatic (x) != 20)
- return 5;
-
- if ((int) x.GetA () != 20)
- return 6;
-
- if ((float) SomeNativeStructWithNfloat.b != 21f)
- return 7;
-
- if ((int) SomeNativeStructWithNfloat.b != 21)
- return 8;
-
- SomeClassWithNfloat y = new SomeClassWithNfloat ((nfloat) 30f);
-
- if ((int) y.GetAVirtual () != 30)
- return 9;
-
- if ((float) y.GetAVirtual () != 30f)
- return 10;
-
- return 0;
- }
-
- static int test_0_much_casting ()
- {
- var notOof = (int)(float)1;
- if (notOof != 1)
- return 1;
-
- var notOof2 = (nint)(float)(nfloat)1;
- if (notOof2 != 1)
- return 2;
-
- var notOof3 = (nint)(int)(nfloat)1;
- if (notOof3 != 1)
- return 3;
-
- var oof = (nint)(nfloat)1;
- var oof2 = (int) oof - 1;
- if (oof2 != 0)
- return 4;
-
- var noof = (nfloat)(nint)1;
- var noof2 = (float) noof - 1;
- if (noof2 > 0.1)
- return 5;
-
- return 0;
- }
-
-#if !__MOBILE__
- public static int Main (String[] args) {
- return TestDriver.RunTests (typeof (BuiltinTests), args);
- }
-#endif
-}
-
-
-// !!! WARNING - GENERATED CODE - DO NOT EDIT !!!
-//
-// Generated by NativeTypes.tt, a T4 template.
-//
-// NativeTypes.cs: basic types with 32 or 64 bit sizes:
-//
-// - nint
-// - nuint
-// - nfloat
-//
-// Authors:
-// Aaron Bockover <abock@xamarin.com>
-//
-// Copyright 2013 Xamarin, Inc. All rights reserved.
-//
-
-namespace System
-{
- [Serializable]
- [DebuggerDisplay ("{v,nq}")]
- public unsafe struct nint : IFormattable, IConvertible, IComparable, IComparable<nint>, IEquatable <nint>
- {
- internal nint (nint v) { this.v = v.v; }
- public nint (Int32 v) { this.v = v; }
-
-#if ARCH_32
- public static readonly int Size = 4;
-
- public static readonly nint MaxValue = Int32.MaxValue;
- public static readonly nint MinValue = Int32.MinValue;
-
- [DebuggerBrowsable (DebuggerBrowsableState.Never)]
- internal Int32 v;
-
- public nint (Int64 v) { this.v = (Int32)v; }
-#else
- public static readonly int Size = 8;
-
- public static readonly nint MaxValue = (nint) Int64.MaxValue; // 64-bit only codepath
- public static readonly nint MinValue = (nint) Int64.MinValue; // 64-bit only codepath
-
- [DebuggerBrowsable (DebuggerBrowsableState.Never)]
- internal Int64 v;
-
- public nint (Int64 v) { this.v = v; }
-#endif
-
- public static explicit operator nint (nuint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nint ((int)v.v);
-#else
- return new nint ((long)v.v);
-#endif
- }
-
- public static explicit operator nuint (nint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nuint ((uint)v.v);
-#else
- return new nuint ((ulong)v.v);
-#endif
- }
-
- public static explicit operator nint (nfloat v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nint ((int)v.v);
-#else
- return new nint ((long)v.v);
-#endif
- }
-
- public static implicit operator nfloat (nint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nfloat ((float)v.v);
-#else
- return new nfloat ((double)v.v);
-#endif
- }
-
- public static explicit operator nint (IntPtr v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nint (*((int *)&v));
-#else
- return new nint (*((long *)&v));
-#endif
- }
-
- public static explicit operator IntPtr (nint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return *((IntPtr *)&v.v);
-#else
- return *((IntPtr *)&v.v);
-#endif
- }
-
- public static implicit operator nint (sbyte v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nint ((int)v);
-#else
- return new nint ((long)v);
-#endif
- }
-
- public static explicit operator sbyte (nint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (sbyte)v.v;
-#else
- return (sbyte)v.v;
-#endif
- }
-
- public static implicit operator nint (byte v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nint ((int)v);
-#else
- return new nint ((long)v);
-#endif
- }
-
- public static explicit operator byte (nint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (byte)v.v;
-#else
- return (byte)v.v;
-#endif
- }
-
- public static implicit operator nint (char v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nint ((int)v);
-#else
- return new nint ((long)v);
-#endif
- }
-
- public static explicit operator char (nint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (char)v.v;
-#else
- return (char)v.v;
-#endif
- }
-
- public static implicit operator nint (short v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nint ((int)v);
-#else
- return new nint ((long)v);
-#endif
- }
-
- public static explicit operator short (nint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (short)v.v;
-#else
- return (short)v.v;
-#endif
- }
-
- public static explicit operator nint (ushort v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nint ((int)v);
-#else
- return new nint ((long)v);
-#endif
- }
-
- public static explicit operator ushort (nint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (ushort)v.v;
-#else
- return (ushort)v.v;
-#endif
- }
-
- public static implicit operator nint (int v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nint ((int)v);
-#else
- return new nint ((long)v);
-#endif
- }
-
- public static explicit operator int (nint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (int)v.v;
-#else
- return (int)v.v;
-#endif
- }
-
- public static explicit operator nint (uint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nint ((int)v);
-#else
- return new nint ((long)v);
-#endif
- }
-
- public static explicit operator uint (nint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (uint)v.v;
-#else
- return (uint)v.v;
-#endif
- }
-
- public static implicit operator nint (long v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nint ((int)v);
-#else
- return new nint ((long)v);
-#endif
- }
-
- public static implicit operator long (nint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (long)v.v;
-#else
- return (long)v.v;
-#endif
- }
-
- public static explicit operator nint (ulong v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nint ((int)v);
-#else
- return new nint ((long)v);
-#endif
- }
-
- public static explicit operator ulong (nint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (ulong)v.v;
-#else
- return (ulong)v.v;
-#endif
- }
-
- public static explicit operator nint (float v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nint ((int)v);
-#else
- return new nint ((long)v);
-#endif
- }
-
- public static implicit operator float (nint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (float)v.v;
-#else
- return (float)v.v;
-#endif
- }
-
- public static explicit operator nint (double v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nint ((int)v);
-#else
- return new nint ((long)v);
-#endif
- }
-
- public static implicit operator double (nint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (double)v.v;
-#else
- return (double)v.v;
-#endif
- }
-
- public static explicit operator nint (decimal v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nint ((int)v);
-#else
- return new nint ((long)v);
-#endif
- }
-
- public static implicit operator decimal (nint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (decimal)v.v;
-#else
- return (decimal)v.v;
-#endif
- }
-
-#if NINT_JIT_OPTIMIZED
- public static nint operator + (nint v) { throw new NotImplementedException (); }
- public static nint operator - (nint v) { throw new NotImplementedException (); }
- public static nint operator ~ (nint v) { throw new NotImplementedException (); }
-#else
- public static nint operator + (nint v) { return new nint (+v.v); }
- public static nint operator - (nint v) { return new nint (-v.v); }
- public static nint operator ~ (nint v) { return new nint (~v.v); }
-#endif
-
-
-#if NINT_JIT_OPTIMIZED
- public static nint operator + (nint l, nint r) { throw new NotImplementedException (); }
- public static nint operator - (nint l, nint r) { throw new NotImplementedException (); }
- public static nint operator * (nint l, nint r) { throw new NotImplementedException (); }
- public static nint operator / (nint l, nint r) { throw new NotImplementedException (); }
- public static nint operator % (nint l, nint r) { throw new NotImplementedException (); }
- public static nint operator & (nint l, nint r) { throw new NotImplementedException (); }
- public static nint operator | (nint l, nint r) { throw new NotImplementedException (); }
- public static nint operator ^ (nint l, nint r) { throw new NotImplementedException (); }
-
- public static nint operator << (nint l, int r) { throw new NotImplementedException (); }
- public static nint operator >> (nint l, int r) { throw new NotImplementedException (); }
-#else
- public static nint operator + (nint l, nint r) { return new nint (l.v + r.v); }
- public static nint operator - (nint l, nint r) { return new nint (l.v - r.v); }
- public static nint operator * (nint l, nint r) { return new nint (l.v * r.v); }
- public static nint operator / (nint l, nint r) { return new nint (l.v / r.v); }
- public static nint operator % (nint l, nint r) { return new nint (l.v % r.v); }
- public static nint operator & (nint l, nint r) { return new nint (l.v & r.v); }
- public static nint operator | (nint l, nint r) { return new nint (l.v | r.v); }
- public static nint operator ^ (nint l, nint r) { return new nint (l.v ^ r.v); }
-
- public static nint operator << (nint l, int r) { return new nint (l.v << r); }
- public static nint operator >> (nint l, int r) { return new nint (l.v >> r); }
-#endif
-
-#if NINT_JIT_OPTIMIZED
- public static bool operator == (nint l, nint r) { throw new NotImplementedException (); }
- public static bool operator != (nint l, nint r) { throw new NotImplementedException (); }
- public static bool operator < (nint l, nint r) { throw new NotImplementedException (); }
- public static bool operator > (nint l, nint r) { throw new NotImplementedException (); }
- public static bool operator <= (nint l, nint r) { throw new NotImplementedException (); }
- public static bool operator >= (nint l, nint r) { throw new NotImplementedException (); }
-#else
- public static bool operator == (nint l, nint r) { return l.v == r.v; }
- public static bool operator != (nint l, nint r) { return l.v != r.v; }
- public static bool operator < (nint l, nint r) { return l.v < r.v; }
- public static bool operator > (nint l, nint r) { return l.v > r.v; }
- public static bool operator <= (nint l, nint r) { return l.v <= r.v; }
- public static bool operator >= (nint l, nint r) { return l.v >= r.v; }
-#endif
-
- public int CompareTo (nint value) { return v.CompareTo (value.v); }
- public int CompareTo (object value)
- {
- if (value is nint)
- return v.CompareTo (((nint) value).v);
- return v.CompareTo (value);
- }
- public bool Equals (nint obj) { return v.Equals (obj.v); }
- public override bool Equals (object obj)
- {
- if (obj is nint)
- return v.Equals (((nint) obj).v);
- return v.Equals (obj);
- }
- public override int GetHashCode () { return v.GetHashCode (); }
-
-#if ARCH_32
- public static nint Parse (string s, IFormatProvider provider) { return (nint)Int32.Parse (s, provider); }
- public static nint Parse (string s, NumberStyles style) { return (nint)Int32.Parse (s, style); }
- public static nint Parse (string s) { return (nint)Int32.Parse (s); }
- public static nint Parse (string s, NumberStyles style, IFormatProvider provider) {
- return (nint)Int32.Parse (s, style, provider);
- }
-
- public static bool TryParse (string s, out nint result)
- {
- Int32 v;
- var r = Int32.TryParse (s, out v);
- result = (nint)v;
- return r;
- }
-
- public static bool TryParse (string s, NumberStyles style, IFormatProvider provider, out nint result)
- {
- Int32 v;
- var r = Int32.TryParse (s, style, provider, out v);
- result = (nint)v;
- return r;
- }
-#else
- public static nint Parse (string s, IFormatProvider provider) { return (nint)Int64.Parse (s, provider); }
- public static nint Parse (string s, NumberStyles style) { return (nint)Int64.Parse (s, style); }
- public static nint Parse (string s) { return (nint)Int64.Parse (s); }
- public static nint Parse (string s, NumberStyles style, IFormatProvider provider) {
- return (nint)Int64.Parse (s, style, provider);
- }
-
- public static bool TryParse (string s, out nint result)
- {
- Int64 v;
- var r = Int64.TryParse (s, out v);
- result = (nint)v;
- return r;
- }
-
- public static bool TryParse (string s, NumberStyles style, IFormatProvider provider, out nint result)
- {
- Int64 v;
- var r = Int64.TryParse (s, style, provider, out v);
- result = (nint)v;
- return r;
- }
-#endif
-
- public override string ToString () { return v.ToString (); }
- public string ToString (IFormatProvider provider) { return v.ToString (provider); }
- public string ToString (string format) { return v.ToString (format); }
- public string ToString (string format, IFormatProvider provider) { return v.ToString (format, provider); }
-
- public TypeCode GetTypeCode () { return v.GetTypeCode (); }
-
- bool IConvertible.ToBoolean (IFormatProvider provider) { return ((IConvertible)v).ToBoolean (provider); }
- byte IConvertible.ToByte (IFormatProvider provider) { return ((IConvertible)v).ToByte (provider); }
- char IConvertible.ToChar (IFormatProvider provider) { return ((IConvertible)v).ToChar (provider); }
- DateTime IConvertible.ToDateTime (IFormatProvider provider) { return ((IConvertible)v).ToDateTime (provider); }
- decimal IConvertible.ToDecimal (IFormatProvider provider) { return ((IConvertible)v).ToDecimal (provider); }
- double IConvertible.ToDouble (IFormatProvider provider) { return ((IConvertible)v).ToDouble (provider); }
- short IConvertible.ToInt16 (IFormatProvider provider) { return ((IConvertible)v).ToInt16 (provider); }
- int IConvertible.ToInt32 (IFormatProvider provider) { return ((IConvertible)v).ToInt32 (provider); }
- long IConvertible.ToInt64 (IFormatProvider provider) { return ((IConvertible)v).ToInt64 (provider); }
- sbyte IConvertible.ToSByte (IFormatProvider provider) { return ((IConvertible)v).ToSByte (provider); }
- float IConvertible.ToSingle (IFormatProvider provider) { return ((IConvertible)v).ToSingle (provider); }
- ushort IConvertible.ToUInt16 (IFormatProvider provider) { return ((IConvertible)v).ToUInt16 (provider); }
- uint IConvertible.ToUInt32 (IFormatProvider provider) { return ((IConvertible)v).ToUInt32 (provider); }
- ulong IConvertible.ToUInt64 (IFormatProvider provider) { return ((IConvertible)v).ToUInt64 (provider); }
-
- object IConvertible.ToType (Type targetType, IFormatProvider provider) {
- return ((IConvertible)v).ToType (targetType, provider);
- }
-
- public static void CopyArray (IntPtr source, nint [] destination, int startIndex, int length)
- {
- if (source == IntPtr.Zero)
- throw new ArgumentNullException ("source");
- if (destination == null)
- throw new ArgumentNullException ("destination");
- if (destination.Rank != 1)
- throw new ArgumentException ("destination", "array is multi-dimensional");
- if (startIndex < 0)
- throw new ArgumentException ("startIndex", "must be >= 0");
- if (length < 0)
- throw new ArgumentException ("length", "must be >= 0");
- if (startIndex + length > destination.Length)
- throw new ArgumentException ("length", "startIndex + length > destination.Length");
-
- for (int i = 0; i < length; i++)
- destination [i + startIndex] = (nint)Marshal.ReadIntPtr (source, i * nint.Size);
- }
-
- public static void CopyArray (nint [] source, int startIndex, IntPtr destination, int length)
- {
- if (source == null)
- throw new ArgumentNullException ("source");
- if (destination == IntPtr.Zero)
- throw new ArgumentNullException ("destination");
- if (source.Rank != 1)
- throw new ArgumentException ("source", "array is multi-dimensional");
- if (startIndex < 0)
- throw new ArgumentException ("startIndex", "must be >= 0");
- if (length < 0)
- throw new ArgumentException ("length", "must be >= 0");
- if (startIndex + length > source.Length)
- throw new ArgumentException ("length", "startIndex + length > source.Length");
-
- for (int i = 0; i < length; i++)
- Marshal.WriteIntPtr (destination, i * nint.Size, (IntPtr)source [i + startIndex]);
- }
- }
- [Serializable]
- [DebuggerDisplay ("{v,nq}")]
- public unsafe struct nuint : IFormattable, IConvertible, IComparable, IComparable<nuint>, IEquatable <nuint>
- {
- internal nuint (nuint v) { this.v = v.v; }
- public nuint (UInt32 v) { this.v = v; }
-
-#if ARCH_32
- public static readonly int Size = 4;
-
- public static readonly nuint MaxValue = UInt32.MaxValue;
- public static readonly nuint MinValue = UInt32.MinValue;
-
- [DebuggerBrowsable (DebuggerBrowsableState.Never)]
- internal UInt32 v;
-
- public nuint (UInt64 v) { this.v = (UInt32)v; }
-#else
- public static readonly int Size = 8;
-
- public static readonly nuint MaxValue = (nuint) UInt64.MaxValue; // 64-bit only codepath
- public static readonly nuint MinValue = (nuint) UInt64.MinValue; // 64-bit only codepath
-
- [DebuggerBrowsable (DebuggerBrowsableState.Never)]
- internal UInt64 v;
-
- public nuint (UInt64 v) { this.v = v; }
-#endif
-
- public static explicit operator nuint (nfloat v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nuint ((uint)v.v);
-#else
- return new nuint ((ulong)v.v);
-#endif
- }
-
- public static implicit operator nfloat (nuint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nfloat ((float)v.v);
-#else
- return new nfloat ((double)v.v);
-#endif
- }
-
- public static explicit operator nuint (IntPtr v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nuint (*((uint *)&v));
-#else
- return new nuint (*((ulong *)&v));
-#endif
- }
-
- public static explicit operator IntPtr (nuint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return *((IntPtr *)&v.v);
-#else
- return *((IntPtr *)&v.v);
-#endif
- }
-
- public static explicit operator nuint (sbyte v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nuint ((uint)v);
-#else
- return new nuint ((ulong)v);
-#endif
- }
-
- public static explicit operator sbyte (nuint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (sbyte)v.v;
-#else
- return (sbyte)v.v;
-#endif
- }
-
- public static implicit operator nuint (byte v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nuint ((uint)v);
-#else
- return new nuint ((ulong)v);
-#endif
- }
-
- public static explicit operator byte (nuint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (byte)v.v;
-#else
- return (byte)v.v;
-#endif
- }
-
- public static implicit operator nuint (char v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nuint ((uint)v);
-#else
- return new nuint ((ulong)v);
-#endif
- }
-
- public static explicit operator char (nuint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (char)v.v;
-#else
- return (char)v.v;
-#endif
- }
-
- public static explicit operator nuint (short v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nuint ((uint)v);
-#else
- return new nuint ((ulong)v);
-#endif
- }
-
- public static explicit operator short (nuint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (short)v.v;
-#else
- return (short)v.v;
-#endif
- }
-
- public static implicit operator nuint (ushort v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nuint ((uint)v);
-#else
- return new nuint ((ulong)v);
-#endif
- }
-
- public static explicit operator ushort (nuint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (ushort)v.v;
-#else
- return (ushort)v.v;
-#endif
- }
-
- public static explicit operator nuint (int v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nuint ((uint)v);
-#else
- return new nuint ((ulong)v);
-#endif
- }
-
- public static explicit operator int (nuint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (int)v.v;
-#else
- return (int)v.v;
-#endif
- }
-
- public static implicit operator nuint (uint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nuint ((uint)v);
-#else
- return new nuint ((ulong)v);
-#endif
- }
-
- public static explicit operator uint (nuint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (uint)v.v;
-#else
- return (uint)v.v;
-#endif
- }
-
- public static explicit operator nuint (long v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nuint ((uint)v);
-#else
- return new nuint ((ulong)v);
-#endif
- }
-
- public static explicit operator long (nuint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (long)v.v;
-#else
- return (long)v.v;
-#endif
- }
-
- public static implicit operator nuint (ulong v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nuint ((uint)v);
-#else
- return new nuint ((ulong)v);
-#endif
- }
-
- public static implicit operator ulong (nuint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (ulong)v.v;
-#else
- return (ulong)v.v;
-#endif
- }
-
- public static explicit operator nuint (float v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nuint ((uint)v);
-#else
- return new nuint ((ulong)v);
-#endif
- }
-
- public static implicit operator float (nuint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (float)v.v;
-#else
- return (float)v.v;
-#endif
- }
-
- public static explicit operator nuint (double v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nuint ((uint)v);
-#else
- return new nuint ((ulong)v);
-#endif
- }
-
- public static implicit operator double (nuint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (double)v.v;
-#else
- return (double)v.v;
-#endif
- }
-
- public static explicit operator nuint (decimal v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nuint ((uint)v);
-#else
- return new nuint ((ulong)v);
-#endif
- }
-
- public static implicit operator decimal (nuint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (decimal)v.v;
-#else
- return (decimal)v.v;
-#endif
- }
-
-#if NINT_JIT_OPTIMIZED
- public static nuint operator + (nuint v) { throw new NotImplementedException (); }
- public static nuint operator ~ (nuint v) { throw new NotImplementedException (); }
-#else
- public static nuint operator + (nuint v) { return new nuint (+v.v); }
- public static nuint operator ~ (nuint v) { return new nuint (~v.v); }
-#endif
-
-#if NINT_JIT_OPTIMIZED
- public static nuint operator + (nuint l, nuint r) { throw new NotImplementedException (); }
- public static nuint operator - (nuint l, nuint r) { throw new NotImplementedException (); }
- public static nuint operator * (nuint l, nuint r) { throw new NotImplementedException (); }
- public static nuint operator / (nuint l, nuint r) { throw new NotImplementedException (); }
- public static nuint operator % (nuint l, nuint r) { throw new NotImplementedException (); }
- public static nuint operator & (nuint l, nuint r) { throw new NotImplementedException (); }
- public static nuint operator | (nuint l, nuint r) { throw new NotImplementedException (); }
- public static nuint operator ^ (nuint l, nuint r) { throw new NotImplementedException (); }
-
- public static nuint operator << (nuint l, int r) { throw new NotImplementedException (); }
- public static nuint operator >> (nuint l, int r) { throw new NotImplementedException (); }
-#else
- public static nuint operator + (nuint l, nuint r) { return new nuint (l.v + r.v); }
- public static nuint operator - (nuint l, nuint r) { return new nuint (l.v - r.v); }
- public static nuint operator * (nuint l, nuint r) { return new nuint (l.v * r.v); }
- public static nuint operator / (nuint l, nuint r) { return new nuint (l.v / r.v); }
- public static nuint operator % (nuint l, nuint r) { return new nuint (l.v % r.v); }
- public static nuint operator & (nuint l, nuint r) { return new nuint (l.v & r.v); }
- public static nuint operator | (nuint l, nuint r) { return new nuint (l.v | r.v); }
- public static nuint operator ^ (nuint l, nuint r) { return new nuint (l.v ^ r.v); }
-
- public static nuint operator << (nuint l, int r) { return new nuint (l.v << r); }
- public static nuint operator >> (nuint l, int r) { return new nuint (l.v >> r); }
-#endif
-
-#if NINT_JIT_OPTIMIZED
- public static bool operator == (nuint l, nuint r) { throw new NotImplementedException (); }
- public static bool operator != (nuint l, nuint r) { throw new NotImplementedException (); }
- public static bool operator < (nuint l, nuint r) { throw new NotImplementedException (); }
- public static bool operator > (nuint l, nuint r) { throw new NotImplementedException (); }
- public static bool operator <= (nuint l, nuint r) { throw new NotImplementedException (); }
- public static bool operator >= (nuint l, nuint r) { throw new NotImplementedException (); }
-#else
- public static bool operator == (nuint l, nuint r) { return l.v == r.v; }
- public static bool operator != (nuint l, nuint r) { return l.v != r.v; }
- public static bool operator < (nuint l, nuint r) { return l.v < r.v; }
- public static bool operator > (nuint l, nuint r) { return l.v > r.v; }
- public static bool operator <= (nuint l, nuint r) { return l.v <= r.v; }
- public static bool operator >= (nuint l, nuint r) { return l.v >= r.v; }
-#endif
-
- public int CompareTo (nuint value) { return v.CompareTo (value.v); }
- public int CompareTo (object value)
- {
- if (value is nuint)
- return v.CompareTo (((nuint) value).v);
- return v.CompareTo (value);
- }
- public bool Equals (nuint obj) { return v.Equals (obj.v); }
- public override bool Equals (object obj)
- {
- if (obj is nuint)
- return v.Equals (((nuint) obj).v);
- return v.Equals (obj);
- }
- public override int GetHashCode () { return v.GetHashCode (); }
-
-#if ARCH_32
- public static nuint Parse (string s, IFormatProvider provider) { return (nuint)UInt32.Parse (s, provider); }
- public static nuint Parse (string s, NumberStyles style) { return (nuint)UInt32.Parse (s, style); }
- public static nuint Parse (string s) { return (nuint)UInt32.Parse (s); }
- public static nuint Parse (string s, NumberStyles style, IFormatProvider provider) {
- return (nuint)UInt32.Parse (s, style, provider);
- }
-
- public static bool TryParse (string s, out nuint result)
- {
- UInt32 v;
- var r = UInt32.TryParse (s, out v);
- result = (nuint)v;
- return r;
- }
-
- public static bool TryParse (string s, NumberStyles style, IFormatProvider provider, out nuint result)
- {
- UInt32 v;
- var r = UInt32.TryParse (s, style, provider, out v);
- result = (nuint)v;
- return r;
- }
-#else
- public static nuint Parse (string s, IFormatProvider provider) { return (nuint)UInt64.Parse (s, provider); }
- public static nuint Parse (string s, NumberStyles style) { return (nuint)UInt64.Parse (s, style); }
- public static nuint Parse (string s) { return (nuint)UInt64.Parse (s); }
- public static nuint Parse (string s, NumberStyles style, IFormatProvider provider) {
- return (nuint)UInt64.Parse (s, style, provider);
- }
-
- public static bool TryParse (string s, out nuint result)
- {
- UInt64 v;
- var r = UInt64.TryParse (s, out v);
- result = (nuint)v;
- return r;
- }
-
- public static bool TryParse (string s, NumberStyles style, IFormatProvider provider, out nuint result)
- {
- UInt64 v;
- var r = UInt64.TryParse (s, style, provider, out v);
- result = (nuint)v;
- return r;
- }
-#endif
-
- public override string ToString () { return v.ToString (); }
- public string ToString (IFormatProvider provider) { return v.ToString (provider); }
- public string ToString (string format) { return v.ToString (format); }
- public string ToString (string format, IFormatProvider provider) { return v.ToString (format, provider); }
-
- public TypeCode GetTypeCode () { return v.GetTypeCode (); }
-
- bool IConvertible.ToBoolean (IFormatProvider provider) { return ((IConvertible)v).ToBoolean (provider); }
- byte IConvertible.ToByte (IFormatProvider provider) { return ((IConvertible)v).ToByte (provider); }
- char IConvertible.ToChar (IFormatProvider provider) { return ((IConvertible)v).ToChar (provider); }
- DateTime IConvertible.ToDateTime (IFormatProvider provider) { return ((IConvertible)v).ToDateTime (provider); }
- decimal IConvertible.ToDecimal (IFormatProvider provider) { return ((IConvertible)v).ToDecimal (provider); }
- double IConvertible.ToDouble (IFormatProvider provider) { return ((IConvertible)v).ToDouble (provider); }
- short IConvertible.ToInt16 (IFormatProvider provider) { return ((IConvertible)v).ToInt16 (provider); }
- int IConvertible.ToInt32 (IFormatProvider provider) { return ((IConvertible)v).ToInt32 (provider); }
- long IConvertible.ToInt64 (IFormatProvider provider) { return ((IConvertible)v).ToInt64 (provider); }
- sbyte IConvertible.ToSByte (IFormatProvider provider) { return ((IConvertible)v).ToSByte (provider); }
- float IConvertible.ToSingle (IFormatProvider provider) { return ((IConvertible)v).ToSingle (provider); }
- ushort IConvertible.ToUInt16 (IFormatProvider provider) { return ((IConvertible)v).ToUInt16 (provider); }
- uint IConvertible.ToUInt32 (IFormatProvider provider) { return ((IConvertible)v).ToUInt32 (provider); }
- ulong IConvertible.ToUInt64 (IFormatProvider provider) { return ((IConvertible)v).ToUInt64 (provider); }
-
- object IConvertible.ToType (Type targetType, IFormatProvider provider) {
- return ((IConvertible)v).ToType (targetType, provider);
- }
-
- public static void CopyArray (IntPtr source, nuint [] destination, int startIndex, int length)
- {
- if (source == IntPtr.Zero)
- throw new ArgumentNullException ("source");
- if (destination == null)
- throw new ArgumentNullException ("destination");
- if (destination.Rank != 1)
- throw new ArgumentException ("destination", "array is multi-dimensional");
- if (startIndex < 0)
- throw new ArgumentException ("startIndex", "must be >= 0");
- if (length < 0)
- throw new ArgumentException ("length", "must be >= 0");
- if (startIndex + length > destination.Length)
- throw new ArgumentException ("length", "startIndex + length > destination.Length");
-
- for (int i = 0; i < length; i++)
- destination [i + startIndex] = (nuint)Marshal.ReadIntPtr (source, i * nuint.Size);
- }
-
- public static void CopyArray (nuint [] source, int startIndex, IntPtr destination, int length)
- {
- if (source == null)
- throw new ArgumentNullException ("source");
- if (destination == IntPtr.Zero)
- throw new ArgumentNullException ("destination");
- if (source.Rank != 1)
- throw new ArgumentException ("source", "array is multi-dimensional");
- if (startIndex < 0)
- throw new ArgumentException ("startIndex", "must be >= 0");
- if (length < 0)
- throw new ArgumentException ("length", "must be >= 0");
- if (startIndex + length > source.Length)
- throw new ArgumentException ("length", "startIndex + length > source.Length");
-
- for (int i = 0; i < length; i++)
- Marshal.WriteIntPtr (destination, i * nuint.Size, (IntPtr)source [i + startIndex]);
- }
- }
- [Serializable]
- [DebuggerDisplay ("{v,nq}")]
- public unsafe struct nfloat : IFormattable, IConvertible, IComparable, IComparable<nfloat>, IEquatable <nfloat>
- {
- internal nfloat (nfloat v) { this.v = v.v; }
- public nfloat (Single v) { this.v = v; }
-
-#if ARCH_32
- public static readonly int Size = 4;
-
- public static readonly nfloat MaxValue = Single.MaxValue;
- public static readonly nfloat MinValue = Single.MinValue;
- public static readonly nfloat Epsilon = (nfloat)Single.Epsilon;
- public static readonly nfloat NaN = (nfloat)Single.NaN;
- public static readonly nfloat NegativeInfinity = (nfloat)Single.NegativeInfinity;
- public static readonly nfloat PositiveInfinity = (nfloat)Single.PositiveInfinity;
-
- [DebuggerBrowsable (DebuggerBrowsableState.Never)]
- internal Single v;
-
- public nfloat (Double v) { this.v = (Single)v; }
-#else
- public static readonly int Size = 8;
-
- public static readonly nfloat MaxValue = (nfloat) Double.MaxValue; // 64-bit only codepath
- public static readonly nfloat MinValue = (nfloat) Double.MinValue; // 64-bit only codepath
- public static readonly nfloat Epsilon = (nfloat)Double.Epsilon;
- public static readonly nfloat NaN = (nfloat)Double.NaN;
- public static readonly nfloat NegativeInfinity = (nfloat)Double.NegativeInfinity;
- public static readonly nfloat PositiveInfinity = (nfloat)Double.PositiveInfinity;
-
- [DebuggerBrowsable (DebuggerBrowsableState.Never)]
- internal Double v;
-
- public nfloat (Double v) { this.v = v; }
-#endif
-
- public static explicit operator nfloat (IntPtr v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nfloat (*((float *)&v));
-#else
- return new nfloat (*((double *)&v));
-#endif
- }
-
- public static explicit operator IntPtr (nfloat v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return *((IntPtr *)&v.v);
-#else
- return *((IntPtr *)&v.v);
-#endif
- }
-
- public static implicit operator nfloat (sbyte v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nfloat ((float)v);
-#else
- return new nfloat ((double)v);
-#endif
- }
-
- public static explicit operator sbyte (nfloat v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (sbyte)v.v;
-#else
- return (sbyte)v.v;
-#endif
- }
-
- public static implicit operator nfloat (byte v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nfloat ((float)v);
-#else
- return new nfloat ((double)v);
-#endif
- }
-
- public static explicit operator byte (nfloat v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (byte)v.v;
-#else
- return (byte)v.v;
-#endif
- }
-
- public static implicit operator nfloat (char v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nfloat ((float)v);
-#else
- return new nfloat ((double)v);
-#endif
- }
-
- public static explicit operator char (nfloat v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (char)v.v;
-#else
- return (char)v.v;
-#endif
- }
-
- public static implicit operator nfloat (short v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nfloat ((float)v);
-#else
- return new nfloat ((double)v);
-#endif
- }
-
- public static explicit operator short (nfloat v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (short)v.v;
-#else
- return (short)v.v;
-#endif
- }
-
- public static implicit operator nfloat (ushort v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nfloat ((float)v);
-#else
- return new nfloat ((double)v);
-#endif
- }
-
- public static explicit operator ushort (nfloat v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (ushort)v.v;
-#else
- return (ushort)v.v;
-#endif
- }
-
- public static implicit operator nfloat (int v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nfloat ((float)v);
-#else
- return new nfloat ((double)v);
-#endif
- }
-
- public static explicit operator int (nfloat v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (int)v.v;
-#else
- return (int)v.v;
-#endif
- }
-
- public static implicit operator nfloat (uint v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nfloat ((float)v);
-#else
- return new nfloat ((double)v);
-#endif
- }
-
- public static explicit operator uint (nfloat v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (uint)v.v;
-#else
- return (uint)v.v;
-#endif
- }
-
- public static implicit operator nfloat (long v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nfloat ((float)v);
-#else
- return new nfloat ((double)v);
-#endif
- }
-
- public static explicit operator long (nfloat v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (long)v.v;
-#else
- return (long)v.v;
-#endif
- }
-
- public static implicit operator nfloat (ulong v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nfloat ((float)v);
-#else
- return new nfloat ((double)v);
-#endif
- }
-
- public static explicit operator ulong (nfloat v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (ulong)v.v;
-#else
- return (ulong)v.v;
-#endif
- }
-
- public static implicit operator nfloat (float v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nfloat ((float)v);
-#else
- return new nfloat ((double)v);
-#endif
- }
-
- public static explicit operator float (nfloat v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (float)v.v;
-#else
- return (float)v.v;
-#endif
- }
-
- public static explicit operator nfloat (double v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nfloat ((float)v);
-#else
- return new nfloat ((double)v);
-#endif
- }
-
- public static implicit operator double (nfloat v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (double)v.v;
-#else
- return (double)v.v;
-#endif
- }
-
- public static explicit operator nfloat (decimal v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return new nfloat ((float)v);
-#else
- return new nfloat ((double)v);
-#endif
- }
-
- public static explicit operator decimal (nfloat v)
- {
-#if NINT_JIT_OPTIMIZED
- throw new NotImplementedException ();
-#elif ARCH_32
- return (decimal)v.v;
-#else
- return (decimal)v.v;
-#endif
- }
-
-#if NINT_JIT_OPTIMIZED
- public static nfloat operator + (nfloat v) { throw new NotImplementedException (); }
- public static nfloat operator - (nfloat v) { throw new NotImplementedException (); }
-#else
- public static nfloat operator + (nfloat v) { return new nfloat (+v.v); }
- public static nfloat operator - (nfloat v) { return new nfloat (-v.v); }
-#endif
-
-#if NINT_JIT_OPTIMIZED
- public static nfloat operator ++ (nfloat v) { throw new NotImplementedException (); }
- public static nfloat operator -- (nfloat v) { throw new NotImplementedException (); }
-#else
- public static nfloat operator ++ (nfloat v) { return new nfloat (v.v + 1); }
- public static nfloat operator -- (nfloat v) { return new nfloat (v.v - 1); }
-#endif
-
-#if NINT_JIT_OPTIMIZED
- public static nfloat operator + (nfloat l, nfloat r) { throw new NotImplementedException (); }
- public static nfloat operator - (nfloat l, nfloat r) { throw new NotImplementedException (); }
- public static nfloat operator * (nfloat l, nfloat r) { throw new NotImplementedException (); }
- public static nfloat operator / (nfloat l, nfloat r) { throw new NotImplementedException (); }
- public static nfloat operator % (nfloat l, nfloat r) { throw new NotImplementedException (); }
-#else
- public static nfloat operator + (nfloat l, nfloat r) { return new nfloat (l.v + r.v); }
- public static nfloat operator - (nfloat l, nfloat r) { return new nfloat (l.v - r.v); }
- public static nfloat operator * (nfloat l, nfloat r) { return new nfloat (l.v * r.v); }
- public static nfloat operator / (nfloat l, nfloat r) { return new nfloat (l.v / r.v); }
- public static nfloat operator % (nfloat l, nfloat r) { return new nfloat (l.v % r.v); }
-#endif
-
-#if NINT_JIT_OPTIMIZED
- public static bool operator == (nfloat l, nfloat r) { throw new NotImplementedException (); }
- public static bool operator != (nfloat l, nfloat r) { throw new NotImplementedException (); }
- public static bool operator < (nfloat l, nfloat r) { throw new NotImplementedException (); }
- public static bool operator > (nfloat l, nfloat r) { throw new NotImplementedException (); }
- public static bool operator <= (nfloat l, nfloat r) { throw new NotImplementedException (); }
- public static bool operator >= (nfloat l, nfloat r) { throw new NotImplementedException (); }
-#else
- public static bool operator == (nfloat l, nfloat r) { return l.v == r.v; }
- public static bool operator != (nfloat l, nfloat r) { return l.v != r.v; }
- public static bool operator < (nfloat l, nfloat r) { return l.v < r.v; }
- public static bool operator > (nfloat l, nfloat r) { return l.v > r.v; }
- public static bool operator <= (nfloat l, nfloat r) { return l.v <= r.v; }
- public static bool operator >= (nfloat l, nfloat r) { return l.v >= r.v; }
-#endif
-
- public int CompareTo (nfloat value) { return v.CompareTo (value.v); }
- public int CompareTo (object value)
- {
- if (value is nfloat)
- return v.CompareTo (((nfloat) value).v);
- return v.CompareTo (value);
- }
- public bool Equals (nfloat obj) { return v.Equals (obj.v); }
- public override bool Equals (object obj)
- {
- if (obj is nfloat)
- return v.Equals (((nfloat) obj).v);
- return v.Equals (obj);
- }
- public override int GetHashCode () { return v.GetHashCode (); }
-
-#if ARCH_32
- public static bool IsNaN (nfloat f) { return Single.IsNaN ((Single)f); }
- public static bool IsInfinity (nfloat f) { return Single.IsInfinity ((Single)f); }
- public static bool IsPositiveInfinity (nfloat f) { return Single.IsPositiveInfinity ((Single)f); }
- public static bool IsNegativeInfinity (nfloat f) { return Single.IsNegativeInfinity ((Single)f); }
-
- public static nfloat Parse (string s, IFormatProvider provider) { return (nfloat)Single.Parse (s, provider); }
- public static nfloat Parse (string s, NumberStyles style) { return (nfloat)Single.Parse (s, style); }
- public static nfloat Parse (string s) { return (nfloat)Single.Parse (s); }
- public static nfloat Parse (string s, NumberStyles style, IFormatProvider provider) {
- return (nfloat)Single.Parse (s, style, provider);
- }
-
- public static bool TryParse (string s, out nfloat result)
- {
- Single v;
- var r = Single.TryParse (s, out v);
- result = (nfloat)v;
- return r;
- }
-
- public static bool TryParse (string s, NumberStyles style, IFormatProvider provider, out nfloat result)
- {
- Single v;
- var r = Single.TryParse (s, style, provider, out v);
- result = (nfloat)v;
- return r;
- }
-#else
- public static bool IsNaN (nfloat f) { return Double.IsNaN ((Double)f); }
- public static bool IsInfinity (nfloat f) { return Double.IsInfinity ((Double)f); }
- public static bool IsPositiveInfinity (nfloat f) { return Double.IsPositiveInfinity ((Double)f); }
- public static bool IsNegativeInfinity (nfloat f) { return Double.IsNegativeInfinity ((Double)f); }
-
- public static nfloat Parse (string s, IFormatProvider provider) { return (nfloat)Double.Parse (s, provider); }
- public static nfloat Parse (string s, NumberStyles style) { return (nfloat)Double.Parse (s, style); }
- public static nfloat Parse (string s) { return (nfloat)Double.Parse (s); }
- public static nfloat Parse (string s, NumberStyles style, IFormatProvider provider) {
- return (nfloat)Double.Parse (s, style, provider);
- }
-
- public static bool TryParse (string s, out nfloat result)
- {
- Double v;
- var r = Double.TryParse (s, out v);
- result = (nfloat)v;
- return r;
- }
-
- public static bool TryParse (string s, NumberStyles style, IFormatProvider provider, out nfloat result)
- {
- Double v;
- var r = Double.TryParse (s, style, provider, out v);
- result = (nfloat)v;
- return r;
- }
-#endif
-
- public override string ToString () { return v.ToString (); }
- public string ToString (IFormatProvider provider) { return v.ToString (provider); }
- public string ToString (string format) { return v.ToString (format); }
- public string ToString (string format, IFormatProvider provider) { return v.ToString (format, provider); }
-
- public TypeCode GetTypeCode () { return v.GetTypeCode (); }
-
- bool IConvertible.ToBoolean (IFormatProvider provider) { return ((IConvertible)v).ToBoolean (provider); }
- byte IConvertible.ToByte (IFormatProvider provider) { return ((IConvertible)v).ToByte (provider); }
- char IConvertible.ToChar (IFormatProvider provider) { return ((IConvertible)v).ToChar (provider); }
- DateTime IConvertible.ToDateTime (IFormatProvider provider) { return ((IConvertible)v).ToDateTime (provider); }
- decimal IConvertible.ToDecimal (IFormatProvider provider) { return ((IConvertible)v).ToDecimal (provider); }
- double IConvertible.ToDouble (IFormatProvider provider) { return ((IConvertible)v).ToDouble (provider); }
- short IConvertible.ToInt16 (IFormatProvider provider) { return ((IConvertible)v).ToInt16 (provider); }
- int IConvertible.ToInt32 (IFormatProvider provider) { return ((IConvertible)v).ToInt32 (provider); }
- long IConvertible.ToInt64 (IFormatProvider provider) { return ((IConvertible)v).ToInt64 (provider); }
- sbyte IConvertible.ToSByte (IFormatProvider provider) { return ((IConvertible)v).ToSByte (provider); }
- float IConvertible.ToSingle (IFormatProvider provider) { return ((IConvertible)v).ToSingle (provider); }
- ushort IConvertible.ToUInt16 (IFormatProvider provider) { return ((IConvertible)v).ToUInt16 (provider); }
- uint IConvertible.ToUInt32 (IFormatProvider provider) { return ((IConvertible)v).ToUInt32 (provider); }
- ulong IConvertible.ToUInt64 (IFormatProvider provider) { return ((IConvertible)v).ToUInt64 (provider); }
-
- object IConvertible.ToType (Type targetType, IFormatProvider provider) {
- return ((IConvertible)v).ToType (targetType, provider);
- }
-
- public static void CopyArray (IntPtr source, nfloat [] destination, int startIndex, int length)
- {
- if (source == IntPtr.Zero)
- throw new ArgumentNullException ("source");
- if (destination == null)
- throw new ArgumentNullException ("destination");
- if (destination.Rank != 1)
- throw new ArgumentException ("destination", "array is multi-dimensional");
- if (startIndex < 0)
- throw new ArgumentException ("startIndex", "must be >= 0");
- if (length < 0)
- throw new ArgumentException ("length", "must be >= 0");
- if (startIndex + length > destination.Length)
- throw new ArgumentException ("length", "startIndex + length > destination.Length");
-
- for (int i = 0; i < length; i++)
- destination [i + startIndex] = (nfloat)Marshal.ReadIntPtr (source, i * nfloat.Size);
- }
-
- public static void CopyArray (nfloat [] source, int startIndex, IntPtr destination, int length)
- {
- if (source == null)
- throw new ArgumentNullException ("source");
- if (destination == IntPtr.Zero)
- throw new ArgumentNullException ("destination");
- if (source.Rank != 1)
- throw new ArgumentException ("source", "array is multi-dimensional");
- if (startIndex < 0)
- throw new ArgumentException ("startIndex", "must be >= 0");
- if (length < 0)
- throw new ArgumentException ("length", "must be >= 0");
- if (startIndex + length > source.Length)
- throw new ArgumentException ("length", "startIndex + length > source.Length");
-
- for (int i = 0; i < length; i++)
- Marshal.WriteIntPtr (destination, i * nfloat.Size, (IntPtr)source [i + startIndex]);
- }
- }
-}
#define MINT_STIND_I MINT_STIND_I4
#endif
-typedef struct {
- const gchar *op_name;
- guint16 insn [3];
-} MagicIntrinsic;
-
-// static const MagicIntrinsic int_binop[] = {
-
-static const MagicIntrinsic int_unnop[] = {
- { "op_UnaryPlus", {MINT_MOV_P, MINT_MOV_P, MINT_MOV_4}},
- { "op_UnaryNegation", {MINT_NEG_P, MINT_NEG_P, MINT_NEG_FP}},
- { "op_OnesComplement", {MINT_NOT_P, MINT_NOT_P, MINT_NIY}}
-};
-
-static const MagicIntrinsic int_binop[] = {
- { "op_Addition", {MINT_ADD_P, MINT_ADD_P, MINT_ADD_FP}},
- { "op_Subtraction", {MINT_SUB_P, MINT_SUB_P, MINT_SUB_FP}},
- { "op_Multiply", {MINT_MUL_P, MINT_MUL_P, MINT_MUL_FP}},
- { "op_Division", {MINT_DIV_P, MINT_DIV_UN_P, MINT_DIV_FP}},
- { "op_Modulus", {MINT_REM_P, MINT_REM_UN_P, MINT_REM_FP}},
- { "op_BitwiseAnd", {MINT_AND_P, MINT_AND_P, MINT_NIY}},
- { "op_BitwiseOr", {MINT_OR_P, MINT_OR_P, MINT_NIY}},
- { "op_ExclusiveOr", {MINT_XOR_P, MINT_XOR_P, MINT_NIY}},
- { "op_LeftShift", {MINT_SHL_P, MINT_SHL_P, MINT_NIY}},
- { "op_RightShift", {MINT_SHR_P, MINT_SHR_UN_P, MINT_NIY}},
-};
-
-static const MagicIntrinsic int_cmpop[] = {
- { "op_Inequality", {MINT_CNE_P, MINT_CNE_P, MINT_CNE_FP}},
- { "op_Equality", {MINT_CEQ_P, MINT_CEQ_P, MINT_CEQ_FP}},
- { "op_GreaterThan", {MINT_CGT_P, MINT_CGT_UN_P, MINT_CGT_FP}},
- { "op_GreaterThanOrEqual", {MINT_CGE_P, MINT_CGE_UN_P, MINT_CGE_FP}},
- { "op_LessThan", {MINT_CLT_P, MINT_CLT_UN_P, MINT_CLT_FP}},
- { "op_LessThanOrEqual", {MINT_CLE_P, MINT_CLE_UN_P, MINT_CLE_FP}}
-};
-
static const char *stack_type_string [] = { "I4", "I8", "R4", "R8", "O ", "VT", "MP", "F " };
static int stack_type [] = {
}
#endif
-static int mono_class_get_magic_index (MonoClass *k)
-{
- if (mono_class_is_magic_int (k))
- return !strcmp ("nint", m_class_get_name (k)) ? 0 : 1;
-
- if (mono_class_is_magic_float (k))
- return 2;
-
- return -1;
-}
-
static void
interp_generate_mae_throw (TransformData *td, MonoMethod *method, MonoMethod *target_method)
{
interp_ins_set_dreg (td->last_ins, td->sp [-1].local);
}
-static gboolean
-interp_handle_magic_type_intrinsics (TransformData *td, MonoMethod *target_method, MonoMethodSignature *csignature, int type_index)
-{
- MonoClass *magic_class = target_method->klass;
- const char *tm = target_method->name;
- int i;
-
- const int mt = mint_type (m_class_get_byval_arg (magic_class));
- if (!strcmp (".ctor", tm)) {
- MonoType *arg = csignature->params [0];
- /* depending on SIZEOF_VOID_P and the type of the value passed to the .ctor we either have to CONV it, or do nothing */
- int arg_size = mini_magic_type_size (NULL, arg);
-
- if (arg_size > SIZEOF_VOID_P) { // 8 -> 4
- switch (type_index) {
- case 0: case 1:
- interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I4, MINT_MOV_8);
- break;
- case 2:
- interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I4, MINT_CONV_R4_R8);
- break;
- }
- }
-
- if (arg_size < SIZEOF_VOID_P) { // 4 -> 8
- switch (type_index) {
- case 0:
- interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I8, MINT_CONV_I8_I4);
- break;
- case 1:
- interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I8, MINT_CONV_I8_U4);
- break;
- case 2:
- interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_R8, MINT_CONV_R8_R4);
- break;
- }
- }
-
- switch (type_index) {
- case 0: case 1:
-#if SIZEOF_VOID_P == 4
- interp_add_ins (td, MINT_STIND_I4);
-#else
- interp_add_ins (td, MINT_STIND_I8);
-#endif
- break;
- case 2:
-#if SIZEOF_VOID_P == 4
- interp_add_ins (td, MINT_STIND_R4);
-#else
- interp_add_ins (td, MINT_STIND_R8);
-#endif
- break;
- }
- td->sp -= 2;
- interp_ins_set_sregs2 (td->last_ins, td->sp [0].local, td->sp [1].local);
- td->ip += 5;
- return TRUE;
- } else if (!strcmp ("op_Implicit", tm ) || !strcmp ("op_Explicit", tm)) {
- MonoType *src = csignature->params [0];
- MonoType *dst = csignature->ret;
- MonoClass *src_klass = mono_class_from_mono_type_internal (src);
- int src_size = mini_magic_type_size (NULL, src);
- int dst_size = mini_magic_type_size (NULL, dst);
-
- gboolean managed_fallback = FALSE;
-
- switch (type_index) {
- case 0: case 1:
- if (!mini_magic_is_int_type (src) || !mini_magic_is_int_type (dst)) {
- if (mini_magic_is_int_type (src))
- managed_fallback = TRUE;
- else if (mono_class_is_magic_float (src_klass))
- managed_fallback = TRUE;
- else
- return FALSE;
- }
- break;
- case 2:
- if (!mini_magic_is_float_type (src) || !mini_magic_is_float_type (dst)) {
- if (mini_magic_is_float_type (src))
- managed_fallback = TRUE;
- else if (mono_class_is_magic_int (src_klass))
- managed_fallback = TRUE;
- else
- return FALSE;
- }
- break;
- }
-
- if (managed_fallback)
- return FALSE;
-
- if (src_size > dst_size) { // 8 -> 4
- switch (type_index) {
- case 0: case 1:
- interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I4, MINT_MOV_8);
- break;
- case 2:
- interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_R4, MINT_CONV_R4_R8);
- break;
- }
- }
-
- if (src_size < dst_size) { // 4 -> 8
- switch (type_index) {
- case 0:
- interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I8, MINT_CONV_I8_I4);
- break;
- case 1:
- interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I8, MINT_CONV_I8_U4);
- break;
- case 2:
- interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_R8, MINT_CONV_R8_R4);
- break;
- }
- }
-
- SET_TYPE (td->sp - 1, stack_type [mint_type (dst)], mono_class_from_mono_type_internal (dst));
- td->ip += 5;
- return TRUE;
- } else if (!strcmp ("op_Increment", tm)) {
- g_assert (type_index != 2); // no nfloat
-#if SIZEOF_VOID_P == 8
- interp_add_ins (td, MINT_ADD1_I8);
-#else
- interp_add_ins (td, MINT_ADD1_I4);
-#endif
- td->sp--;
- interp_ins_set_sreg (td->last_ins, td->sp [0].local);
- push_type (td, stack_type [mt], magic_class);
- interp_ins_set_dreg (td->last_ins, td->sp [-1].local);
- td->ip += 5;
- return TRUE;
- } else if (!strcmp ("op_Decrement", tm)) {
- g_assert (type_index != 2); // no nfloat
-#if SIZEOF_VOID_P == 8
- interp_add_ins (td, MINT_SUB1_I8);
-#else
- interp_add_ins (td, MINT_SUB1_I4);
-#endif
- td->sp--;
- interp_ins_set_sreg (td->last_ins, td->sp [0].local);
- push_type (td, stack_type [mt], magic_class);
- interp_ins_set_dreg (td->last_ins, td->sp [-1].local);
- td->ip += 5;
- return TRUE;
- } else if (!strcmp ("CompareTo", tm) || !strcmp ("Equals", tm)) {
- return FALSE;
- } else if (!strcmp (".cctor", tm)) {
- return FALSE;
- } else if (!strcmp ("Parse", tm)) {
- return FALSE;
- } else if (!strcmp ("ToString", tm)) {
- return FALSE;
- } else if (!strcmp ("GetHashCode", tm)) {
- return FALSE;
- } else if (!strcmp ("IsNaN", tm) || !strcmp ("IsInfinity", tm) || !strcmp ("IsNegativeInfinity", tm) || !strcmp ("IsPositiveInfinity", tm)) {
- g_assert (type_index == 2); // nfloat only
- return FALSE;
- }
-
- for (i = 0; i < sizeof (int_unnop) / sizeof (MagicIntrinsic); ++i) {
- if (!strcmp (int_unnop [i].op_name, tm)) {
- interp_add_ins (td, int_unnop [i].insn [type_index]);
- td->sp--;
- interp_ins_set_sreg (td->last_ins, td->sp [0].local);
- push_type (td, stack_type [mt], magic_class);
- interp_ins_set_dreg (td->last_ins, td->sp [-1].local);
- td->ip += 5;
- return TRUE;
- }
- }
-
- for (i = 0; i < sizeof (int_binop) / sizeof (MagicIntrinsic); ++i) {
- if (!strcmp (int_binop [i].op_name, tm)) {
- interp_add_ins (td, int_binop [i].insn [type_index]);
- td->sp -= 2;
- interp_ins_set_sregs2 (td->last_ins, td->sp [0].local, td->sp [1].local);
- push_type (td, stack_type [mt], magic_class);
- interp_ins_set_dreg (td->last_ins, td->sp [-1].local);
- td->ip += 5;
- return TRUE;
- }
- }
-
- for (i = 0; i < sizeof (int_cmpop) / sizeof (MagicIntrinsic); ++i) {
- if (!strcmp (int_cmpop [i].op_name, tm)) {
- MonoClass *k = mono_defaults.boolean_class;
- interp_add_ins (td, int_cmpop [i].insn [type_index]);
- td->sp -= 2;
- interp_ins_set_sregs2 (td->last_ins, td->sp [0].local, td->sp [1].local);
- push_type (td, stack_type [mint_type (m_class_get_byval_arg (k))], k);
- interp_ins_set_dreg (td->last_ins, td->sp [-1].local);
- td->ip += 5;
- return TRUE;
- }
- }
-
- g_error ("TODO: interp_transform_call %s:%s", m_class_get_name (target_method->klass), tm);
-}
-
/* Return TRUE if call transformation is finished */
static gboolean
interp_handle_intrinsics (TransformData *td, MonoMethod *target_method, MonoClass *constrained_class, MonoMethodSignature *csignature, gboolean readonly, int *op)
{
const char *tm = target_method->name;
- int type_index = mono_class_get_magic_index (target_method->klass);
gboolean in_corlib = m_class_get_image (target_method->klass) == mono_defaults.corlib;
const char *klass_name_space;
if (m_class_get_nested_in (target_method->klass))
else if (strcmp (tm, "get_Length") == 0)
*op = MINT_STRLEN;
}
- } else if (type_index >= 0) {
- return interp_handle_magic_type_intrinsics (td, target_method, csignature, type_index);
} else if (mono_class_is_subclass_of_internal (target_method->klass, mono_defaults.array_class, FALSE)) {
if (!strcmp (tm, "get_Rank")) {
*op = MINT_ARRAY_RANK;
if (method->wrapper_type != MONO_WRAPPER_NONE)
return FALSE;
- // FIXME Re-enable this
- if (mono_class_get_magic_index (method->klass) >= 0)
- return FALSE;
-
if (td->prof_coverage)
return FALSE;
}
int ret_mt = mint_type (m_class_get_byval_arg (klass));
- if (mono_class_is_magic_int (klass) || mono_class_is_magic_float (klass)) {
- g_assert (csignature->param_count == 1);
-#if SIZEOF_VOID_P == 8
- if (mono_class_is_magic_int (klass) && td->sp [-1].type == STACK_TYPE_I4)
- interp_add_conv (td, td->sp - 1, NULL, stack_type [ret_mt], MINT_CONV_I8_I4);
- else if (mono_class_is_magic_float (klass) && td->sp [-1].type == STACK_TYPE_R4)
- interp_add_conv (td, td->sp - 1, NULL, stack_type [ret_mt], MINT_CONV_R8_R4);
-#endif
- } else if (klass == mono_defaults.int_class && csignature->param_count == 1) {
+ if (klass == mono_defaults.int_class && csignature->param_count == 1) {
#if SIZEOF_VOID_P == 8
if (td->sp [-1].type == STACK_TYPE_I4)
interp_add_conv (td, td->sp - 1, NULL, stack_type [ret_mt], MINT_CONV_I8_I4);
td->sp--;
interp_emit_sfld_access (td, field, field_klass, mt, TRUE, error);
goto_if_nok (error, exit);
- } else if (td->sp [-1].type != STACK_TYPE_O && td->sp [-1].type != STACK_TYPE_MP && (mono_class_is_magic_int (klass) || mono_class_is_magic_float (klass))) {
- // No need to load anything, the value is already on the execution stack
} else if (td->sp [-1].type == STACK_TYPE_VT) {
int size = 0;
/* First we pop the vt object from the stack. Then we push the field */
+++ /dev/null
-/**
- * \file
- * intrinsics for variable sized int/floats
- *
- * Author:
- * Rodrigo Kumpera (kumpera@gmail.com)
- *
- * (C) 2013 Xamarin
- * Licensed under the MIT license. See LICENSE file in the project root for full license information.
- */
-
-#include <config.h>
-#include <stdio.h>
-
-#include "mini.h"
-#include "ir-emit.h"
-#include "glib.h"
-
-
-typedef struct {
- const char *op_name;
- short op_table[4];
-} IntIntrisic;
-
-typedef struct {
- short op_index;
- MonoStackType big_stack_type;
- MonoStackType small_stack_type;
- MonoStackType stack_type;
- short conv_4_to_8;
- short conv_8_to_4;
- short move;
- short inc_op;
- short dec_op;
- short store_op;
- short compare_op;
-} MagicTypeInfo;
-
-#if TARGET_SIZEOF_VOID_P == 8
-#define OP_PT_ADD OP_LADD
-#define OP_PT_SUB OP_LSUB
-#define OP_PT_MUL OP_LMUL
-#define OP_PT_DIV OP_LDIV
-#define OP_PT_REM OP_LREM
-#define OP_PT_NEG OP_LNEG
-#define OP_PT_AND OP_LAND
-#define OP_PT_OR OP_LOR
-#define OP_PT_XOR OP_LXOR
-#define OP_PT_NOT OP_LNOT
-#define OP_PT_SHL OP_LSHL
-#define OP_PT_SHR OP_LSHR
-
-#define OP_PT_DIV_UN OP_LDIV_UN
-#define OP_PT_REM_UN OP_LREM_UN
-#define OP_PT_SHR_UN OP_LSHR_UN
-
-#define OP_PT_ADD_IMM OP_LADD_IMM
-#define OP_PT_SUB_IMM OP_LSUB_IMM
-
-#define OP_PT_STORE_FP_MEMBASE_REG OP_STORER8_MEMBASE_REG
-
-#define OP_PCOMPARE OP_LCOMPARE
-
-#else
-#define OP_PT_ADD OP_IADD
-#define OP_PT_SUB OP_ISUB
-#define OP_PT_MUL OP_IMUL
-#define OP_PT_DIV OP_IDIV
-#define OP_PT_REM OP_IREM
-#define OP_PT_NEG OP_INEG
-#define OP_PT_AND OP_IAND
-#define OP_PT_OR OP_IOR
-#define OP_PT_XOR OP_IXOR
-#define OP_PT_NOT OP_INOT
-#define OP_PT_SHL OP_ISHL
-#define OP_PT_SHR OP_ISHR
-
-#define OP_PT_DIV_UN OP_IDIV_UN
-#define OP_PT_REM_UN OP_IREM_UN
-#define OP_PT_SHR_UN OP_ISHR_UN
-
-#define OP_PT_ADD_IMM OP_IADD_IMM
-#define OP_PT_SUB_IMM OP_ISUB_IMM
-
-#define OP_PT_STORE_FP_MEMBASE_REG OP_STORER4_MEMBASE_REG
-
-#define OP_PCOMPARE OP_ICOMPARE
-
-#endif
-
-gsize
-mini_magic_type_size (MonoCompile *cfg, MonoType *type)
-{
- if (type->type == MONO_TYPE_I4 || type->type == MONO_TYPE_U4)
- return 4;
- else if (type->type == MONO_TYPE_I8 || type->type == MONO_TYPE_U8)
- return 8;
- else if (type->type == MONO_TYPE_R4 && !m_type_is_byref (type) && (!cfg || cfg->r4fp))
- return 4;
- else if (type->type == MONO_TYPE_R8 && !m_type_is_byref (type))
- return 8;
- return TARGET_SIZEOF_VOID_P;
-}
-
-#ifndef DISABLE_JIT
-
-static const IntIntrisic int_binop[] = {
- { "op_Addition", { OP_PT_ADD, OP_PT_ADD, OP_FADD, OP_RADD } },
- { "op_Subtraction", { OP_PT_SUB, OP_PT_SUB, OP_FSUB, OP_RSUB } },
- { "op_Multiply", { OP_PT_MUL, OP_PT_MUL, OP_FMUL, OP_RMUL } },
- { "op_Division", { OP_PT_DIV, OP_PT_DIV_UN, OP_FDIV, OP_RDIV } },
- { "op_Modulus", { OP_PT_REM, OP_PT_REM_UN, OP_FREM, OP_RREM } },
- { "op_BitwiseAnd", { OP_PT_AND, OP_PT_AND } },
- { "op_BitwiseOr", { OP_PT_OR, OP_PT_OR } },
- { "op_ExclusiveOr", { OP_PT_XOR, OP_PT_XOR } },
- { "op_LeftShift", { OP_PT_SHL, OP_PT_SHL } },
- { "op_RightShift", { OP_PT_SHR, OP_PT_SHR_UN } },
-};
-
-static const IntIntrisic int_unnop[] = {
- { "op_UnaryPlus", { OP_MOVE, OP_MOVE, OP_FMOVE, OP_RMOVE } },
- { "op_UnaryNegation", { OP_PT_NEG, OP_PT_NEG, OP_FNEG, OP_RNEG } },
- { "op_OnesComplement", { OP_PT_NOT, OP_PT_NOT, OP_FNOT, OP_RNOT } },
-};
-
-static const IntIntrisic int_cmpop[] = {
- { "op_Inequality", { OP_ICNEQ, OP_ICNEQ, OP_FCNEQ, OP_RCNEQ } },
- { "op_Equality", { OP_ICEQ, OP_ICEQ, OP_FCEQ, OP_RCEQ } },
- { "op_GreaterThan", { OP_ICGT, OP_ICGT_UN, OP_FCGT, OP_RCGT } },
- { "op_GreaterThanOrEqual", { OP_ICGE, OP_ICGE_UN, OP_FCLT_UN, OP_RCLT_UN } },
- { "op_LessThan", { OP_ICLT, OP_ICLT_UN, OP_FCLT, OP_RCLT } },
- { "op_LessThanOrEqual", { OP_ICLE, OP_ICLE_UN, OP_FCGT_UN, OP_RCGT_UN } },
-};
-
-static const MagicTypeInfo type_info[] = {
- //nint
- { 0, STACK_I8, STACK_I4, STACK_PTR, OP_ICONV_TO_I8, OP_LCONV_TO_I4, OP_MOVE, OP_PT_ADD_IMM, OP_PT_SUB_IMM, OP_STORE_MEMBASE_REG, OP_PCOMPARE },
- //nuint
- { 1, STACK_I8, STACK_I4, STACK_PTR, OP_ICONV_TO_U8, OP_LCONV_TO_U4, OP_MOVE, OP_PT_ADD_IMM, OP_PT_SUB_IMM, OP_STORE_MEMBASE_REG, OP_PCOMPARE },
- //nfloat
- { 2, STACK_R8, STACK_R8, STACK_R8, OP_FCONV_TO_R8, OP_FCONV_TO_R4, OP_FMOVE, 0, 0, OP_PT_STORE_FP_MEMBASE_REG, 0 },
-};
-
-static MonoInst*
-emit_narrow (MonoCompile *cfg, const MagicTypeInfo *info, int sreg)
-{
- MonoInst *ins;
-
- MONO_INST_NEW (cfg, ins, info->conv_8_to_4);
- ins->sreg1 = sreg;
- if (info->conv_8_to_4 == OP_FCONV_TO_R4)
- ins->type = cfg->r4_stack_type;
- else
- ins->type = info->small_stack_type;
- ins->dreg = alloc_dreg (cfg, (MonoStackType)ins->type);
- MONO_ADD_INS (cfg->cbb, ins);
- return mono_decompose_opcode (cfg, ins);
-}
-
-static MonoInst*
-emit_widen (MonoCompile *cfg, const MagicTypeInfo *info, int sreg)
-{
- MonoInst *ins;
-
- if (cfg->r4fp && info->conv_4_to_8 == OP_FCONV_TO_R8)
- MONO_INST_NEW (cfg, ins, OP_RCONV_TO_R8);
- else
- MONO_INST_NEW (cfg, ins, info->conv_4_to_8);
- ins->sreg1 = sreg;
- ins->type = info->big_stack_type;
- ins->dreg = alloc_dreg (cfg, info->big_stack_type);
- MONO_ADD_INS (cfg->cbb, ins);
- return mono_decompose_opcode (cfg, ins);
-}
-
-static MonoInst*
-emit_intrinsics (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args, const MagicTypeInfo *info)
-{
- int i = 0;
- const char *name = cmethod->name;
- MonoInst *ins;
- int type_index;
- MonoStackType stack_type;
-
- if (info->op_index == 2 && cfg->r4fp && TARGET_SIZEOF_VOID_P == 4) {
- type_index = 3;
- stack_type = STACK_R4;
- } else {
- type_index = info->op_index;
- stack_type = info->stack_type;
- }
-
- if (!strcmp ("op_Implicit", name) || !strcmp ("op_Explicit", name)) {
- int source_size = mini_magic_type_size (cfg, fsig->params [0]);
- int dest_size = mini_magic_type_size (cfg, fsig->ret);
-
- switch (info->big_stack_type) {
- case STACK_I8:
- if (!mini_magic_is_int_type (fsig->params [0]) || !mini_magic_is_int_type (fsig->ret))
- return NULL;
- break;
- case STACK_R8:
- if (!mini_magic_is_float_type (fsig->params [0]) || !mini_magic_is_float_type (fsig->ret))
- return NULL;
- break;
- default:
- g_assert_not_reached ();
- }
-
- //4 -> 4 or 8 -> 8
- if (source_size == dest_size)
- return args [0];
-
- //4 -> 8
- if (source_size < dest_size)
- return emit_widen (cfg, info, args [0]->dreg);
-
- //8 -> 4
- return emit_narrow (cfg, info, args [0]->dreg);
- }
-
- if (!strcmp (".ctor", name)) {
- gboolean is_ldaddr = args [0]->opcode == OP_LDADDR;
- int arg0 = args [1]->dreg;
- int arg_size = mini_magic_type_size (cfg, fsig->params [0]);
-
- if (arg_size > TARGET_SIZEOF_VOID_P) //8 -> 4
- arg0 = emit_narrow (cfg, info, arg0)->dreg;
- else if (arg_size < TARGET_SIZEOF_VOID_P) //4 -> 8
- arg0 = emit_widen (cfg, info, arg0)->dreg;
-
- if (is_ldaddr) { /*Eliminate LDADDR if it's initing a local var*/
- int dreg = ((MonoInst*)args [0]->inst_p0)->dreg;
- NULLIFY_INS (args [0]);
- EMIT_NEW_UNALU (cfg, ins, info->move, dreg, arg0);
- cfg->has_indirection = TRUE;
- } else {
- EMIT_NEW_STORE_MEMBASE (cfg, ins, info->store_op, args [0]->dreg, 0, arg0);
- }
- return ins;
- }
-
- if (!strcmp ("op_Increment", name) || !strcmp ("op_Decrement", name)) {
- gboolean inc = !strcmp ("op_Increment", name);
- /* FIXME float inc is too complex to bother with*/
- //this is broken with ints too
- // if (!info->inc_op)
- return NULL;
-
- /* We have IR for inc/dec */
- MONO_INST_NEW (cfg, ins, inc ? info->inc_op : info->dec_op);
- ins->dreg = alloc_dreg (cfg, (MonoStackType)info->stack_type);
- ins->sreg1 = args [0]->dreg;
- ins->inst_imm = 1;
- ins->type = info->stack_type;
- MONO_ADD_INS (cfg->cbb, ins);
- return ins;
- }
-
- for (i = 0; i < sizeof (int_binop) / sizeof (IntIntrisic); ++i) {
- if (!strcmp (int_binop [i].op_name, name)) {
- if (!int_binop [i].op_table [info->op_index])
- return NULL;
- g_assert (int_binop [i].op_table [type_index]);
-
- MONO_INST_NEW (cfg, ins, int_binop [i].op_table [type_index]);
- ins->dreg = alloc_dreg (cfg, stack_type);
- ins->sreg1 = args [0]->dreg;
- ins->sreg2 = args [1]->dreg;
- ins->type = stack_type;
- MONO_ADD_INS (cfg->cbb, ins);
- return mono_decompose_opcode (cfg, ins);
- }
- }
-
- for (i = 0; i < sizeof (int_unnop) / sizeof (IntIntrisic); ++i) {
- if (!strcmp (int_unnop [i].op_name, name)) {
- g_assert (int_unnop [i].op_table [type_index]);
-
- MONO_INST_NEW (cfg, ins, int_unnop [i].op_table [type_index]);
- ins->dreg = alloc_dreg (cfg, stack_type);
- ins->sreg1 = args [0]->dreg;
- ins->type = stack_type;
- MONO_ADD_INS (cfg->cbb, ins);
- return ins;
- }
- }
-
- for (i = 0; i < sizeof (int_cmpop) / sizeof (IntIntrisic); ++i) {
- if (!strcmp (int_cmpop [i].op_name, name)) {
- short op_cmp = int_cmpop [i].op_table [type_index];
-
- g_assert (op_cmp);
-
- if (info->compare_op) {
- MONO_INST_NEW (cfg, ins, info->compare_op);
- ins->dreg = -1;
- ins->sreg1 = args [0]->dreg;
- ins->sreg2 = args [1]->dreg;
- MONO_ADD_INS (cfg->cbb, ins);
-
- MONO_INST_NEW (cfg, ins, op_cmp);
- ins->dreg = alloc_preg (cfg);
- ins->type = STACK_I4;
- MONO_ADD_INS (cfg->cbb, ins);
- } else {
- MONO_INST_NEW (cfg, ins, op_cmp);
- guint32 fcmp_dreg = ins->dreg = alloc_ireg (cfg);
- ins->sreg1 = args [0]->dreg;
- ins->sreg2 = args [1]->dreg;
- MONO_ADD_INS (cfg->cbb, ins);
- if (op_cmp == OP_FCLT_UN || op_cmp == OP_FCGT_UN || op_cmp == OP_RCLT_UN || op_cmp == OP_RCGT_UN) {
- /* we have to negate the result of this comparison:
- * - op_GreaterThanOrEqual maps to NOT x OP_FCLT_UN / OP_RCLT_UN
- * - op_LessThanOrEqual maps to NOT x OP_FCGT_UN / OP_RCGT_UN
- *
- * this matches generated bytecode by C# when doing the
- * same operations on float/double. the `_UN` suffix says
- * that if an operand is NaN, the result is true. If
- * OP_FCGE/OP_FCLE is used, it is mapped to instructions
- * on some architectures that don't detect NaN. For
- * example, on arm64 the condition `eq` doesn't respect
- * NaN results of a `fcmp` instruction.
- */
- MONO_INST_NEW (cfg, ins, OP_ICOMPARE_IMM);
- ins->dreg = -1;
- ins->sreg1 = fcmp_dreg;
- ins->inst_imm = 0;
- MONO_ADD_INS (cfg->cbb, ins);
-
- MONO_INST_NEW (cfg, ins, OP_CEQ);
- ins->dreg = alloc_preg (cfg);
- ins->type = STACK_I4;
- MONO_ADD_INS (cfg->cbb, ins);
- }
- }
-
- return ins;
- }
- }
-
- return NULL;
-}
-
-
-MonoInst*
-mono_emit_native_types_intrinsics (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
-{
- if (mono_class_is_magic_int (cmethod->klass)) {
- const char *class_name = m_class_get_name (cmethod->klass);
- if (!strcmp ("nint", class_name))
- return emit_intrinsics (cfg, cmethod, fsig, args, &type_info [0]);
- else
- return emit_intrinsics (cfg, cmethod, fsig, args, &type_info [1]);
- } else if (mono_class_is_magic_float (cmethod->klass))
- return emit_intrinsics (cfg, cmethod, fsig, args, &type_info [2]);
-
- return NULL;
-}
-
-#endif /* !DISABLE_JIT */
-
-static gboolean
-mono_class_is_magic_assembly (MonoClass *klass)
-{
- const char *aname = m_class_get_image (klass)->assembly_name;
- if (!aname)
- return FALSE;
- if (!strcmp ("Xamarin.iOS", aname))
- return TRUE;
- if (!strcmp ("Xamarin.Mac", aname))
- return TRUE;
- if (!strcmp ("Xamarin.WatchOS", aname))
- return TRUE;
- if (!strcmp ("Xamarin.MacCatalyst", aname))
- return TRUE;
- if (!strcmp ("Microsoft.iOS", aname))
- return TRUE;
- if (!strcmp ("Microsoft.macOS", aname))
- return TRUE;
- if (!strcmp ("Microsoft.watchOS", aname))
- return TRUE;
- if (!strcmp ("Microsoft.MacCatalyst", aname))
- return TRUE;
- /* regression test suite */
- if (!strcmp ("builtin-types", aname))
- return TRUE;
- if (!strcmp ("mini_tests", aname))
- return TRUE;
- return FALSE;
-}
-
-gboolean
-mono_class_is_magic_int (MonoClass *klass)
-{
- static MonoClass *magic_nint_class;
- static MonoClass *magic_nuint_class;
-
- if (klass == magic_nint_class)
- return TRUE;
-
- if (klass == magic_nuint_class)
- return TRUE;
-
- if (magic_nint_class && magic_nuint_class)
- return FALSE;
-
- if (!mono_class_is_magic_assembly (klass))
- return FALSE;
-
- if (strcmp ("System", m_class_get_name_space (klass)) != 0)
- return FALSE;
-
- if (strcmp ("nint", m_class_get_name (klass)) == 0) {
- magic_nint_class = klass;
- return TRUE;
- }
-
- if (strcmp ("nuint", m_class_get_name (klass)) == 0){
- magic_nuint_class = klass;
- return TRUE;
- }
- return FALSE;
-}
-
-gboolean
-mono_class_is_magic_float (MonoClass *klass)
-{
- static MonoClass *magic_nfloat_class;
-
- if (klass == magic_nfloat_class)
- return TRUE;
-
- if (magic_nfloat_class)
- return FALSE;
-
- if (!mono_class_is_magic_assembly (klass))
- return FALSE;
-
- if (strcmp ("System", m_class_get_name_space (klass)) != 0 && strcmp ("ObjCRuntime", m_class_get_name_space (klass)) != 0)
- return FALSE;
-
- if (strcmp ("nfloat", m_class_get_name (klass)) == 0) {
- magic_nfloat_class = klass;
-
- /* Assert that we are using the matching assembly */
- MonoClassField *value_field = mono_class_get_field_from_name_full (klass, "v", NULL);
- g_assert (value_field);
- MonoType *t = mono_field_get_type_internal (value_field);
- MonoType *native = mini_native_type_replace_type (m_class_get_byval_arg (klass));
- if (t->type != native->type)
- g_error ("Assembly used for native types '%s' doesn't match this runtime, %s is mapped to %s, expecting %s.\n", m_class_get_image (klass)->name, m_class_get_name (klass), mono_type_full_name (t), mono_type_full_name (native));
- return TRUE;
- }
- return FALSE;
-}
-
-gboolean
-mini_magic_is_int_type (MonoType *t)
-{
- if (t->type != MONO_TYPE_I && t->type != MONO_TYPE_I4 && t->type != MONO_TYPE_I8 && t->type != MONO_TYPE_U4 && t->type != MONO_TYPE_U8 && !mono_class_is_magic_int (mono_class_from_mono_type_internal (t)))
- return FALSE;
- return TRUE;
-}
-
-gboolean
-mini_magic_is_float_type (MonoType *t)
-{
- if (t->type != MONO_TYPE_R4 && t->type != MONO_TYPE_R8 && !mono_class_is_magic_float (mono_class_from_mono_type_internal (t)))
- return FALSE;
- return TRUE;
-}
-
-MonoType*
-mini_native_type_replace_type (MonoType *type)
-{
- MonoClass *klass;
-
- if (type->type != MONO_TYPE_VALUETYPE)
- return type;
- klass = type->data.klass;
-
- if (mono_class_is_magic_int (klass))
- return m_type_is_byref (type) ? mono_class_get_byref_type (mono_defaults.int_class) : mono_get_int_type ();
- if (mono_class_is_magic_float (klass))
-#if TARGET_SIZEOF_VOID_P == 8
- return m_type_is_byref (type) ? mono_class_get_byref_type (mono_defaults.double_class) : m_class_get_byval_arg (mono_defaults.double_class);
-#else
- return m_type_is_byref (type) ? mono_class_get_byref_type (mono_defaults.single_class) : m_class_get_byval_arg (mono_defaults.single_class);
-#endif
- return type;
-}