{"action":"created","issue":{"url":"https://api.github.com/repos/halide/Halide/issues/1302","repository_url":"https://api.github.com/repos/halide/Halide","labels_url":"https://api.github.com/repos/halide/Halide/issues/1302/labels{/name}","comments_url":"https://api.github.com/repos/halide/Halide/issues/1302/comments","events_url":"https://api.github.com/repos/halide/Halide/issues/1302/events","html_url":"https://github.com/halide/Halide/pull/1302","id":160072795,"number":1302,"title":"Unify common cast helper functions","user":{"login":"abadams","id":515398,"avatar_url":"https://avatars.githubusercontent.com/u/515398?v=3","gravatar_id":"","url":"https://api.github.com/users/abadams","html_url":"https://github.com/abadams","followers_url":"https://api.github.com/users/abadams/followers","following_url":"https://api.github.com/users/abadams/following{/other_user}","gists_url":"https://api.github.com/users/abadams/gists{/gist_id}","starred_url":"https://api.github.com/users/abadams/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abadams/subscriptions","organizations_url":"https://api.github.com/users/abadams/orgs","repos_url":"https://api.github.com/users/abadams/repos","events_url":"https://api.github.com/users/abadams/events{/privacy}","received_events_url":"https://api.github.com/users/abadams/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-06-14T00:21:46Z","updated_at":"2016-06-15T22:54:45Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/halide/Halide/pulls/1302","html_url":"https://github.com/halide/Halide/pull/1302","diff_url":"https://github.com/halide/Halide/pull/1302.diff","patch_url":"https://github.com/halide/Halide/pull/1302.patch"},"body":"People seem to like to write helpers to do casts more concisely. E.g. cast(UInt(8), foo) -> u8(foo). This is especially convenient for codegen patterns, which use lots of casts inline, and for saturating casts, which are otherwise very verbose (and tricky to get right). \r\n\r\nThe precise nesting and sequencing of the casts and the other basic numeric operations (+, *, min, etc) are also important to express tersely when you're writing fixed-point code. It's often only clear that code doesn't overflow yet still generates good machine code if the cast is right there in the middle of the expression. Otherwise you have to think about bounds of things across multiple lines of code.\r\n\r\nUnfortunately, these helpers get re-declared with slightly different names all over the place. Nobody wants to put them in the global namespace, because they're too short. This PR dumps them in a namespace ConciseCasts, which you can import via \"using namespace ConciseCasts\"\r\n\r\nI just went with the most common choice I saw for naming: u8(foo) and u8c(foo) for the clamping/saturating variant. Other opinions on naming welcome. Keep in mind though that if it isn't significantly shorter than cast<uint8_t>(foo) then people may just continue writing their own helpers."},"comment":{"url":"https://api.github.com/repos/halide/Halide/issues/comments/226343783","html_url":"https://github.com/halide/Halide/pull/1302#issuecomment-226343783","issue_url":"https://api.github.com/repos/halide/Halide/issues/1302","id":226343783,"user":{"login":"abadams","id":515398,"avatar_url":"https://avatars.githubusercontent.com/u/515398?v=3","gravatar_id":"","url":"https://api.github.com/users/abadams","html_url":"https://github.com/abadams","followers_url":"https://api.github.com/users/abadams/followers","following_url":"https://api.github.com/users/abadams/following{/other_user}","gists_url":"https://api.github.com/users/abadams/gists{/gist_id}","starred_url":"https://api.github.com/users/abadams/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abadams/subscriptions","organizations_url":"https://api.github.com/users/abadams/orgs","repos_url":"https://api.github.com/users/abadams/repos","events_url":"https://api.github.com/users/abadams/events{/privacy}","received_events_url":"https://api.github.com/users/abadams/received_events","type":"User","site_admin":false},"created_at":"2016-06-15T22:54:45Z","updated_at":"2016-06-15T22:54:45Z","body":"Updated for hexagon. PTAL."}}
{"actor":{"display_login":"abadams"}}