testLoadStore-2.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation and contributors. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. this.WScript.LoadScriptFile("..\\UnitTestFramework\\SimdJsHelpers.js");
  6. function asmModule(stdlib, imports, buffer) {
  7. "use asm";
  8. var i4 = stdlib.SIMD.Int32x4;
  9. var i4check = i4.check;
  10. var i4splat = i4.splat;
  11. var i4fromFloat32x4 = i4.fromFloat32x4;
  12. var i4fromFloat32x4Bits = i4.fromFloat32x4Bits;
  13. //var i4abs = i4.abs;
  14. var i4neg = i4.neg;
  15. var i4add = i4.add;
  16. var i4sub = i4.sub;
  17. var i4mul = i4.mul;
  18. var i4swizzle = i4.swizzle;
  19. var i4shuffle = i4.shuffle;
  20. var i4lessThan = i4.lessThan;
  21. var i4equal = i4.equal;
  22. var i4greaterThan = i4.greaterThan;
  23. var i4select = i4.select;
  24. var i4and = i4.and;
  25. var i4or = i4.or;
  26. var i4xor = i4.xor;
  27. var i4not = i4.not;
  28. var i4load = i4.load;
  29. var i4load1 = i4.load1;
  30. var i4load2 = i4.load2;
  31. var i4load3 = i4.load3;
  32. var i4store = i4.store
  33. var i4store1 = i4.store1;
  34. var i4store2 = i4.store2;
  35. var i4store3 = i4.store3;
  36. //var i4shiftLeftByScalar = i4.shiftLeftByScalar;
  37. //var i4shiftRightByScalar = i4.shiftRightByScalar;
  38. //var i4shiftRightArithmeticByScalar = i4.shiftRightArithmeticByScalar;
  39. var f4 = stdlib.SIMD.Float32x4;
  40. var f4check = f4.check;
  41. var f4splat = f4.splat;
  42. var f4fromInt32x4 = f4.fromInt32x4;
  43. var f4fromInt32x4Bits = f4.fromInt32x4Bits;
  44. var f4abs = f4.abs;
  45. var f4neg = f4.neg;
  46. var f4add = f4.add;
  47. var f4sub = f4.sub;
  48. var f4mul = f4.mul;
  49. var f4div = f4.div;
  50. var f4min = f4.min;
  51. var f4max = f4.max;
  52. var f4sqrt = f4.sqrt;
  53. var f4swizzle = f4.swizzle;
  54. var f4shuffle = f4.shuffle;
  55. var f4lessThan = f4.lessThan;
  56. var f4lessThanOrEqual = f4.lessThanOrEqual;
  57. var f4equal = f4.equal;
  58. var f4notEqual = f4.notEqual;
  59. var f4greaterThan = f4.greaterThan;
  60. var f4greaterThanOrEqual = f4.greaterThanOrEqual;
  61. var f4select = f4.select;
  62. var f4load = f4.load;
  63. var f4load1 = f4.load1;
  64. var f4load2 = f4.load2;
  65. var f4load3 = f4.load3;
  66. var f4store = f4.store;
  67. var f4store1 = f4.store1;
  68. var f4store2 = f4.store2;
  69. var f4store3 = f4.store3;
  70. var fround = stdlib.Math.fround;
  71. var globImportF4 = f4check(imports.g1); // global var import
  72. var globImportI4 = i4check(imports.g2); // global var import
  73. var g1 = f4(-5033.2,-3401.0,665.34,32234.1); // global var initialized
  74. var g2 = i4(1065353216, -1073741824, -1077936128, 1082130432); // global var initialized
  75. var gval = 1234;
  76. var gval2 = 1234.0;
  77. var loopCOUNT = 3;
  78. var Int8Heap = new stdlib.Int8Array (buffer);
  79. var Uint8Heap = new stdlib.Uint8Array (buffer);
  80. var Int16Heap = new stdlib.Int16Array(buffer);
  81. var Uint16Heap = new stdlib.Uint16Array(buffer);
  82. var Int32Heap = new stdlib.Int32Array(buffer);
  83. var Uint32Heap = new stdlib.Uint32Array(buffer);
  84. var Float32Heap = new stdlib.Float32Array(buffer);
  85. function storeF32(value, idx)
  86. {
  87. value= f4check(value);
  88. idx = idx|0;
  89. idx = idx<<2;
  90. f4store(Float32Heap, (idx>>2), value);
  91. }
  92. function loadF32(idx)
  93. {
  94. idx = idx|0;
  95. idx = idx<<2;
  96. return f4load(Float32Heap, (idx>>2));
  97. }
  98. function storeUI32(value, idx)
  99. { value= f4check(value); idx = idx|0; idx = idx<<2;
  100. f4store(Uint32Heap, (idx>>2), value);}
  101. function loadUI32(idx)
  102. { idx = idx|0; idx = idx<<2; return f4load(Uint32Heap, (idx>>2)); }
  103. function storeI32(value, idx)
  104. { value= f4check(value); idx = idx|0; idx = idx<<2;
  105. f4store(Int32Heap, (idx>>2), value);}
  106. function loadI32(idx)
  107. { idx = idx|0; idx = idx<<2; return f4load(Int32Heap, (idx>>2)); }
  108. function storeI16(value, idx)
  109. { value= f4check(value); idx = idx|0; idx = idx<<1;
  110. f4store(Int16Heap, (idx>>1), value);}
  111. function loadI16(idx)
  112. { idx = idx|0; idx = idx<<1; return f4load(Int16Heap, (idx>>1)); }
  113. function storeUI16(value, idx)
  114. { value= f4check(value); idx = idx|0; idx = idx<<1;
  115. f4store(Uint16Heap, (idx>>1), value);}
  116. function loadUI16(idx)
  117. { idx = idx|0; idx = idx<<1; return f4load(Uint16Heap, (idx>>1)); }
  118. function storeI8(value, idx)
  119. { value= f4check(value); idx = idx|0; idx = idx<<0;
  120. f4store(Int8Heap, (idx>>0), value);}
  121. function loadI8(idx)
  122. { idx = idx|0; idx = idx<<0; return f4load(Int8Heap, (idx>>0)); }
  123. function storeUI8(value, idx)
  124. { value= f4check(value); idx = idx|0; idx = idx<<0;
  125. f4store(Uint8Heap, (idx>>0), value);}
  126. function loadUI8(idx)
  127. { idx = idx|0; idx = idx<<0; return f4load(Uint8Heap, (idx>>0)); }
  128. function loadStoreIndex1()
  129. {
  130. f4store(Float32Heap, 0, f4(-1.0,-2.0,3.1,-4.0));
  131. return f4load(Float32Heap, 0);
  132. }
  133. function store_1(functionPicker) //Function picker to pick store1/store2/store3/store
  134. {
  135. functionPicker = functionPicker|0;
  136. var v0 = f4(0.0,0.0,0.0,0.0);
  137. var loopIndex = 0, idx = 0, end = 256;
  138. while((loopIndex|0) < (loopCOUNT|0))
  139. {
  140. idx = 0;
  141. v0 = f4(5.1,-12.3,-0.0,0.0);
  142. for(idx = idx << 2; (idx|0) < (end|0 << 2); idx = (idx + 16)|0)
  143. {
  144. switch(functionPicker|0)
  145. {
  146. case 5:
  147. f4store(Float32Heap, idx>>2, v0);
  148. break;
  149. case 6:
  150. f4store1(Float32Heap, idx>>2, v0);
  151. break;
  152. case 7:
  153. f4store2(Float32Heap, idx>>2, v0);
  154. break;
  155. case 8:
  156. f4store3(Float32Heap, idx>>2, v0);
  157. break;
  158. default:
  159. break;
  160. }
  161. v0 = f4add(v0, f4(1.0,1.0,1.0,1.0));
  162. }
  163. loopIndex = (loopIndex + 1)|0;
  164. }
  165. return f4load(Float32Heap, 0);
  166. }
  167. function store_2(functionPicker)
  168. {
  169. functionPicker = functionPicker|0;
  170. var v0 = f4(0.0,0.0,0.0,0.0);
  171. var loopIndex = 0, idx = 0, end = 256;
  172. for (loopIndex = 0; (loopIndex | 0) < (loopCOUNT | 0) ; loopIndex = (loopIndex + 1) | 0)
  173. {
  174. idx = 0;
  175. v0 = f4(0.0,0.0,0.0,0.0);
  176. for(idx = idx << 2; (idx|0) < (end|0 << 2); idx = (idx + 16)|0)
  177. {
  178. switch(functionPicker|0)
  179. {
  180. case 5:
  181. f4store(Float32Heap, idx>>2, v0);
  182. break;
  183. case 6:
  184. f4store1(Float32Heap, idx>>2, v0);
  185. break;
  186. case 7:
  187. f4store2(Float32Heap, idx>>2, v0);
  188. break;
  189. case 8:
  190. f4store3(Float32Heap, idx>>2, v0);
  191. break;
  192. default:
  193. break;
  194. }
  195. v0 = f4add(v0, f4(1.0,1.0,1.0,1.0));
  196. }
  197. }
  198. return f4load(Float32Heap, 8);
  199. }
  200. function store_3(functionPicker)
  201. {
  202. functionPicker = functionPicker|0;
  203. var v0 = f4(0.0,0.0,0.0,0.0);
  204. var loopIndex = 0, idx = 0, end = 256;
  205. loopIndex = loopCOUNT | 0;
  206. do {
  207. idx = 0;
  208. v0 = f4(0.0,0.0,0.0,0.0);
  209. for(idx = idx << 2; (idx|0) < (end|0 << 2); idx = (idx + 16)|0)
  210. {
  211. switch(functionPicker|0)
  212. {
  213. case 5:
  214. f4store(Float32Heap, idx>>2, v0);
  215. break;
  216. case 6:
  217. f4store1(Float32Heap, idx>>2, v0);
  218. break;
  219. case 7:
  220. f4store2(Float32Heap, idx>>2, v0);
  221. break;
  222. case 8:
  223. f4store3(Float32Heap, idx>>2, v0);
  224. break;
  225. default:
  226. break;
  227. }
  228. v0 = f4add(v0, f4(1.0,1.0,1.0,1.0));
  229. }
  230. loopIndex = (loopIndex - 1) | 0;
  231. }
  232. while ( (loopIndex | 0) > 0);
  233. return f4load(Float32Heap, 8);
  234. }
  235. function store_1_Int8(length)
  236. {
  237. length = length|0;
  238. var v0 = f4(0.0,0.0,0.0,0.0);
  239. var loopIndex = 0, idx = 0, end = 0;
  240. end = (length * 4)|0;
  241. while((loopIndex|0) < (loopCOUNT|0))
  242. {
  243. idx = 0;
  244. v0 = f4(0.0,0.0,0.0,0.0);
  245. for(idx = idx << 0; (idx|0) < (end|0 << 0); idx = (idx + 16)|0)
  246. {
  247. f4store(Int8Heap, idx>>0, v0);
  248. v0 = f4add(v0, f4(1.0,1.0,1.0,1.0));
  249. }
  250. loopIndex = (loopIndex + 1)|0;
  251. }
  252. //Expects the heap to be: 0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3...15,15,15,15,0,0,0,0...
  253. return f4load(Float32Heap, 2);
  254. }
  255. function store_1_Uint8(length)
  256. {
  257. length = length|0;
  258. var v0 = f4(0.0,0.0,0.0,0.0);
  259. var loopIndex = 0, idx = 0, end = 0;
  260. end = (length * 4)|0;
  261. while((loopIndex|0) < (loopCOUNT|0))
  262. {
  263. idx = 0;
  264. v0 = f4(0.0,0.0,0.0,0.0);
  265. for(idx = idx << 0; (idx|0) < (end|0 << 0); idx = (idx + 16)|0)
  266. {
  267. f4store(Uint8Heap, idx>>0, v0);
  268. v0 = f4add(v0, f4(1.0,1.0,1.0,1.0));
  269. }
  270. loopIndex = (loopIndex + 1)|0;
  271. }
  272. //Expects the heap to be: 0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3...15,15,15,15,0,0,0,0...
  273. return f4load(Float32Heap, 2);
  274. }
  275. function store_1_Int16(length)
  276. {
  277. length = length|0;
  278. var v0 = f4(0.0,0.0,0.0,0.0);
  279. var loopIndex = 0, idx = 0, end = 0;
  280. end = (length * 4)|0;
  281. while((loopIndex|0) < (loopCOUNT|0))
  282. {
  283. idx = 0;
  284. v0 = f4(0.0,0.0,0.0,0.0);
  285. for(idx = idx << 1; (idx|0) < (end|0 << 1); idx = (idx + 16)|0)
  286. {
  287. f4store(Int16Heap, idx>>1, v0);
  288. v0 = f4add(v0, f4(1.0,1.0,1.0,1.0));
  289. }
  290. loopIndex = (loopIndex + 1)|0;
  291. }
  292. //Expects the heap to be: 0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3...15,15,15,15,0,0,0,0...
  293. return f4load(Float32Heap, 2);
  294. }
  295. function store_1_Uint16(length)
  296. {
  297. length = length|0;
  298. var v0 = f4(0.0,0.0,0.0,0.0);
  299. var loopIndex = 0, idx = 0, end = 0;
  300. end = (length * 4)|0;
  301. while((loopIndex|0) < (loopCOUNT|0))
  302. {
  303. idx = 0;
  304. v0 = f4(0.0,0.0,0.0,0.0);
  305. for(idx = idx << 1; (idx|0) < (end|0 << 1); idx = (idx + 16)|0)
  306. {
  307. f4store(Uint16Heap, idx>>1, v0);
  308. v0 = f4add(v0, f4(1.0,1.0,1.0,1.0));
  309. }
  310. loopIndex = (loopIndex + 1)|0;
  311. }
  312. //Expects the heap to be: 0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3...15,15,15,15,0,0,0,0...
  313. return f4load(Float32Heap, 2);
  314. }
  315. function store_1_Int32(length)
  316. {
  317. length = length|0;
  318. var v0 = f4(0.0,0.0,0.0,0.0);
  319. var loopIndex = 0, idx = 0, end = 0;
  320. end = (length * 4)|0;
  321. while((loopIndex|0) < (loopCOUNT|0))
  322. {
  323. idx = 0;
  324. v0 = f4(0.0,0.0,0.0,0.0);
  325. for(idx = idx << 2; (idx|0) < (end|0 << 2); idx = (idx + 16)|0)
  326. {
  327. f4store(Int32Heap, idx>>2, v0);
  328. v0 = f4add(v0, f4(1.0,1.0,1.0,1.0));
  329. }
  330. loopIndex = (loopIndex + 1)|0;
  331. }
  332. //Expects the heap to be: 0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3...15,15,15,15,0,0,0,0...
  333. return f4load(Float32Heap, 2);
  334. }
  335. function store_1_Uint32(length)
  336. {
  337. length = length|0;
  338. var v0 = f4(0.0,0.0,0.0,0.0);
  339. var loopIndex = 0, idx = 0, end = 0;
  340. end = (length * 4)|0;
  341. while((loopIndex|0) < (loopCOUNT|0))
  342. {
  343. idx = 0;
  344. v0 = f4(0.0,0.0,0.0,0.0);
  345. for(idx = idx << 2; (idx|0) < (end|0 << 2); idx = (idx + 16)|0)
  346. {
  347. f4store(Uint32Heap, idx>>2, v0);
  348. v0 = f4add(v0, f4(1.0,1.0,1.0,1.0));
  349. }
  350. loopIndex = (loopIndex + 1)|0;
  351. }
  352. //Expects the heap to be: 0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3...15,15,15,15,0,0,0,0...
  353. return f4load(Float32Heap, 2);
  354. }
  355. ////////////////////////////Load////////////////////////////
  356. function load_1(functionPicker)
  357. {
  358. //length = length|0;
  359. functionPicker = functionPicker|0;
  360. var idx=0,end=16;//(length-4)|0;;
  361. var loopIndex = 0;
  362. var v = f4(0.0,0.0,0.0,0.0);
  363. while ( (loopIndex|0) < (loopCOUNT|0)) {
  364. idx=0;
  365. for(idx = idx<<2; (idx|0) <= (end<<2); idx = (idx + 1)|0)
  366. {
  367. switch(functionPicker|0)
  368. {
  369. case 1:
  370. v = f4load(Float32Heap, idx>>2);
  371. break;
  372. case 2:
  373. v = f4load1(Float32Heap, idx>>2);
  374. break;
  375. case 3:
  376. v = f4load2(Float32Heap, idx>>2);
  377. break;
  378. case 4:
  379. v = f4load3(Float32Heap, idx>>2);
  380. break;
  381. default:
  382. break;
  383. }
  384. }
  385. loopIndex = (loopIndex + 1) | 0;
  386. }
  387. return v;
  388. }
  389. function load_2(functionPicker)
  390. {
  391. //length = length|0;
  392. functionPicker = functionPicker|0;
  393. var idx=0,end=16;//(length-4)|0;;
  394. var loopIndex = 0;
  395. var v = f4(0.0,0.0,0.0,0.0);
  396. for (loopIndex = 0; (loopIndex | 0) < (loopCOUNT | 0) ; loopIndex = (loopIndex + 1) | 0)
  397. {
  398. idx=0;
  399. for(idx = idx<<2; (idx|0) <= (end<<2); idx = (idx + 1)|0)
  400. {
  401. switch(functionPicker|0)
  402. {
  403. case 1:
  404. v = f4load(Float32Heap, idx>>2);
  405. break;
  406. case 2:
  407. v = f4load1(Float32Heap, idx>>2);
  408. break;
  409. case 3:
  410. v = f4load2(Float32Heap, idx>>2);
  411. break;
  412. case 4:
  413. v = f4load3(Float32Heap, idx>>2);
  414. break;
  415. default:
  416. break;
  417. }
  418. }
  419. }
  420. return v;
  421. }
  422. function load_3(functionPicker)
  423. {
  424. //length = length|0;
  425. functionPicker = functionPicker|0;
  426. var idx=0,end=16;//(length-4)|0;;
  427. var loopIndex = 0;
  428. var v = f4(0.0,0.0,0.0,0.0);
  429. loopIndex = loopCOUNT | 0;
  430. do {
  431. idx = 0;
  432. for(idx = idx<<2; (idx|0) <= (end<<2); idx = (idx + 1)|0)
  433. {
  434. switch(functionPicker|0)
  435. {
  436. case 1:
  437. v = f4load(Float32Heap, idx>>2);
  438. break;
  439. case 2:
  440. v = f4load1(Float32Heap, idx>>2);
  441. break;
  442. case 3:
  443. v = f4load2(Float32Heap, idx>>2);
  444. break;
  445. case 4:
  446. v = f4load3(Float32Heap, idx>>2);
  447. break;
  448. default:
  449. break;
  450. }
  451. }
  452. loopIndex = (loopIndex - 1) | 0;
  453. }
  454. while ( (loopIndex | 0) > 0);
  455. return v;
  456. }
  457. function load_1_Int8(length)
  458. {
  459. length = length|0;
  460. var idx=0,end=0;
  461. var loopIndex = 0;
  462. var v = f4(0.0,0.0,0.0,0.0);
  463. end = (((length * 4)|0) - 16)|0;
  464. while ( (loopIndex|0) < (loopCOUNT|0)) {
  465. idx=0;
  466. for(idx = idx<<0; (idx|0) <= (end<<0); idx = (idx + 1)|0)
  467. {
  468. v = f4load(Int8Heap, idx>>0);
  469. }
  470. loopIndex = (loopIndex + 1) | 0;
  471. }
  472. return v;
  473. }
  474. function load_1_Uint8(length)
  475. {
  476. length = length|0;
  477. var idx=0,end=0;
  478. var loopIndex = 0;
  479. var v = f4(0.0,0.0,0.0,0.0);
  480. end = (((length * 4)|0) - 16)|0;
  481. while ( (loopIndex|0) < (loopCOUNT|0)) {
  482. idx=0;
  483. for(idx = idx<<0; (idx|0) <= (end<<0); idx = (idx + 1)|0)
  484. {
  485. v = f4load(Uint8Heap, idx>>0);
  486. }
  487. loopIndex = (loopIndex + 1) | 0;
  488. }
  489. return v;
  490. }
  491. function load_1_Int16(length)
  492. {
  493. length = length|0;
  494. var idx=0,end=0;
  495. var loopIndex = 0;
  496. var v = f4(0.0,0.0,0.0,0.0);
  497. end = (((length * 2)|0) - 8)|0;
  498. while ( (loopIndex|0) < (loopCOUNT|0)) {
  499. idx=0;
  500. for(idx = idx<<1; (idx|0) <= (end<<1); idx = (idx + 1)|0)
  501. {
  502. v = f4load(Int16Heap, idx>>1);
  503. }
  504. loopIndex = (loopIndex + 1) | 0;
  505. }
  506. return v;
  507. }
  508. function load_1_Uint16(length)
  509. {
  510. length = length|0;
  511. var idx=0,end=120;
  512. var loopIndex = 0;
  513. var v = f4(0.0,0.0,0.0,0.0);
  514. end = (((length * 2)|0) - 8)|0;
  515. while ( (loopIndex|0) < (loopCOUNT|0)) {
  516. idx=0;
  517. for(idx = idx<<1; (idx|0) <= (end<<1); idx = (idx + 1)|0)
  518. {
  519. v = f4load(Uint16Heap, idx>>1);
  520. }
  521. loopIndex = (loopIndex + 1) | 0;
  522. }
  523. return v;
  524. }
  525. function load_1_Int32(length)
  526. {
  527. length = length|0;
  528. var idx=0,end=60;
  529. var loopIndex = 0;
  530. var v = f4(0.0,0.0,0.0,0.0);
  531. end = (((length * 1)|0) - 4)|0;
  532. while ( (loopIndex|0) < (loopCOUNT|0)) {
  533. idx=0;
  534. for(idx = idx<<2; (idx|0) <= (end<<2); idx = (idx + 1)|0)
  535. {
  536. v = f4load(Int32Heap, idx>>2);
  537. }
  538. loopIndex = (loopIndex + 1) | 0;
  539. }
  540. return v;
  541. }
  542. function load_1_Uint32(length)
  543. {
  544. length = length|0;
  545. var idx=0,end=60;
  546. var loopIndex = 0;
  547. var v = f4(0.0,0.0,0.0,0.0);
  548. end = (((length * 1)|0) - 4)|0;
  549. while ( (loopIndex|0) < (loopCOUNT|0)) {
  550. idx=0;
  551. for(idx = idx<<2; (idx|0) <= (end<<2); idx = (idx + 1)|0)
  552. {
  553. v = f4load(Uint32Heap, idx>>2);
  554. }
  555. loopIndex = (loopIndex + 1) | 0;
  556. }
  557. return v;
  558. }
  559. return {store1:store_1
  560. ,store2:store_2
  561. ,store3:store_3
  562. ,store1Int8:store_1_Int8
  563. ,store1Uint8:store_1_Uint8
  564. ,store1Int16:store_1_Int16
  565. ,store1Uint16:store_1_Uint16
  566. ,store1Int32:store_1_Int32
  567. ,store1Uint32:store_1_Uint32
  568. ,load1:load_1
  569. ,load2:load_2
  570. ,load3:load_3
  571. ,load1Int8:load_1_Int8
  572. ,load1Uint8:load_1_Uint8
  573. ,load1Int16:load_1_Int16
  574. ,load1Uint16:load_1_Uint16
  575. ,load1Int32:load_1_Int32
  576. ,load1Uint32:load_1_Uint32
  577. ,loadF32:loadF32
  578. ,storeF32:storeF32
  579. ,storeUI32:storeUI32
  580. ,loadUI32:loadUI32
  581. ,storeI32:storeI32
  582. ,loadI32:loadI32
  583. ,storeI16:storeI16
  584. ,loadI16:loadI16
  585. ,storeUI16:storeUI16
  586. ,loadUI16:loadUI16
  587. ,storeI8:storeI8
  588. ,loadI8:loadI8
  589. ,storeUI8:storeUI8
  590. ,loadUI8:loadUI8
  591. ,loadStoreIndex1:loadStoreIndex1};
  592. }
  593. var buffer = new ArrayBuffer(0x10000); //16mb min 2^12
  594. //Reset or flush the buffer
  595. function initF32(buffer) {
  596. var values = new Float32Array( buffer );
  597. for( var i=0; i < values.length ; ++i ) {
  598. values[i] = i * 10;
  599. }
  600. return values.length;
  601. }
  602. function printBuffer(buffer, count)
  603. {
  604. var f4;
  605. for (var i = 0; i < count/* * 16*/; i += 16)
  606. {
  607. f4 = SIMD.Float32x4.load(buffer, i);
  608. print(f4.toString());
  609. }
  610. }
  611. function printResults(res)
  612. {
  613. print(typeof(res));
  614. print(res.toString());
  615. }
  616. inputLength = initF32(buffer);
  617. print(inputLength);
  618. //Enumerating SIMD loads to test.
  619. SIMDLoad = 1;
  620. SIMDLoad1 = 2;
  621. SIMDLoad2 = 3;
  622. SIMDLoad3 = 4;
  623. SIMDStore = 5;
  624. SIMDStore1 = 6;
  625. SIMDStore2 = 7;
  626. SIMDStore3 = 8;
  627. //Module initialization
  628. var m = asmModule(this, {g0:initF32(buffer),g1:SIMD.Float32x4(9,9,9,9), g2:SIMD.Int32x4(1, 2, 3, 4)}, buffer);
  629. var values = new Float32Array(buffer);
  630. print("Stores:");
  631. print("Test1");
  632. var ret = m.store1(SIMDStore1);//Lane1 store
  633. // printBuffer(values, 10);
  634. equalSimd([5.099999904632568, 10, 20, 30], SIMD.Float32x4.load(values, 0), SIMD.Float32x4, "TestStore1");
  635. print("Test2");;
  636. inputLength = initF32(buffer);
  637. var ret = m.store1(SIMDStore2);//Lane 1,2 store
  638. // printBuffer(values, 10);
  639. equalSimd([5.099999904632568, -12.300000190734863, 20, 30], SIMD.Float32x4.load(values, 0), SIMD.Float32x4, "TestStore2");
  640. print("Test3");
  641. inputLength = initF32(buffer);
  642. var ret = m.store1(SIMDStore3);//Lane 1,2,3 store
  643. // printBuffer(values, 10);
  644. equalSimd([5.099999904632568, -12.300000190734863, 0, 30 ], SIMD.Float32x4.load(values, 0), SIMD.Float32x4, "TestStore3");
  645. print("Test4");
  646. inputLength = initF32(buffer);
  647. //Should change the buffer to 0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3...15,15,15,15,0,0,0,0...
  648. var ret = m.store1(SIMDStore);//Generic Store
  649. // printBuffer(values, 10);
  650. equalSimd([5.099999904632568, -12.300000190734863, 0, 0], SIMD.Float32x4.load(values, 0), SIMD.Float32x4, "TestStore4");
  651. print("Test5");
  652. inputLength = initF32(buffer);
  653. var ret = m.store2(SIMDStore);//Generic store
  654. // printBuffer(values, 10);
  655. equalSimd([0, 0, 0, 0], SIMD.Float32x4.load(values, 0), SIMD.Float32x4, "TestStore5");
  656. print("Test6");
  657. inputLength = initF32(buffer);
  658. var ret = m.store3(SIMDStore);//Generic store
  659. // printBuffer(values, 10);
  660. equalSimd([0, 0, 0, 0], SIMD.Float32x4.load(values, 0), SIMD.Float32x4, "TestStore6");
  661. print("Test7");
  662. inputLength = initF32(buffer);
  663. var ret = m.store1Int8(inputLength);//Int8Heap store
  664. // printBuffer(values, 10);
  665. equalSimd([0, 0, 0, 0], SIMD.Float32x4.load(values, 0), SIMD.Float32x4, "TestStore7");
  666. print("Test8");
  667. inputLength = initF32(buffer);
  668. var ret = m.store1Uint8(inputLength);//Uint8Heap store
  669. // printBuffer(values, 10);
  670. equalSimd([0, 0, 0, 0], SIMD.Float32x4.load(values, 0), SIMD.Float32x4, "TestStore8");
  671. print("Test9");
  672. inputLength = initF32(buffer);
  673. var ret = m.store1Int16(inputLength);//Int16Heap store
  674. // printBuffer(values, 10);
  675. equalSimd([0, 0, 0, 0], SIMD.Float32x4.load(values, 0), SIMD.Float32x4, "TestStore9");
  676. print("Test10");
  677. inputLength = initF32(buffer);
  678. var ret = m.store1Uint16(inputLength);//Uint16Heap store
  679. // printBuffer(values, 10);
  680. equalSimd([0, 0, 0, 0], SIMD.Float32x4.load(values, 0), SIMD.Float32x4, "TestStore10");
  681. print("Test12");
  682. inputLength = initF32(buffer);
  683. var ret = m.store1Int32(inputLength);//Int32Heap store
  684. // printBuffer(values, 10);
  685. equalSimd([0, 0, 0, 0], SIMD.Float32x4.load(values, 0), SIMD.Float32x4, "TestStore12");
  686. print("Test13");
  687. inputLength = initF32(buffer);
  688. var ret = m.store1Uint32(inputLength);//Uint32Heap store
  689. // printBuffer(values, 10);
  690. equalSimd([0, 0, 0, 0], SIMD.Float32x4.load(values, 0), SIMD.Float32x4, "TestStore13");
  691. print("Test14");
  692. inputLength = initF32(buffer);
  693. var ret = m.loadStoreIndex1();//Uint32Heap store
  694. // printBuffer(values, 10);
  695. equalSimd([-1, -2, 3.0999999046325683, -4], SIMD.Float32x4.load(values, 0), SIMD.Float32x4, "TestStore14");
  696. print("Loads");
  697. print("Test1");
  698. var ret = m.load1(SIMDLoad1);
  699. equalSimd([160, 0, 0, 0], ret, SIMD.Float32x4, "TestStore");
  700. print("Test2");
  701. var ret = m.load1(SIMDLoad2);
  702. equalSimd([160, 170, 0, 0], ret, SIMD.Float32x4, "TestStore2");
  703. print("Test3");
  704. var ret = m.load1(SIMDLoad3);
  705. equalSimd([160, 170, 180, 0], ret, SIMD.Float32x4, "TestStore3");
  706. print("Test4");
  707. var ret = m.load1(SIMDLoad);
  708. equalSimd([160, 170, 180, 190], ret, SIMD.Float32x4, "TestStore4");
  709. print("Test5");
  710. var ret = m.load2(SIMDLoad);
  711. equalSimd([160, 170, 180, 190], ret, SIMD.Float32x4, "TestStore5");
  712. print("Test6");
  713. var ret = m.load3(SIMDLoad);
  714. equalSimd([160, 170, 180, 190], ret, SIMD.Float32x4, "TestStore6");
  715. print("Test7");
  716. var ret = m.load1Int8(inputLength); //Int8Heap load
  717. equalSimd([163800, 163810, 163820, 163830], ret, SIMD.Float32x4, "TestStore7");
  718. print("Test8");
  719. var ret = m.load1Uint8(inputLength); //Int8Heap load
  720. equalSimd([163800, 163810, 163820, 163830], ret, SIMD.Float32x4, "TestStore8");
  721. print("Test9");
  722. var ret = m.load1Int16(inputLength); //Int16Heap load
  723. equalSimd([163800, 163810, 163820, 163830], ret, SIMD.Float32x4, "TestStore9");
  724. print("Test10");
  725. var ret = m.load1Uint16(inputLength); //Int16Heap load
  726. equalSimd([163800, 163810, 163820, 163830], ret, SIMD.Float32x4, "TestStore10");
  727. print("Test11");
  728. var ret = m.load1Int32(inputLength); //Int32Heap load
  729. equalSimd([163800, 163810, 163820, 163830], ret, SIMD.Float32x4, "TestStore11");
  730. print("Test12");
  731. var ret = m.load1Uint32(inputLength); //Int32Heap load
  732. equalSimd([163800, 163810, 163820, 163830], ret, SIMD.Float32x4, "TestStore12");
  733. print("BoundCheck");
  734. var value = SIMD.Float32x4(9.9,1.2,3.4,5.6);
  735. print("Test1");
  736. try {m.storeF32(value, inputLength); print("Wrong");} catch(err) {print("Correct");}
  737. print("Test2");
  738. try {m.loadF32(inputLength); print("Wrong");} catch(err) {print("Correct");}
  739. print("Test3");
  740. try {m.storeF32(value, inputLength-1); print("Wrong");} catch(err) {print("Correct");}
  741. print("Test4");
  742. try {m.loadF32(inputLength-1); print("Wrong");} catch(err) {print("Correct");}
  743. print("Test5");
  744. try {m.storeF32(value, inputLength-4);print("Correct");} catch(err) {print("Wrong");}
  745. print("Test6");
  746. try {var v = m.loadF32(inputLength-4);print("Correct");} catch(err) {print("Wrong");}
  747. print("Test7");
  748. try {m.storeUI32(value, inputLength+1);print("Wrong");} catch(err) {print("Correct");}
  749. print("Test8");
  750. try { m.loadUI32(inputLength+1); print("Wrong"); } catch(err) { print("Correct"); }
  751. print("Test9");
  752. try {m.storeI32(value, inputLength+1); print("Wrong");} catch(err) {print("Correct");}
  753. print("Test10");
  754. try {m.loadI32(inputLength+1);print("Wrong");} catch(err) {print("Correct");}
  755. print("Test11");
  756. try{
  757. m.storeI16(value, inputLength*2-8);
  758. print("Correct");
  759. m.storeUI16(value, inputLength*2-8);
  760. print("Correct");
  761. m.storeI8(value, inputLength*4-16);
  762. print("Correct");
  763. m.storeUI8(value, inputLength*4-16);
  764. print("Correct");
  765. m.loadI16(inputLength*2-8);
  766. print("Correct");
  767. m.loadUI16(inputLength*2-8);
  768. print("Correct");
  769. m.loadI8(inputLength*4-16);
  770. print("Correct");
  771. m.loadUI8(inputLength*4-16);
  772. print("Correct");
  773. } catch(err){ print("Wrong"); }
  774. print("Test12");
  775. try {m.storeUI16(value, inputLength*2);print("Wrong");} catch(err) {print("Correct");}
  776. print("Test13");
  777. try {m.loadUI16(inputLength*2-7); print("Wrong");} catch(err) {print("Correct");}
  778. print("Test14");
  779. try {m.storeI16(value, inputLength*2-7); print("Wrong");} catch(err) {print("Correct");}
  780. print("Test15");
  781. try {m.loadI16(inputLength*2-7); print("Wrong");} catch(err) {print("Correct");}
  782. print("Test16");
  783. try {m.storeUI8(value, inputLength*4-15); print("Wrong");} catch(err) {print("Correct");}
  784. print("Test17");
  785. try {m.loadUI8(inputLength*4-15); print("Wrong");} catch(err) {print("Correct");}
  786. print("Test18");
  787. try {m.storeI8(value, inputLength*4-15); print("Wrong");} catch(err) {print("Correct");}
  788. print("Test19");
  789. try {m.loadI8(inputLength*4+15); print("Wrong");} catch(err) {print("Correct");}