Make BitOperations public (CoreFX) (dotnet/corefx#35606)
authorGrant <grant@jesanna.com>
Sat, 2 Mar 2019 04:01:53 +0000 (20:01 -0800)
committerJan Kotas <jkotas@microsoft.com>
Sat, 2 Mar 2019 04:01:53 +0000 (20:01 -0800)
* Add ref assembly class

* Add [CLSCompliantAttribute(false)]

* Change name to System.Numerics.BitOperations

* Move ref to System.Runtime.Extensions

Commit migrated from https://github.com/dotnet/corefx/commit/0ae011a57253959b79c952219c5fa16389255b7b

src/libraries/System.Runtime.Extensions/ref/System.Runtime.Extensions.cs
src/libraries/System.Runtime.Extensions/src/ApiCompatBaseline.netcoreappaot.txt
src/libraries/System.Runtime.Extensions/src/ApiCompatBaseline.uapaot.txt
src/libraries/System.Runtime.Extensions/src/System.Runtime.Extensions.csproj
src/libraries/System.Runtime.Extensions/tests/System.Runtime.Extensions.Tests.csproj
src/libraries/System.Runtime.Extensions/tests/System/Numerics/BitOperationsTests.cs [moved from src/libraries/Common/tests/Tests/System/BitOpsTests.cs with 87% similarity]

index a0dd941..02647a3 100644 (file)
@@ -1656,6 +1656,38 @@ namespace System.Net
         public static byte[] UrlEncodeToBytes(byte[] value, int offset, int count) { throw null; }
     }
 }
