{"action":"created","issue":{"url":"https://api.github.com/repos/kripken/emscripten/issues/3561","labels_url":"https://api.github.com/repos/kripken/emscripten/issues/3561/labels{/name}","comments_url":"https://api.github.com/repos/kripken/emscripten/issues/3561/comments","events_url":"https://api.github.com/repos/kripken/emscripten/issues/3561/events","html_url":"https://github.com/kripken/emscripten/issues/3561","id":89606712,"number":3561,"title":"Global variables are not correctly aligned.","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":[{"url":"https://api.github.com/repos/kripken/emscripten/labels/SIMD","name":"SIMD","color":"bfd4f2"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-19T16:33:09Z","updated_at":"2015-06-19T22:30:14Z","closed_at":null,"body":"When using the `__attribute__((aligned(16)))` attribute, or the LLVM vector attribute `typedef float float32x4 __attribute__((__vector_size__(16), __may_alias__))` to specify 16-byte alignment for a variable, global variables should get this alignment, but testing on the following code, it looks like 8 byte alignment is the best that is achieved. The following code\r\n\r\n\t#include <xmmintrin.h>\r\n\t#include <stdio.h>\r\n\r\n\tstruct __attribute__((aligned(16))) float4x4\r\n\t{\r\n\t\tunion\r\n\t\t{\r\n\t\t\tfloat v[4][4];\r\n\t\t\t__m128 row[4];\r\n\t\t};\r\n\t};\r\n\r\n\tfloat4x4 v;\r\n\t__m128 m;\r\n\r\n\tint main()\r\n\t{\r\n\t\tprintf(\"Alignment: %d addr: %x\\n\", ((int)&v) % 16, (int)&v);\r\n\t\tprintf(\"Alignment: %d addr: %x\\n\", ((int)&m) % 16, (int)&m);\r\n\t}\r\n\r\nprints\r\n\r\n    Alignment: 8 addr: 8\r\n    Alignment: 8 addr: 48\r\n\r\nwhen it is expected to print `Alignment 0`. Function local variables seem to work ok. I see we get the global address `8` as the starting address, perhaps this has to do with a guardband address of 8 bytes at the start of the heap (or similar?), and that should be bumped to 16 bytes or more? @kripken?"},"comment":{"url":"https://api.github.com/repos/kripken/emscripten/issues/comments/113661708","html_url":"https://github.com/kripken/emscripten/issues/3561#issuecomment-113661708","issue_url":"https://api.github.com/repos/kripken/emscripten/issues/3561","id":113661708,"user":{"login":"kripken","id":173661,"avatar_url":"https://avatars.githubusercontent.com/u/173661?v=3","gravatar_id":"","url":"https://api.github.com/users/kripken","html_url":"https://github.com/kripken","followers_url":"https://api.github.com/users/kripken/followers","following_url":"https://api.github.com/users/kripken/following{/other_user}","gists_url":"https://api.github.com/users/kripken/gists{/gist_id}","starred_url":"https://api.github.com/users/kripken/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kripken/subscriptions","organizations_url":"https://api.github.com/users/kripken/orgs","repos_url":"https://api.github.com/users/kripken/repos","events_url":"https://api.github.com/users/kripken/events{/privacy}","received_events_url":"https://api.github.com/users/kripken/received_events","type":"User","site_admin":false},"created_at":"2015-06-19T22:30:14Z","updated_at":"2015-06-19T22:30:14Z","body":"The issue is that we just assume align 8 for all heap vars, which was a temporary thing that... never stopped working, so we never fixed it ;)\r\n\r\nI opened `heapalign` branches to fix this. I think I have most of the logic done, but still some test failures currently.\r\n"}}