Skip to content
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

Codegen cleanup #240

Merged
merged 9 commits into from
Oct 13, 2022
Merged

Codegen cleanup #240

merged 9 commits into from
Oct 13, 2022

Conversation

alexreinking
Copy link
Contributor

@alexreinking alexreinking commented Oct 4, 2022

Add const to function signatures

When a function does not write or accumulate to a parameter it's passed, it should tell the C compiler about this by declaring it const. In some cases that can promote inlining or better codegen and definitely improves the ergonomics of using exo functions by allowing callers to declare their local variables const in the first place. It also plays nicer with C's type system generally.

Use void instead of an empty struct

This prevents an actual ABI issue whereby a C compiler is allowed to give such a struct a size of 0, but C++ must give it a size of 1.

Fixes #95

Only generate _floor_div and _clamp_32to8 when needed.

Self-explanatory. Also uses exo_ prefixes since leading underscores are generally sketchy in C.

@alexreinking alexreinking marked this pull request as ready for review October 4, 2022 20:07
@alexreinking alexreinking changed the title Add const to function signatures Codegen cleanup Oct 4, 2022
@alexreinking alexreinking enabled auto-merge (squash) October 13, 2022 20:12
@@ -396,7 +392,7 @@ gemmini_extended_compute_preloaded((uint32_t)(&*(int8_t*)((uint64_t)( ((uint32_t
}
}
if (orow_ii + 7 * orow_io == 0 || false) {
gemmini_extended4_config_ld(((struct exo_win_2i8){ (int8_t*)&inp[(b) * (58 * 58 * 64) + (1 + orow_ii + 7 * orow_io + 28 * orow_o) * (58 * 64) + (2 + 16 * ocol_o) * (64) + (0) * (1)], { 64, 1 } }).strides[0]*1, 1.0f, 0, (16), 2);
gemmini_extended4_config_ld(((struct exo_win_2i8c){ &inp[(b) * (58 * 58 * 64) + (1 + orow_ii + 7 * orow_io + 28 * orow_o) * (58 * 64) + (2 + 16 * ocol_o) * (64) + (0) * (1)], { 64, 1 } }).strides[0]*1, 1.0f, 0, (16), 2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does c stands for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Const

@yamaguchi1024
Copy link
Member

Great changes!!
Were we able to remove some of the -fno- 's in the cmake scripts for Gemmini as a result?

@alexreinking
Copy link
Contributor Author

Not yet. That will be my next PR or two

Copy link
Member

@yamaguchi1024 yamaguchi1024 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@alexreinking alexreinking merged commit 3574214 into master Oct 13, 2022
@alexreinking alexreinking deleted the codegen/const-correctness branch October 13, 2022 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Empty structs differ in C/C++
2 participants