-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace EM_BOOL with normal C/C++ bool type. NFC #22155
base: main
Are you sure you want to change the base?
Conversation
This change was created using sed to substitutions |
Updated to include struct size saves and code size savings. |
I'm trying to change the type of EM_BOOL and this is currently blocking that: emscripten-core/emscripten#22155
I could do this in two phases perhaps:
|
Why do struct sizes change? I'd expect an int and an unpacked bool to both take 32 bits. Is that wrong? |
I guess Indeed this program printf
|
(same for C++ BTW) |
By itself it's 1 byte, I guess, but inside a struct the field after it might be aligned: #include <stdbool.h>
#include <stdio.h>
class C {
bool x;
int y;
};
int main() {
printf("%ld\n", sizeof(C));
return 0;
} That prints |
Anyhow, yeah, if this causes struct layout changes then splitting the PR as much as possible sgtm. |
Right, that is just normal struct layout rules. If you put the Lowering the alignment of a type can for sure shrink struct sizes. That is the primary use of the alignment of a given type. Higher alignment == worse for struct size. |
This reduces the size of several structs and results in code size savings in some cases. This change is split of from a larger change I have planned to remove the use of EM_BOOL completely: emscripten-core#22155.
This reduces the size of several structs and results in code size savings in some cases. This change is split of from a larger change I have planned to remove the use of EM_BOOL completely: emscripten-core#22155.
This reduces the size of several structs and results in code size savings in some cases. This change is split of from a larger change I have planned to remove the use of EM_BOOL completely: emscripten-core#22155.
This reduces the size of several structs and results in code size savings in some cases. This change is split of from a larger change I have planned to remove the use of EM_BOOL completely: emscripten-core#22155.
This reduces the size of several structs and results in code size savings in some cases. This change is split of from a larger change I have planned to remove the use of EM_BOOL completely: emscripten-core#22155.
This reduces the size of several structs and results in code size savings in some cases. This change is split of from a larger change I have planned to remove the use of EM_BOOL completely: emscripten-core#22155.
This reduces the size of several structs and can result in code size savings in some cases. The reason the code size savings don't show up in trivial examples is (I believe) because this change also increases the use of HEAP8 (where previously some examples only depended on HEAP32). This change is split of from a larger change I have planned to remove the use of EM_BOOL completely: #22155.
Rebased now that #22157 has landed. I'm planning on waiting for a release or two before landing this larger change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm in a separate release as you said.
Also, do we have a test that EM_BOOL, EM_TRUE, EM_FALSE
still work as legacy?
There is no need that I can think of to use a custom type/macro here. This also reduces the size of several structs due to the fact that the C/C++ bool type is smaller than int. Keep EM_BOOL/EM_TRUE/EM_FALSE around for backwards compat but don't use them internally anymore.
Added a test. |
Thanks - which is it though? (this is a pretty big diff and I don't see a separate commit for it, this would have been a nice case to not squash actually I think?) |
Added test as a separate commit |
Thanks, lgtm. |
There is no need that I can think of to use a custom type/macro here.
This also reduces the size of several structs due to the fact that
the C/C++ bool type is smaller than int.
Keep EM_BOOL/EM_TRUE/EM_FALSE around for backwards compat but don't use them internally anymore.