{"action":"opened","issue":{"url":"https://api.github.com/repos/tc39/ecmascript_simd/issues/313","labels_url":"https://api.github.com/repos/tc39/ecmascript_simd/issues/313/labels{/name}","comments_url":"https://api.github.com/repos/tc39/ecmascript_simd/issues/313/comments","events_url":"https://api.github.com/repos/tc39/ecmascript_simd/issues/313/events","html_url":"https://github.com/tc39/ecmascript_simd/issues/313","id":129613501,"number":313,"title":"SIMD partial loads generate NaNs in higher lanes in the polyfill, when they should generate zeroes.","user":{"login":"juj","id":225351,"avatar_url":"https://avatars.githubusercontent.com/u/225351?v=3","gravatar_id":"","url":"https://api.github.com/users/juj","html_url":"https://github.com/juj","followers_url":"https://api.github.com/users/juj/followers","following_url":"https://api.github.com/users/juj/following{/other_user}","gists_url":"https://api.github.com/users/juj/gists{/gist_id}","starred_url":"https://api.github.com/users/juj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juj/subscriptions","organizations_url":"https://api.github.com/users/juj/orgs","repos_url":"https://api.github.com/users/juj/repos","events_url":"https://api.github.com/users/juj/events{/privacy}","received_events_url":"https://api.github.com/users/juj/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-01-28T23:09:37Z","updated_at":"2016-01-28T23:09:37Z","closed_at":null,"body":"Calling `SIMD.Float32x4.load1(HEAPU8, index)` in the polyfill will erroneously generate a vector of form `{ s_: Float32Array { '0': 20, '1': NaN, '2': NaN, '3': NaN } }`, when it should generate a vector with the higher lanes initialized to zero as per step 4 of http://tc39.github.io/ecmascript_simd/#simd-load.\r\n\r\nPoking at this a bit, looks like the issue is avoided by adding in the polyfill `simdLoad` function the following:\r\n\r\n    function simdLoad(type, tarray, index, count) {\r\n      if (!isTypedArray(tarray))\r\n        throw new TypeError(\"The 1st argument must be a typed array.\");\r\n      if (!isInt32(index))\r\n        throw new TypeError(\"The 2nd argument must be an Int32.\");\r\n      var bpe = tarray.BYTES_PER_ELEMENT;\r\n      var bytes = count * type.laneSize;\r\n      if (index < 0 || (index * bpe + bytes) > tarray.byteLength)\r\n        throw new RangeError(\"The value of index is invalid.\");\r\n\r\n      var newValue = type.fn();\r\n      var dst = new Uint8Array(newValue.s_.buffer);\r\n      var src = new Uint8Array(tarray.buffer, tarray.byteOffset + index * bpe, bytes);\r\n\r\n      for (var i = 0; i < bytes; i++) {\r\n        dst[i] = src[i];\r\n      }\r\n    +  for (var i = bytes; i < 16; ++i) {\r\n    +    dst[i] = 0;\r\n    +  }\r\n      return newValue;\r\n    }\r\n\r\nNot sure though if that would be a preferred form to fix.\r\n"}}