private static void TestRDTSCP() { if (!CPUID.ISSupported(CPUID.CPUIDFeature.InvariantTSC)) { Console.WriteLine("Invariant TSC is not supported, RDTSC isn't reliable as a wall clock"); } const int LOOP = 1000000; var sw = Stopwatch.StartNew(); var start = Intrinsincs.RDTSCP(); for (var i = 0; i < LOOP; i++) { Intrinsincs.RDTSCP(); } var end = Intrinsincs.RDTSCP(); sw.Stop(); Console.WriteLine("SW: {0}ms", sw.ElapsedMilliseconds); Console.WriteLine("RDTSCP: {0}ms", (end - start) / MHZ); Console.WriteLine("RDTSCP: {0}cycles", (end - start) / LOOP); }
public void BitScanReverseSimple() { int location; Console.WriteLine("Testing BSR"); var test_16u = (ushort)0x0001U; for (var i = 0; i < 16; i++) { location = Intrinsincs.BSR(test_16u); Assert.That(location, Is.EqualTo(i)); test_16u <<= 1; } var test_32u = 0x00000001U; for (var i = 0; i < 32; i++) { location = Intrinsincs.BSR(test_32u); Assert.That(location, Is.EqualTo(i)); test_32u <<= 1; } var test_64u = 0x0000000000000001U; for (var i = 0; i < 32; i++) { location = Intrinsincs.BSR(test_64u); Assert.That(location, Is.EqualTo(i)); test_64u <<= 1; } }
static public void Main(string[] args) { Intrinsincs.Init(); TestCPUID(); TestBSWAP32(); //TestBSWAP64(); TestBSF16(); TestBSF32(); TestBSF64(); TestBSR16(); TestBSR32(); TestBSR64(); if (CPUID.ISSupported(CPUID.CPUIDFeature.POPCNT)) { TestPOPCNT16(); TestPOPCNT32(); TestPOPCNT64(); } else { Console.WriteLine("POPCNT not supported, skipping"); } TestRDTSC(); if (CPUID.ISSupported(CPUID.CPUIDFeature.RDTSCP)) { TestRDTSCP(); } else { Console.WriteLine("RDTSCP not supported, skipping"); } }
private static void TestBSR64() { var test = 0x00000100U; var location = Intrinsincs.BSR(test); Console.WriteLine("BSR32 {0}", location); }
private static void TestBSR16() { var test = (ushort)0x0100U; var location = Intrinsincs.BSR(test); Console.WriteLine("BSR16 {0}", location); }
private static void TestBSWAP32() { var before = 0x01020304U; Console.WriteLine("Before BSWAP32 0x{0:X8}", before); var after = Intrinsincs.BSWAP32U(before); Console.WriteLine("After BSWAP32 0x{0:X8}", after); }
private static void TestBSWAP64() { Debugger.Break(); var before = 0x1122334455667788U; Console.WriteLine("Before BSWAP64 0x{0:X8}", before); var after = Intrinsincs.BSWAP64U(before); Console.WriteLine("After BSWAP64 0x{0:X8}", after); }
private unsafe static void TestCPUID() { uint eax, ebx, ecx, edx; eax = 0x00; ebx = ecx = edx = 0x00; Intrinsincs.CPUID(ref eax, out ebx, out ecx, out edx); var x = stackalloc sbyte[12]; var p = (uint *)x; p[0] = ebx; p[1] = edx; p[2] = ecx; var cpuid0s = new string(x, 0, 12); Console.WriteLine("CPUID: {0}", cpuid0s); }
public void PopulationCount() { int count; Console.WriteLine("Testing POPCNT"); var test_16u = (ushort)0x0F0FU; count = Intrinsincs.POPCNT(test_16u); Assert.That(count, Is.EqualTo(8)); var test_32u = 0x0F0F0F0FU; count = Intrinsincs.POPCNT(test_32u); Assert.That(count, Is.EqualTo(16)); var test_64u = 0x0F0F0F0F0F0F0F0FLU; count = Intrinsincs.POPCNT(test_64u); Assert.That(count, Is.EqualTo(32)); }
public void Setup() { Intrinsincs.Init(); }