CpuTestAluBinary32.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #define AluBinary32
  2. using ARMeilleure.State;
  3. using NUnit.Framework;
  4. using System;
  5. namespace Ryujinx.Tests.Cpu
  6. {
  7. [Category("AluBinary32")]
  8. public sealed class CpuTestAluBinary32 : CpuTest32
  9. {
  10. #if AluBinary32
  11. public struct CrcTest32
  12. {
  13. public uint Crc;
  14. public uint Value;
  15. public bool C;
  16. public uint[] Results; // One result for each CRC variant (8, 16, 32)
  17. public CrcTest32(uint crc, uint value, bool c, params uint[] results)
  18. {
  19. Crc = crc;
  20. Value = value;
  21. C = c;
  22. Results = results;
  23. }
  24. }
  25. #region "ValueSource (CRC32/CRC32C)"
  26. private static CrcTest32[] _CRC32_Test_Values_()
  27. {
  28. // Created with http://www.sunshine2k.de/coding/javascript/crc/crc_js.html, with:
  29. // - non-reflected polynomials
  30. // - input reflected, result reflected
  31. // - bytes in order of increasing significance
  32. // - xor 0
  33. return new CrcTest32[]
  34. {
  35. new CrcTest32(0x00000000u, 0x00_00_00_00u, false, 0x00000000, 0x00000000, 0x00000000),
  36. new CrcTest32(0x00000000u, 0x7f_ff_ff_ffu, false, 0x2d02ef8d, 0xbe2612ff, 0x3303a3c3),
  37. new CrcTest32(0x00000000u, 0x80_00_00_00u, false, 0x00000000, 0x00000000, 0xedb88320),
  38. new CrcTest32(0x00000000u, 0xff_ff_ff_ffu, false, 0x2d02ef8d, 0xbe2612ff, 0xdebb20e3),
  39. new CrcTest32(0x00000000u, 0x9d_cb_12_f0u, false, 0xbdbdf21c, 0xe70590f5, 0x3f7480c5),
  40. new CrcTest32(0xffffffffu, 0x00_00_00_00u, false, 0x2dfd1072, 0xbe26ed00, 0xdebb20e3),
  41. new CrcTest32(0xffffffffu, 0x7f_ff_ff_ffu, false, 0x00ffffff, 0x0000ffff, 0xedb88320),
  42. new CrcTest32(0xffffffffu, 0x80_00_00_00u, false, 0x2dfd1072, 0xbe26ed00, 0x3303a3c3),
  43. new CrcTest32(0xffffffffu, 0xff_ff_ff_ffu, false, 0x00ffffff, 0x0000ffff, 0x00000000),
  44. new CrcTest32(0xffffffffu, 0x9d_cb_12_f0u, false, 0x9040e26e, 0x59237df5, 0xe1cfa026),
  45. new CrcTest32(0x00000000u, 0x00_00_00_00u, true, 0x00000000, 0x00000000, 0x00000000),
  46. new CrcTest32(0x00000000u, 0x7f_ff_ff_ffu, true, 0xad7d5351, 0x0e9e77d2, 0x356e8f40),
  47. new CrcTest32(0x00000000u, 0x80_00_00_00u, true, 0x00000000, 0x00000000, 0x82f63b78),
  48. new CrcTest32(0x00000000u, 0xff_ff_ff_ffu, true, 0xad7d5351, 0x0e9e77d2, 0xb798b438),
  49. new CrcTest32(0x00000000u, 0x9d_cb_12_f0u, true, 0xf36e6f75, 0xb5ff99e6, 0x782dfbf1),
  50. new CrcTest32(0xffffffffu, 0x00_00_00_00u, true, 0xad82acae, 0x0e9e882d, 0xb798b438),
  51. new CrcTest32(0xffffffffu, 0x7f_ff_ff_ffu, true, 0x00ffffff, 0x0000ffff, 0x82f63b78),
  52. new CrcTest32(0xffffffffu, 0x80_00_00_00u, true, 0xad82acae, 0x0e9e882d, 0x356e8f40),
  53. new CrcTest32(0xffffffffu, 0xff_ff_ff_ffu, true, 0x00ffffff, 0x0000ffff, 0x00000000),
  54. new CrcTest32(0xffffffffu, 0x9d_cb_12_f0u, true, 0x5eecc3db, 0xbb6111cb, 0xcfb54fc9)
  55. };
  56. }
  57. #endregion
  58. [Test, Combinatorial]
  59. public void Crc32_Crc32c_b_h_w([Values(0u)] uint rd,
  60. [Values(1u)] uint rn,
  61. [Values(2u)] uint rm,
  62. [Range(0u, 2u)] uint size,
  63. [ValueSource("_CRC32_Test_Values_")] CrcTest32 test)
  64. {
  65. // Unicorn does not yet support 32bit crc instructions, so test against a known table of results/values.
  66. uint opcode = 0xe1000040; // CRC32B R0, R0, R0
  67. opcode |= ((rm & 15) << 0) | ((rd & 15) << 12) | ((rn & 15) << 16);
  68. opcode |= size << 21;
  69. if (test.C)
  70. {
  71. opcode |= 1 << 9;
  72. }
  73. uint sp = TestContext.CurrentContext.Random.NextUInt();
  74. SingleOpcode(opcode, r1: test.Crc, r2: test.Value, sp: sp, runUnicorn: false);
  75. ExecutionContext context = GetContext();
  76. ulong result = context.GetX((int)rd);
  77. Assert.That(result == test.Results[size]);
  78. }
  79. #endif
  80. }
  81. }