Title: Avoid masking/sign extension between function calls · Issue #38 · AssemblyScript/assemblyscript · GitHub
Open Graph Title: Avoid masking/sign extension between function calls · Issue #38 · AssemblyScript/assemblyscript
X Title: Avoid masking/sign extension between function calls · Issue #38 · AssemblyScript/assemblyscript
Description: Booleans, u8, i8, u16 and i16 are optimized poorly it seems. There is a lot of masking going on at the moment that is not necessary. Consider the following two functions: export function add16(x: i16, y: i16): i16 { return x + y; } expor...
Open Graph Description: Booleans, u8, i8, u16 and i16 are optimized poorly it seems. There is a lot of masking going on at the moment that is not necessary. Consider the following two functions: export function add16(x: i...
X Description: Booleans, u8, i8, u16 and i16 are optimized poorly it seems. There is a lot of masking going on at the moment that is not necessary. Consider the following two functions: export function add16(x: i...
Opengraph URL: https://github.com/AssemblyScript/assemblyscript/issues/38
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Avoid masking/sign extension between function calls","articleBody":"Booleans, u8, i8, u16 and i16 are optimized poorly it seems. There is a lot of masking going on at the moment that is not necessary.\r\n\r\nConsider the following two functions:\r\n```ts\r\nexport function add16(x: i16, y: i16): i16 {\r\n return x + y;\r\n}\r\n\r\nexport function add32(x: i32, y: i32): i32 {\r\n return x + y;\r\n}\r\n```\r\nThey get compiled down to:\r\n```wat\r\n (func $main/add16 (export \"add16\") (type $t0) (param $p0 i32) (param $p1 i32) (result i32)\r\n get_local $p0\r\n get_local $p1\r\n i32.add\r\n i32.const 16\r\n i32.shl\r\n i32.const 16\r\n i32.shr_s\r\n return)\r\n (func $main/add32 (export \"add32\") (type $t0) (param $p0 i32) (param $p1 i32) (result i32)\r\n get_local $p0\r\n get_local $p1\r\n i32.add\r\n return)\r\n```\r\nAs you can see, the add16 function has a lot of masking operations, while the add32 is just a pure addition. Compare this to the following Rust code:\r\n```rust\r\n#[no_mangle]\r\npub extern fn add16(x: i16, y: i16) -> i16 {\r\n x + y\r\n}\r\n\r\n#[no_mangle]\r\npub extern fn add32(x: i32, y: i32) -> i32 {\r\n x + y\r\n}\r\n```\r\nWhich gets compiled down to the following code:\r\n```wat\r\n (func $add16 (export \"add16\") (type $t0) (param $p0 i32) (param $p1 i32) (result i32)\r\n get_local $p1\r\n get_local $p0\r\n i32.add)\r\n (func $add32 (export \"add32\") (type $t0) (param $p0 i32) (param $p1 i32) (result i32)\r\n get_local $p1\r\n get_local $p0\r\n i32.add)\r\n```\r\nAs you can see, they are the same, as adding two i16 values is the same as adding two i32 values, because the upper 16-bits of the 32-bit wide \"register\" is getting masked away anyway when storing the 16-bit wide value in memory with a i32.store16_u instruction. So there's only very few instructions where actual masking is necessary (like dividing).","author":{"url":"https://github.com/CryZe","@type":"Person","name":"CryZe"},"datePublished":"2018-03-11T18:28:11Z","url":"https://github.com/AssemblyScript/assemblyscript/issues/38"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:cab1b1f8-ced1-6e07-6266-b985bece722c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B53C:1A2DA6:AF9A7F:F104DC:6B00AB81 |
| html-safe-nonce | 32684e63f4436a1a0154bf4e8608e3aec11327f0ad08e1441d44b11490decc9f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNTNDOjFBMkRBNjpBRjlBN0Y6RjEwNERDOjZCMDBBQjgxIiwidmlzaXRvcl9pZCI6IjQ4MjgzMTY4MjE5NDM3OTA0NjUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 19304c58f2581a9cfc50a3717870d15dbf74e3291451857750819302a0fa1940 |
| hovercard-subject-tag | issue:304181219 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/AssemblyScript/assemblyscript/38/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c5976b8c89cd8ef11e648527b5d32cf1698a56f957acd4daa0913e1300b9bbc5/AssemblyScript/assemblyscript/issues/38 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c5976b8c89cd8ef11e648527b5d32cf1698a56f957acd4daa0913e1300b9bbc5/AssemblyScript/assemblyscript/issues/38 |
| og:image:alt | Booleans, u8, i8, u16 and i16 are optimized poorly it seems. There is a lot of masking going on at the moment that is not necessary. Consider the following two functions: export function add16(x: i... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | CryZe |
| hostname | github.com |
| expected-hostname | github.com |
| None | 455b493e3402a3a3a06beac5d20bb7db3da060808b220aa48d6a7eca7c59863a |
| turbo-cache-control | no-preview |
| go-import | github.com/AssemblyScript/assemblyscript git https://github.com/AssemblyScript/assemblyscript.git |
| octolytics-dimension-user_id | 28916798 |
| octolytics-dimension-user_login | AssemblyScript |
| octolytics-dimension-repository_id | 105138356 |
| octolytics-dimension-repository_nwo | AssemblyScript/assemblyscript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 105138356 |
| octolytics-dimension-repository_network_root_nwo | AssemblyScript/assemblyscript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2f575159976167242d488c0b062eb355c4e198b7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width