Skip to content

Add a raw C loop that calculates "itersum" without any context-switching.#28

Open
ezrakilty wants to merge 1 commit intomainfrom
itersum_raw
Open

Add a raw C loop that calculates "itersum" without any context-switching.#28
ezrakilty wants to merge 1 commit intomainfrom
itersum_raw

Conversation

@ezrakilty
Copy link
Copy Markdown
Contributor

This is the "speed of light"

Comment thread examples/itersum_raw.c
Comment on lines +12 to +16
int32_t result = 0, i = 0;

while (i++ < max) {
result += (int32_t)(intptr_t)i;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this may work with -O2:

Suggested change
int32_t result = 0, i = 0;
while (i++ < max) {
result += (int32_t)(intptr_t)i;
}
int32_t result = 0;
for (int32_t i = 0; i < max; ++i) {
__asm__("local.get %1\n"
"local.get %2\n"
"i32.add\n"
"local.set %2\n"
: "=r"(result) : "r"(i), "r"(result));
}

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.

2 participants