{"action":"created","comment":{"url":"https://api.github.com/repos/halide/Halide/pulls/comments/54807196","id":54807196,"diff_hunk":"@@ -2734,16 +2739,23 @@ void CodeGen_Hexagon::visit(const Load *op) {\n             CodeGen_Posix::visit(op);\n             return;\n           }\n-          int offset = b->value;\n-          if (mod_rem.remainder != ((bytes_in_vector() + offset) % bytes_in_vector())) {\n+          int offset = (b->value % lanes);\n+          // If the offset is negative, it is because we are trying to load something like\n+          // f(x-1). In this case, the remainder should be (vector_width + offset) % vector_width\n+          // Or in general for any type, it would be (lanes + offset) % lanes.\n+          if (mod_rem.remainder != (lanes + offset) % lanes) {\n             CodeGen_Posix::visit(op);\n             return;\n           }\n-          int bytes_off = std::abs(offset) * (op->type.bits() / 8);\n-          Expr base_low = offset > 0 ? add->a : simplify(add->a - width);\n-          Expr base_high = offset > 0 ? simplify(add->a + width) : add->a;\n-          Expr ramp_low = Ramp::make(base_low, 1, width);\n-          Expr ramp_high = Ramp::make(base_high, 1, width);\n+          // offset tells us that we are off by those many elements from the vector\n+          // width. For e.g. a value of -1 when we are loading a half-word vector\n+          // means we are reading one half-word left of an aligned address.\n+          // so we are 1 * (64 / 32) = 2 bytes off (assuming 64 byte mode).\n+          int bytes_off = std::abs(offset) * (native_vector_bytes / lanes);","path":"src/CodeGen_Hexagon.cpp","position":71,"original_position":71,"commit_id":"b93a175e45c60210bc3d10f80e568857f90e4a37","original_commit_id":"b93a175e45c60210bc3d10f80e568857f90e4a37","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},"body":"If it would make those indistinguishable, then how do you currently distinguish between ```ramp(a*64 + 1, 1, 64)``` and ```ramp(a*64 + 65, 1, 64)```? Looks like you need to also divide b->value by lanes and add that to base (use div_imp to have the right behavior relative to mod_imp).\r\n\r\nAs far as I can tell, for this purpose ```%``` and ```/``` are just slightly broken versions of ```mod_imp``` and ```div_imp```. ","created_at":"2016-03-02T22:54:15Z","updated_at":"2016-03-02T22:54:15Z","html_url":"https://github.com/halide/Halide/pull/1056#discussion_r54807196","pull_request_url":"https://api.github.com/repos/halide/Halide/pulls/1056","_links":{"self":{"href":"https://api.github.com/repos/halide/Halide/pulls/comments/54807196"},"html":{"href":"https://github.com/halide/Halide/pull/1056#discussion_r54807196"},"pull_request":{"href":"https://api.github.com/repos/halide/Halide/pulls/1056"}}},"pull_request":{"url":"https://api.github.com/repos/halide/Halide/pulls/1056","id":60908445,"html_url":"https://github.com/halide/Halide/pull/1056","diff_url":"https://github.com/halide/Halide/pull/1056.diff","patch_url":"https://github.com/halide/Halide/pull/1056.patch","issue_url":"https://api.github.com/repos/halide/Halide/issues/1056","number":1056,"state":"open","locked":false,"title":"Hexagon align unaligned loads","user":{"login":"pranavb-ca","id":16598810,"avatar_url":"https://avatars.githubusercontent.com/u/16598810?v=3","gravatar_id":"","url":"https://api.github.com/users/pranavb-ca","html_url":"https://github.com/pranavb-ca","followers_url":"https://api.github.com/users/pranavb-ca/followers","following_url":"https://api.github.com/users/pranavb-ca/following{/other_user}","gists_url":"https://api.github.com/users/pranavb-ca/gists{/gist_id}","starred_url":"https://api.github.com/users/pranavb-ca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pranavb-ca/subscriptions","organizations_url":"https://api.github.com/users/pranavb-ca/orgs","repos_url":"https://api.github.com/users/pranavb-ca/repos","events_url":"https://api.github.com/users/pranavb-ca/events{/privacy}","received_events_url":"https://api.github.com/users/pranavb-ca/received_events","type":"User","site_admin":false},"body":"So far, we had been generating the vmem+vmem+valign sequence in place of a vmemu\r\nonly for byte-vectors. We now generalize this for all datatypes.\r\n\r\nThis patch, though, works only for well-formed ramp bases. Let's say we are trying to load an unaligned half-word vector with this ramp(c1*64 + c2, 1, 32), where c2  is a constant and it doesn't really matter what c1 is. This is well formed because 64 is a mulitple of the lanes, so it is aligned in that sense. Assuming that the buffer is aligned, it means we are exactly 'c2' half-words away from an aligned address.\r\nSo we will generate the following sequence:\r\n               v0 = vmem(64*c1)      // load aligned vector\r\n               v1 = vmem(64*c1 + 64) // load next aligned vector.\r\n               v2 = valign(v1, v0, (c2*2))\r\n","created_at":"2016-02-26T21:41:16Z","updated_at":"2016-03-02T22:54:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ad9e01db1a73ce7a5327c284dfece6acfd9b62c9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/halide/Halide/pulls/1056/commits","review_comments_url":"https://api.github.com/repos/halide/Halide/pulls/1056/comments","review_comment_url":"https://api.github.com/repos/halide/Halide/pulls/comments{/number}","comments_url":"https://api.github.com/repos/halide/Halide/issues/1056/comments","statuses_url":"https://api.github.com/repos/halide/Halide/statuses/b93a175e45c60210bc3d10f80e568857f90e4a37","head":{"label":"halide:hexagon_align_unaligned_loads","ref":"hexagon_align_unaligned_loads","sha":"b93a175e45c60210bc3d10f80e568857f90e4a37","user":{"login":"halide","id":1548551,"avatar_url":"https://avatars.githubusercontent.com/u/1548551?v=3","gravatar_id":"","url":"https://api.github.com/users/halide","html_url":"https://github.com/halide","followers_url":"https://api.github.com/users/halide/followers","following_url":"https://api.github.com/users/halide/following{/other_user}","gists_url":"https://api.github.com/users/halide/gists{/gist_id}","starred_url":"https://api.github.com/users/halide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/halide/subscriptions","organizations_url":"https://api.github.com/users/halide/orgs","repos_url":"https://api.github.com/users/halide/repos","events_url":"https://api.github.com/users/halide/events{/privacy}","received_events_url":"https://api.github.com/users/halide/received_events","type":"Organization","site_admin":false},"repo":{"id":5241312,"name":"Halide","full_name":"halide/Halide","owner":{"login":"halide","id":1548551,"avatar_url":"https://avatars.githubusercontent.com/u/1548551?v=3","gravatar_id":"","url":"https://api.github.com/users/halide","html_url":"https://github.com/halide","followers_url":"https://api.github.com/users/halide/followers","following_url":"https://api.github.com/users/halide/following{/other_user}","gists_url":"https://api.github.com/users/halide/gists{/gist_id}","starred_url":"https://api.github.com/users/halide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/halide/subscriptions","organizations_url":"https://api.github.com/users/halide/orgs","repos_url":"https://api.github.com/users/halide/repos","events_url":"https://api.github.com/users/halide/events{/privacy}","received_events_url":"https://api.github.com/users/halide/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/halide/Halide","description":"a language for image processing and computational photography","fork":false,"url":"https://api.github.com/repos/halide/Halide","forks_url":"https://api.github.com/repos/halide/Halide/forks","keys_url":"https://api.github.com/repos/halide/Halide/keys{/key_id}","collaborators_url":"https://api.github.com/repos/halide/Halide/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/halide/Halide/teams","hooks_url":"https://api.github.com/repos/halide/Halide/hooks","issue_events_url":"https://api.github.com/repos/halide/Halide/issues/events{/number}","events_url":"https://api.github.com/repos/halide/Halide/events","assignees_url":"https://api.github.com/repos/halide/Halide/assignees{/user}","branches_url":"https://api.github.com/repos/halide/Halide/branches{/branch}","tags_url":"https://api.github.com/repos/halide/Halide/tags","blobs_url":"https://api.github.com/repos/halide/Halide/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/halide/Halide/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/halide/Halide/git/refs{/sha}","trees_url":"https://api.github.com/repos/halide/Halide/git/trees{/sha}","statuses_url":"https://api.github.com/repos/halide/Halide/statuses/{sha}","languages_url":"https://api.github.com/repos/halide/Halide/languages","stargazers_url":"https://api.github.com/repos/halide/Halide/stargazers","contributors_url":"https://api.github.com/repos/halide/Halide/contributors","subscribers_url":"https://api.github.com/repos/halide/Halide/subscribers","subscription_url":"https://api.github.com/repos/halide/Halide/subscription","commits_url":"https://api.github.com/repos/halide/Halide/commits{/sha}","git_commits_url":"https://api.github.com/repos/halide/Halide/git/commits{/sha}","comments_url":"https://api.github.com/repos/halide/Halide/comments{/number}","issue_comment_url":"https://api.github.com/repos/halide/Halide/issues/comments{/number}","contents_url":"https://api.github.com/repos/halide/Halide/contents/{+path}","compare_url":"https://api.github.com/repos/halide/Halide/compare/{base}...{head}","merges_url":"https://api.github.com/repos/halide/Halide/merges","archive_url":"https://api.github.com/repos/halide/Halide/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/halide/Halide/downloads","issues_url":"https://api.github.com/repos/halide/Halide/issues{/number}","pulls_url":"https://api.github.com/repos/halide/Halide/pulls{/number}","milestones_url":"https://api.github.com/repos/halide/Halide/milestones{/number}","notifications_url":"https://api.github.com/repos/halide/Halide/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/halide/Halide/labels{/name}","releases_url":"https://api.github.com/repos/halide/Halide/releases{/id}","deployments_url":"https://api.github.com/repos/halide/Halide/deployments","created_at":"2012-07-31T04:05:25Z","updated_at":"2016-03-02T12:33:38Z","pushed_at":"2016-03-02T22:03:39Z","git_url":"git://github.com/halide/Halide.git","ssh_url":"git@github.com:halide/Halide.git","clone_url":"https://github.com/halide/Halide.git","svn_url":"https://github.com/halide/Halide","homepage":"http://halide-lang.org","size":209075,"stargazers_count":1204,"watchers_count":1204,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":240,"mirror_url":null,"open_issues_count":160,"forks":240,"open_issues":160,"watchers":1204,"default_branch":"master"}},"base":{"label":"halide:hexagon","ref":"hexagon","sha":"4c8f1ef55fd728ae3cd33b0f4f9003e7b66fccad","user":{"login":"halide","id":1548551,"avatar_url":"https://avatars.githubusercontent.com/u/1548551?v=3","gravatar_id":"","url":"https://api.github.com/users/halide","html_url":"https://github.com/halide","followers_url":"https://api.github.com/users/halide/followers","following_url":"https://api.github.com/users/halide/following{/other_user}","gists_url":"https://api.github.com/users/halide/gists{/gist_id}","starred_url":"https://api.github.com/users/halide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/halide/subscriptions","organizations_url":"https://api.github.com/users/halide/orgs","repos_url":"https://api.github.com/users/halide/repos","events_url":"https://api.github.com/users/halide/events{/privacy}","received_events_url":"https://api.github.com/users/halide/received_events","type":"Organization","site_admin":false},"repo":{"id":5241312,"name":"Halide","full_name":"halide/Halide","owner":{"login":"halide","id":1548551,"avatar_url":"https://avatars.githubusercontent.com/u/1548551?v=3","gravatar_id":"","url":"https://api.github.com/users/halide","html_url":"https://github.com/halide","followers_url":"https://api.github.com/users/halide/followers","following_url":"https://api.github.com/users/halide/following{/other_user}","gists_url":"https://api.github.com/users/halide/gists{/gist_id}","starred_url":"https://api.github.com/users/halide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/halide/subscriptions","organizations_url":"https://api.github.com/users/halide/orgs","repos_url":"https://api.github.com/users/halide/repos","events_url":"https://api.github.com/users/halide/events{/privacy}","received_events_url":"https://api.github.com/users/halide/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/halide/Halide","description":"a language for image processing and computational photography","fork":false,"url":"https://api.github.com/repos/halide/Halide","forks_url":"https://api.github.com/repos/halide/Halide/forks","keys_url":"https://api.github.com/repos/halide/Halide/keys{/key_id}","collaborators_url":"https://api.github.com/repos/halide/Halide/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/halide/Halide/teams","hooks_url":"https://api.github.com/repos/halide/Halide/hooks","issue_events_url":"https://api.github.com/repos/halide/Halide/issues/events{/number}","events_url":"https://api.github.com/repos/halide/Halide/events","assignees_url":"https://api.github.com/repos/halide/Halide/assignees{/user}","branches_url":"https://api.github.com/repos/halide/Halide/branches{/branch}","tags_url":"https://api.github.com/repos/halide/Halide/tags","blobs_url":"https://api.github.com/repos/halide/Halide/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/halide/Halide/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/halide/Halide/git/refs{/sha}","trees_url":"https://api.github.com/repos/halide/Halide/git/trees{/sha}","statuses_url":"https://api.github.com/repos/halide/Halide/statuses/{sha}","languages_url":"https://api.github.com/repos/halide/Halide/languages","stargazers_url":"https://api.github.com/repos/halide/Halide/stargazers","contributors_url":"https://api.github.com/repos/halide/Halide/contributors","subscribers_url":"https://api.github.com/repos/halide/Halide/subscribers","subscription_url":"https://api.github.com/repos/halide/Halide/subscription","commits_url":"https://api.github.com/repos/halide/Halide/commits{/sha}","git_commits_url":"https://api.github.com/repos/halide/Halide/git/commits{/sha}","comments_url":"https://api.github.com/repos/halide/Halide/comments{/number}","issue_comment_url":"https://api.github.com/repos/halide/Halide/issues/comments{/number}","contents_url":"https://api.github.com/repos/halide/Halide/contents/{+path}","compare_url":"https://api.github.com/repos/halide/Halide/compare/{base}...{head}","merges_url":"https://api.github.com/repos/halide/Halide/merges","archive_url":"https://api.github.com/repos/halide/Halide/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/halide/Halide/downloads","issues_url":"https://api.github.com/repos/halide/Halide/issues{/number}","pulls_url":"https://api.github.com/repos/halide/Halide/pulls{/number}","milestones_url":"https://api.github.com/repos/halide/Halide/milestones{/number}","notifications_url":"https://api.github.com/repos/halide/Halide/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/halide/Halide/labels{/name}","releases_url":"https://api.github.com/repos/halide/Halide/releases{/id}","deployments_url":"https://api.github.com/repos/halide/Halide/deployments","created_at":"2012-07-31T04:05:25Z","updated_at":"2016-03-02T12:33:38Z","pushed_at":"2016-03-02T22:03:39Z","git_url":"git://github.com/halide/Halide.git","ssh_url":"git@github.com:halide/Halide.git","clone_url":"https://github.com/halide/Halide.git","svn_url":"https://github.com/halide/Halide","homepage":"http://halide-lang.org","size":209075,"stargazers_count":1204,"watchers_count":1204,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":240,"mirror_url":null,"open_issues_count":160,"forks":240,"open_issues":160,"watchers":1204,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/halide/Halide/pulls/1056"},"html":{"href":"https://github.com/halide/Halide/pull/1056"},"issue":{"href":"https://api.github.com/repos/halide/Halide/issues/1056"},"comments":{"href":"https://api.github.com/repos/halide/Halide/issues/1056/comments"},"review_comments":{"href":"https://api.github.com/repos/halide/Halide/pulls/1056/comments"},"review_comment":{"href":"https://api.github.com/repos/halide/Halide/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/halide/Halide/pulls/1056/commits"},"statuses":{"href":"https://api.github.com/repos/halide/Halide/statuses/b93a175e45c60210bc3d10f80e568857f90e4a37"}}}}