{"action":"created","issue":{"url":"https://api.github.com/repos/kripken/emscripten/issues/3329","labels_url":"https://api.github.com/repos/kripken/emscripten/issues/3329/labels{/name}","comments_url":"https://api.github.com/repos/kripken/emscripten/issues/3329/comments","events_url":"https://api.github.com/repos/kripken/emscripten/issues/3329/events","html_url":"https://github.com/kripken/emscripten/pull/3329","id":67566493,"number":3329,"title":"Add pointer-masking runtime validation checks. ","user":{"login":"JSStats","id":11826073,"avatar_url":"https://avatars.githubusercontent.com/u/11826073?v=3","gravatar_id":"","url":"https://api.github.com/users/JSStats","html_url":"https://github.com/JSStats","followers_url":"https://api.github.com/users/JSStats/followers","following_url":"https://api.github.com/users/JSStats/following{/other_user}","gists_url":"https://api.github.com/users/JSStats/gists{/gist_id}","starred_url":"https://api.github.com/users/JSStats/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JSStats/subscriptions","organizations_url":"https://api.github.com/users/JSStats/orgs","repos_url":"https://api.github.com/users/JSStats/repos","events_url":"https://api.github.com/users/JSStats/events{/privacy}","received_events_url":"https://api.github.com/users/JSStats/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-04-10T10:44:42Z","updated_at":"2015-04-13T22:07:21Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/kripken/emscripten/pulls/3329","html_url":"https://github.com/kripken/emscripten/pull/3329","diff_url":"https://github.com/kripken/emscripten/pull/3329.diff","patch_url":"https://github.com/kripken/emscripten/pull/3329.patch"},"body":"These replace the bitand operation with a call to a function that checks that the result of masking the index equals the argument, in other words that the bitand operation is a nop.\r\n\r\nSome cases have been found in which replacing a[(i+c)&m] with a[(i&m)+c] can give invalid results, in particular when 'i' is negative, and this runtime test will detect this.\r\n\r\nWhile runtime checks are not a good long term solution, they help validate benchmarks used to test JS implementation performance and this avoids blocking JS implementation development.\r\n\r\nThis patch also adds support for blacklisting some functions from using the above transform, and for these functions all accesses are emitted as a[(i+c)&m]."},"comment":{"url":"https://api.github.com/repos/kripken/emscripten/issues/comments/92514156","html_url":"https://github.com/kripken/emscripten/pull/3329#issuecomment-92514156","issue_url":"https://api.github.com/repos/kripken/emscripten/issues/3329","id":92514156,"user":{"login":"JSStats","id":11826073,"avatar_url":"https://avatars.githubusercontent.com/u/11826073?v=3","gravatar_id":"","url":"https://api.github.com/users/JSStats","html_url":"https://github.com/JSStats","followers_url":"https://api.github.com/users/JSStats/followers","following_url":"https://api.github.com/users/JSStats/following{/other_user}","gists_url":"https://api.github.com/users/JSStats/gists{/gist_id}","starred_url":"https://api.github.com/users/JSStats/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JSStats/subscriptions","organizations_url":"https://api.github.com/users/JSStats/orgs","repos_url":"https://api.github.com/users/JSStats/repos","events_url":"https://api.github.com/users/JSStats/events{/privacy}","received_events_url":"https://api.github.com/users/JSStats/received_events","type":"User","site_admin":false},"created_at":"2015-04-13T22:07:20Z","updated_at":"2015-04-13T22:07:20Z","body":"Please see the comment submitted with this patch 'While runtime checks are not a good long term solution, they help validate benchmarks used to test JS implementation performance and this avoids blocking JS implementation development.'\r\n\r\nThis problem can not be avoided. A destructive transform is being made. I believe this will be practical using reasonable heuristics and aided by some type information, and the runtime checks give further support for this position. For example, it is probably sound for most code to assume that pointers are not negative, and that code does not depend on pointer wrapping. This makes the transform of `a[(p+c)&m]` to `a[(p&m)+c]` practical, and it is also practical when `p` can be proven non-negative. This might be further limited to only assuming that pointers obtain via certain paths are non-negative. More can be done.\r\n\r\nThese transforms simply can not be made by the JS implementation without dynamic guards (except where they can be proven valid by type information). It has always been my intention to make such transforms in Emscripten where they can be guided by heuristics, and more are planned to support the hoisting of the masking.\r\n\r\nThis patch is needed to double check such heuristics, and as a method to validate benchmarks used for JS implementation development. It can certainly give confidence in a deterministic benchmark.\r\n\r\nI'll probably be focused on helping JS implementations emit great code for these patterns in the short term, and using the validated benchmarks to track progress.\r\n\r\nI am fine with forking Emscripten, and don't want to push these on anyone. It could always be merged in future if proven useful, and there is still a lot of common ground. Just let me know if it's too experimental?"}}