-
Notifications
You must be signed in to change notification settings - Fork 30
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
Fix const-window argument passing #288
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
|
||
#pragma once | ||
#ifndef TEST_H | ||
#define TEST_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
|
||
#include <stdint.h> | ||
#include <stdbool.h> | ||
|
||
// Compiler feature macros adapted from Hedley (public domain) | ||
// https://github.com/nemequ/hedley | ||
|
||
#if defined(__has_builtin) | ||
# define EXO_HAS_BUILTIN(builtin) __has_builtin(builtin) | ||
#else | ||
# define EXO_HAS_BUILTIN(builtin) (0) | ||
#endif | ||
|
||
#if EXO_HAS_BUILTIN(__builtin_assume) | ||
# define EXO_ASSUME(expr) __builtin_assume(expr) | ||
#elif EXO_HAS_BUILTIN(__builtin_unreachable) | ||
# define EXO_ASSUME(expr) \ | ||
((void)((expr) ? 1 : (__builtin_unreachable(), 1))) | ||
#else | ||
# define EXO_ASSUME(expr) ((void)(expr)) | ||
#endif | ||
|
||
|
||
struct exo_win_1f32{ | ||
float * const data; | ||
const int_fast32_t strides[1]; | ||
}; | ||
// caller( | ||
|
||
// ) | ||
void caller( void *ctxt ); | ||
|
||
|
||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif // TEST_H | ||
#include "test.h" | ||
|
||
|
||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
|
||
// callee( | ||
// N : size, | ||
// A : [f32][N] @DRAM | ||
// ) | ||
static void callee( void *ctxt, int_fast32_t N, struct exo_win_1f32 A ); | ||
|
||
// callee( | ||
// N : size, | ||
// A : [f32][N] @DRAM | ||
// ) | ||
static void callee( void *ctxt, int_fast32_t N, struct exo_win_1f32 A ) { | ||
for (int i = 0; i < N; i++) { | ||
A.data[(i) * (A.strides[0])] = 0.0; | ||
} | ||
} | ||
|
||
// caller( | ||
|
||
// ) | ||
void caller( void *ctxt ) { | ||
float *A = malloc(10 * sizeof(*A)); | ||
callee(ctxt,10,(struct exo_win_1f32){ &A[(0) * (1)], { 1 } }); | ||
free(A); | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
In this test and the others, these structs aren't actually used anywhere. I'm guessing they come from instr signatures, but I'm not totally sure.
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.
Just curious, was there any warning or performance consequence from not having const?
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.
Nothing we rigorously measured. But there are still a great many reasons for having const.
const
enables the C compiler to check our generated code. If we misplace a const the C compiler will warn or error, and that means our analysis somewhere is wrong. This helps us catch bugs.const
information makes it easier to integrate into existing C codebases. For instance, someone might have a const-qualified buffer in their program. They would have to cast away that const to call an Exo function. That's a recipe for unexpected / undefined behavior.and so on...