+namespace System.Numerics
+{
+    public static class BitOperations
+    {
+        [System.CLSCompliantAttribute(false)]
+        public static int LeadingZeroCount(uint value) { throw null; }
+        [System.CLSCompliantAttribute(false)]
+        public static int LeadingZeroCount(ulong value) { throw null; }
+        [System.CLSCompliantAttribute(false)]
+        public static int Log2(uint value) { throw null; }
+        [System.CLSCompliantAttribute(false)]
+        public static int Log2(ulong value) { throw null; }
+        [System.CLSCompliantAttribute(false)]
+        public static int PopCount(uint value) { throw null; }
+        [System.CLSCompliantAttribute(false)]
+        public static int PopCount(ulong value) { throw null; }
+        [System.CLSCompliantAttribute(false)]
+        public static uint RotateLeft(uint value, int bitOffset) { throw null; }
+        [System.CLSCompliantAttribute(false)]
+        public static ulong RotateLeft(ulong value, int bitOffset) { throw null; }
+        [System.CLSCompliantAttribute(false)]
+        public static uint RotateRight(uint value, int bitOffset) { throw null; }
+        [System.CLSCompliantAttribute(false)]
+        public static ulong RotateRight(ulong value, int bitOffset) { throw null; }
+        public static int TrailingZeroCount(int value) { throw null; }
+        public static int TrailingZeroCount(long value) { throw null; }
+        [System.CLSCompliantAttribute(false)]
+        public static int TrailingZeroCount(uint value) { throw null; }
+        [System.CLSCompliantAttribute(false)]
+        public static int TrailingZeroCount(ulong value) { throw null; }
+    }
+}
 namespace System.Reflection
 {
     public partial class AssemblyNameProxy : System.MarshalByRefObject
index d6d14fc..1f13535 100644 (file)
@@ -1,3 +1,4 @@
 MembersMustExist : Member 'System.MidpointRounding System.MidpointRounding.ToNegativeInfinity' does not exist in the implementation but it does exist in the contract.
 MembersMustExist : Member 'System.MidpointRounding System.MidpointRounding.ToPositiveInfinity' does not exist in the implementation but it does exist in the contract.
-MembersMustExist : Member 'System.MidpointRounding System.MidpointRounding.ToZero' does not exist in the implementation but it does exist in the contract.
\ No newline at end of file
+MembersMustExist : Member 'System.MidpointRounding System.MidpointRounding.ToZero' does not exist in the implementation but it does exist in the contract.
+TypesMustExist : Type 'System.Numerics.BitOperations' does not exist in the implementation but it does exist in the contract.
\ No newline at end of file
index d6d14fc..1f13535 100644 (file)
@@ -1,3 +1,4 @@
 MembersMustExist : Member 'System.MidpointRounding System.MidpointRounding.ToNegativeInfinity' does not exist in the implementation but it does exist in the contract.
 MembersMustExist : Member 'System.MidpointRounding System.MidpointRounding.ToPositiveInfinity' does not exist in the implementation but it does exist in the contract.
-MembersMustExist : Member 'System.MidpointRounding System.MidpointRounding.ToZero' does not exist in the implementation but it does exist in the contract.
\ No newline at end of file
+MembersMustExist : Member 'System.MidpointRounding System.MidpointRounding.ToZero' does not exist in the implementation but it does exist in the contract.
+TypesMustExist : Type 'System.Numerics.BitOperations' does not exist in the implementation but it does exist in the contract.
\ No newline at end of file
index a04220f..fa02bcc 100644 (file)
@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
     <ProjectGuid>{845D2B72-D8A4-42E5-9BE9-17639EC4FC1A}</ProjectGuid>
     <AssemblyName>System.Runtime.Extensions</AssemblyName>
@@ -6,7 +6,7 @@
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <IsPartialFacadeAssembly>true</IsPartialFacadeAssembly>
     <IncludeDllSafeSearchPathAttribute>true</IncludeDllSafeSearchPathAttribute>
-    <GenFacadesIgnoreMissingTypes Condition="'$(TargetGroup)'=='uapaot'">true</GenFacadesIgnoreMissingTypes>
+    <GenFacadesIgnoreMissingTypes Condition="'$(TargetsAOT)'=='true' OR '$(TargetGroup)' == 'uap'">true</GenFacadesIgnoreMissingTypes>
     <Configurations>netcoreapp-Unix-Debug;netcoreapp-Unix-Release;netcoreapp-Windows_NT-Debug;netcoreapp-Windows_NT-Release;netcoreappaot-Windows_NT-Debug;netcoreappaot-Windows_NT-Release;uap-Windows_NT-Debug;uap-Windows_NT-Release;uapaot-Windows_NT-Debug;uapaot-Windows_NT-Release</Configurations>
   </PropertyGroup>
   <ItemGroup>
index 873190c..35aadd0 100644 (file)
@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
     <ProjectGuid>{6C314C9B-3D28-4B05-9B4C-B57A00A9B3B9}</ProjectGuid>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@@ -39,6 +39,7 @@
     <Compile Include="System\IO\Path.GetRelativePath.cs" />
     <Compile Include="System\MathTests.netcoreapp.cs" />
     <Compile Include="System\MathF.netcoreapp.cs" />
+    <Compile Include="System\Numerics\BitOperationsTests.cs" />
     <Compile Include="System\StringComparer.netcoreapp.cs" />
     <Compile Include="System\UnloadingAndProcessExitTests.netcoreapp.cs" />
     <Compile Include="System\IO\Path.IsPathFullyQualified.cs" />
@@ -3,16 +3,12 @@
 // See the LICENSE file in the project root for more information.
 
 using System;
+using System.Numerics;
 using Xunit;
 
-namespace Internal.Runtime.CompilerServices
+namespace System.Numerics.Tests
 {
-    // Dummy namespace needed for compilation of BitOps
-}
-
-namespace Tests.System
-{
-    public static class BitOpsTests
+    public static class BitOperationsTests
     {
         [Theory]
         [InlineData(0u, 32)]
@@ -31,7 +27,7 @@ namespace Tests.System
         [InlineData(uint.MaxValue, 0)]
         public static void BitOps_LeadingZeroCount_uint(uint n, int expected)
         {
-            int actual = BitOps.LeadingZeroCount(n);
+            int actual = BitOperations.LeadingZeroCount(n);
             Assert.Equal(expected, actual);
         }
 
@@ -54,7 +50,7 @@ namespace Tests.System
         [InlineData(ulong.MaxValue, 0)]
         public static void BitOps_LeadingZeroCount_ulong(ulong n, int expected)
         {
-            int actual = BitOps.LeadingZeroCount(n);
+            int actual = BitOperations.LeadingZeroCount(n);
             Assert.Equal(expected, actual);
         }
 
@@ -76,7 +72,7 @@ namespace Tests.System
         [InlineData(uint.MaxValue, 0)]
         public static void BitOps_TrailingZeroCount_uint(uint n, int expected)
         {
-            int actual = BitOps.TrailingZeroCount(n);
+            int actual = BitOperations.TrailingZeroCount(n);
             Assert.Equal(expected, actual);
         }
 
@@ -98,7 +94,7 @@ namespace Tests.System
         [InlineData(int.MaxValue, 0)]
         public static void BitOps_TrailingZeroCount_int(int n, int expected)
         {
-            int actual = BitOps.TrailingZeroCount(n);
+            int actual = BitOperations.TrailingZeroCount(n);
             Assert.Equal(expected, actual);
         }
 
@@ -121,7 +117,7 @@ namespace Tests.System
         [InlineData(ulong.MaxValue, 0)]
         public static void BitOps_TrailingZeroCount_ulong(ulong n, int expected)
         {
-            int actual = BitOps.TrailingZeroCount(n);
+            int actual = BitOperations.TrailingZeroCount(n);
             Assert.Equal(expected, actual);
         }
 
@@ -144,7 +140,7 @@ namespace Tests.System
         [InlineData(long.MaxValue, 0)]
         public static void BitOps_TrailingZeroCount_long(long n, int expected)
         {
-            int actual = BitOps.TrailingZeroCount(n);
+            int actual = BitOperations.TrailingZeroCount(n);
             Assert.Equal(expected, actual);
         }
 
@@ -164,7 +160,7 @@ namespace Tests.System
         [InlineData(uint.MaxValue, 32 - 1)]
         public static void BitOps_Log2_uint(uint n, int expected)
         {
-            int actual = BitOps.Log2(n);
+            int actual = BitOperations.Log2(n);
             Assert.Equal(expected, actual);
         }
 
@@ -185,7 +181,7 @@ namespace Tests.System
         [InlineData(ulong.MaxValue, 64 - 1)]
         public static void BitOps_Log2_ulong(ulong n, int expected)
         {
-            int actual = BitOps.Log2(n);
+            int actual = BitOperations.Log2(n);
             Assert.Equal(expected, actual);
         }
 
@@ -219,7 +215,7 @@ namespace Tests.System
         [InlineData(uint.MaxValue, 32)] // 4294967295
         public static void BitOps_PopCount_uint(uint n, int expected)
         {
-            int actual = BitOps.PopCount(n);
+            int actual = BitOperations.PopCount(n);
             Assert.Equal(expected, actual);
         }
 
@@ -253,7 +249,7 @@ namespace Tests.System
         [InlineData(ulong.MaxValue, 64)]
         public static void BitOps_PopCount_ulong(ulong n, int expected)
         {
-            int actual = BitOps.PopCount(n);
+            int actual = BitOperations.PopCount(n);
             Assert.Equal(expected, actual);
         }
 
@@ -269,18 +265,18 @@ namespace Tests.System
         [InlineData(0b01010101_11111111_01010101_01010101u, int.MinValue, 0b01010101_11111111_01010101_01010101u)] // % 32 = 0
         public static void BitOps_RotateLeft_uint(uint n, int offset, uint expected)
         {
-            Assert.Equal(expected, BitOps.RotateLeft(n, offset));
+            Assert.Equal(expected, BitOperations.RotateLeft(n, offset));
         }
 
         [Fact]
         public static void BitOps_RotateLeft_ulong()
         {
             ulong value = 0b01010101_01010101_01010101_01010101_01010101_01010101_01010101_01010101ul;
-            Assert.Equal(0b10101010_10101010_10101010_10101010_10101010_10101010_10101010_10101010ul, BitOps.RotateLeft(value, 1));
-            Assert.Equal(0b01010101_01010101_01010101_01010101_01010101_01010101_01010101_01010101ul, BitOps.RotateLeft(value, 2));
-            Assert.Equal(0b10101010_10101010_10101010_10101010_10101010_10101010_10101010_10101010ul, BitOps.RotateLeft(value, 3));
-            Assert.Equal(value, BitOps.RotateLeft(value, int.MinValue)); // % 64 = 0
-            Assert.Equal(BitOps.RotateLeft(value, 63), BitOps.RotateLeft(value, int.MaxValue)); // % 64 = 63
+            Assert.Equal(0b10101010_10101010_10101010_10101010_10101010_10101010_10101010_10101010ul, BitOperations.RotateLeft(value, 1));
+            Assert.Equal(0b01010101_01010101_01010101_01010101_01010101_01010101_01010101_01010101ul, BitOperations.RotateLeft(value, 2));
+            Assert.Equal(0b10101010_10101010_10101010_10101010_10101010_10101010_10101010_10101010ul, BitOperations.RotateLeft(value, 3));
+            Assert.Equal(value, BitOperations.RotateLeft(value, int.MinValue)); // % 64 = 0
+            Assert.Equal(BitOperations.RotateLeft(value, 63), BitOperations.RotateLeft(value, int.MaxValue)); // % 64 = 63
         }
 
         [Theory]
@@ -295,18 +291,18 @@ namespace Tests.System
         [InlineData(0b01010101_11111111_01010101_01010101u, int.MinValue, 0b01010101_11111111_01010101_01010101u)] // % 32 = 0
         public static void BitOps_RotateRight_uint(uint n, int offset, uint expected)
         {
-            Assert.Equal(expected, BitOps.RotateRight(n, offset));
+            Assert.Equal(expected, BitOperations.RotateRight(n, offset));
         }
 
         [Fact]
         public static void BitOps_RotateRight_ulong()
         {
             ulong value = 0b01010101_01010101_01010101_01010101_01010101_01010101_01010101_01010101ul;
-            Assert.Equal(0b10101010_10101010_10101010_10101010_10101010_10101010_10101010_10101010ul, BitOps.RotateRight(value, 1));
-            Assert.Equal(0b01010101_01010101_01010101_01010101_01010101_01010101_01010101_01010101ul, BitOps.RotateRight(value, 2));
-            Assert.Equal(0b10101010_10101010_10101010_10101010_10101010_10101010_10101010_10101010ul, BitOps.RotateRight(value, 3));
-            Assert.Equal(value, BitOps.RotateRight(value, int.MinValue)); // % 64 = 0
-            Assert.Equal(BitOps.RotateLeft(value, 63), BitOps.RotateRight(value, int.MaxValue)); // % 64 = 63
+            Assert.Equal(0b10101010_10101010_10101010_10101010_10101010_10101010_10101010_10101010ul, BitOperations.RotateRight(value, 1));
+            Assert.Equal(0b01010101_01010101_01010101_01010101_01010101_01010101_01010101_01010101ul, BitOperations.RotateRight(value, 2));
+            Assert.Equal(0b10101010_10101010_10101010_10101010_10101010_10101010_10101010_10101010ul, BitOperations.RotateRight(value, 3));
+            Assert.Equal(value, BitOperations.RotateRight(value, int.MinValue)); // % 64 = 0
+            Assert.Equal(BitOperations.RotateLeft(value, 63), BitOperations.RotateRight(value, int.MaxValue)); // % 64 = 63
         }
     }
 }