testStore.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. function equal(a, b) {
  6. if (a == b)
  7. WScript.Echo("Correct");
  8. else
  9. WScript.Echo(">> Fail!");
  10. }
  11. var bufLanes = 2 * 4; //4 = lane size; Test all alignments.
  12. var bufSize = bufLanes * 4 + 8; //bufLanes * lane Size + 8; Extra for over-alignment test.
  13. var ab = new ArrayBuffer(bufSize);
  14. var buf = new Int32Array(ab);
  15. function checkBuffer(offset, count) {
  16. for (var i = 0; i < count; i++) {
  17. if (buf[offset + i] != i) {
  18. WScript.Echo(">> Fail!" + "offset + i:" + (offset + i) + "buf:" + buf[offset + i]);
  19. return false;
  20. }
  21. }
  22. WScript.Echo("Correct");
  23. return true;
  24. }
  25. function testStore() {
  26. WScript.Echo("Int32x4 store");
  27. var ta = new Int32Array(8);
  28. var value = SIMD.Int32x4(1, 2, 3, 4);
  29. SIMD.Int32x4.store(ta, 0, value);
  30. equal(ta[0], 1);
  31. equal(ta[1], 2);
  32. equal(ta[2], 3);
  33. equal(ta[3], 4);
  34. var a = SIMD.Int32x4(0, 1, 2, 3);
  35. // Test aligned stores.
  36. for (var i = 0; i < 4; i++) {
  37. SIMD.Int32x4.store(buf, i, a);
  38. checkBuffer(i, 4);
  39. }
  40. // Test the 2 over-alignments.
  41. var f64 = new Float64Array(ab);
  42. var stride = 8 / 4; // 4 = lane Size;
  43. for (var i = 0; i < 1; i++) {
  44. SIMD.Int32x4.store(f64, i, a);
  45. checkBuffer(stride * i, 4);
  46. }
  47. // Test the 7 mis-alignments.
  48. var i8 = new Int8Array(ab);
  49. for (var misalignment = 1; misalignment < 8; misalignment++) {
  50. SIMD.Int32x4.store(i8, misalignment, a);
  51. // Shift the buffer down by misalignment.
  52. for (var i = 0; i < i8.length - misalignment; i++)
  53. i8[i] = i8[i + misalignment];
  54. checkBuffer(0, 4);
  55. }
  56. }
  57. function testStore1() {
  58. WScript.Echo("Int32x4 store1");
  59. var ta = new Int32Array(8);
  60. var value = SIMD.Int32x4(1, 2, 3, 4);
  61. SIMD.Int32x4.store1(ta, 0, value);
  62. equal(ta[0], 1);
  63. equal(ta[1], 0);
  64. equal(ta[2], 0);
  65. equal(ta[3], 0);
  66. var a = SIMD.Int32x4(0, 1, 2, 3);
  67. // Test aligned stores.
  68. for (var i = 0; i < 4; i++) {
  69. SIMD.Int32x4.store1(buf, i, a);
  70. checkBuffer(i, 1);
  71. }
  72. // Test the 2 over-alignments.
  73. var f64 = new Float64Array(ab);
  74. var stride = 8 / 4; // 4 = lane Size;
  75. for (var i = 0; i < 1; i++) {
  76. SIMD.Int32x4.store1(f64, i, a);
  77. checkBuffer(stride * i, 1);
  78. }
  79. // Test the 7 mis-alignments.
  80. var i8 = new Int8Array(ab);
  81. for (var misalignment = 1; misalignment < 8; misalignment++) {
  82. SIMD.Int32x4.store1(i8, misalignment, a);
  83. // Shift the buffer down by misalignment.
  84. for (var i = 0; i < i8.length - misalignment; i++)
  85. i8[i] = i8[i + misalignment];
  86. checkBuffer(0, 1);
  87. }
  88. }
  89. function testStore2() {
  90. WScript.Echo("Int32x4 store2");
  91. var ta = new Int32Array(8);
  92. var value = SIMD.Int32x4(1, 2, 3, 4);
  93. SIMD.Int32x4.store2(ta, 0, value);
  94. equal(ta[0], 1);
  95. equal(ta[1], 2);
  96. equal(ta[2], 0);
  97. equal(ta[3], 0);
  98. var a = SIMD.Int32x4(0, 1, 2, 3);
  99. // Test aligned stores.
  100. for (var i = 0; i < 4; i++) {
  101. SIMD.Int32x4.store2(buf, i, a);
  102. checkBuffer(i, 2);
  103. }
  104. // Test the 2 over-alignments.
  105. var f64 = new Float64Array(ab);
  106. var stride = 8 / 4; // 4 = lane Size;
  107. for (var i = 0; i < 1; i++) {
  108. SIMD.Int32x4.store2(f64, i, a);
  109. checkBuffer(stride * i, 2);
  110. }
  111. // Test the 7 mis-alignments.
  112. var i8 = new Int8Array(ab);
  113. for (var misalignment = 1; misalignment < 8; misalignment++) {
  114. SIMD.Int32x4.store2(i8, misalignment, a);
  115. // Shift the buffer down by misalignment.
  116. for (var i = 0; i < i8.length - misalignment; i++)
  117. i8[i] = i8[i + misalignment];
  118. checkBuffer(0, 2);
  119. }
  120. }
  121. function testStore3() {
  122. WScript.Echo("Int32x4 store3");
  123. var ta = new Int32Array(8);
  124. var value = SIMD.Int32x4(1, 2, 3, 4);
  125. SIMD.Int32x4.store3(ta, 0, value);
  126. equal(ta[0], 1);
  127. equal(ta[1], 2);
  128. equal(ta[2], 3);
  129. equal(ta[3], 0);
  130. var a = SIMD.Int32x4(0, 1, 2, 3);
  131. // Test aligned stores.
  132. for (var i = 0; i < 4; i++) {
  133. SIMD.Int32x4.store3(buf, i, a);
  134. checkBuffer(i, 3);
  135. }
  136. // Test the 2 over-alignments.
  137. var f64 = new Float64Array(ab);
  138. var stride = 8 / 4; // 4 = lane Size;
  139. for (var i = 0; i < 1; i++) {
  140. SIMD.Int32x4.store3(f64, i, a);
  141. checkBuffer(stride * i, 3);
  142. }
  143. // Test the 7 mis-alignments.
  144. var i8 = new Int8Array(ab);
  145. for (var misalignment = 1; misalignment < 8; misalignment++) {
  146. SIMD.Int32x4.store3(i8, misalignment, a);
  147. // Shift the buffer down by misalignment.
  148. for (var i = 0; i < i8.length - misalignment; i++)
  149. i8[i] = i8[i + misalignment];
  150. checkBuffer(0, 3);
  151. }
  152. }
  153. testStore();
  154. testStore1();
  155. testStore2();
  156. testStore3();