-
Notifications
You must be signed in to change notification settings - Fork 279
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
Add modular exponentiation benchmark #367
Merged
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# ARGS: 4 13 497 | ||
@main (base: int, exp: int, mod: int){ | ||
out: int = call @mod_pow base exp mod; | ||
print out; | ||
} | ||
@mod_pow(b: int, e: int, m: int): int { | ||
v1: int = id m; | ||
v2: int = const 1; | ||
v3: bool = eq v1 v2; | ||
br v3 .then.0 .else.0; | ||
.then.0: | ||
v4: int = const 0; | ||
ret v4; | ||
.else.0: | ||
v5: int = const 1; | ||
result: int = id v5; | ||
v6: int = id b; | ||
v7: int = id m; | ||
base: int = call @mod v6 v7; | ||
base: int = id base; | ||
v9: int = id e; | ||
exp: int = id v9; | ||
.for.cond.8: | ||
v10: int = id exp; | ||
v11: int = const 0; | ||
v12: bool = gt v10 v11; | ||
br v12 .for.body.8 .for.end.8; | ||
.for.body.8: | ||
v13: int = id exp; | ||
v14: int = const 2; | ||
bit: int = call @mod v13 v14; | ||
bit: int = id bit; | ||
v16: int = id bit; | ||
v17: int = const 1; | ||
v18: bool = eq v16 v17; | ||
br v18 .then.15 .else.15; | ||
.then.15: | ||
v19: int = id result; | ||
v20: int = id base; | ||
v21: int = mul v19 v20; | ||
result: int = id v21; | ||
v22: int = id result; | ||
v23: int = id m; | ||
v24: int = call @mod v22 v23; | ||
result: int = id v24; | ||
jmp .endif.15; | ||
.else.15: | ||
.endif.15: | ||
v25: int = id base; | ||
v26: int = id base; | ||
v27: int = mul v25 v26; | ||
base: int = id v27; | ||
v28: int = id base; | ||
v29: int = id m; | ||
v30: int = call @mod v28 v29; | ||
base: int = id v30; | ||
v31: int = id exp; | ||
v32: int = const 2; | ||
v33: int = div v31 v32; | ||
exp: int = id v33; | ||
jmp .for.cond.8; | ||
.for.end.8: | ||
v34: int = id result; | ||
ret v34; | ||
} | ||
@mod(n: int, m: int): int { | ||
v0: int = id n; | ||
v1: int = id n; | ||
v2: int = id m; | ||
v3: int = div v1 v2; | ||
v4: int = id m; | ||
v5: int = mul v3 v4; | ||
v6: int = sub v0 v5; | ||
ret v6; | ||
} |
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 @@ | ||
445 |
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 @@ | ||
total_dyn_inst: 243 |
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
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.
This already links to the Wikipedia article, so no need to say it again. 😃