Last active
June 4, 2019 03:13
-
-
Save kaityo256/95276045de818bb899c1ea0b03f41f8c to your computer and use it in GitHub Desktop.
Constant folding and loop unrolling
This file contains hidden or 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
| n = ARGV[0].to_i | |
| s = (1..n).to_a.map { |i| i.to_s }.join(",") | |
| s = "{" + s + "}" | |
| puts <<"EOS" | |
| #include <cstdio> | |
| const int N = #{n}; | |
| const int a[] = #{s}; | |
| int func(int b[N]) { | |
| int sum = 0; | |
| for (int i = 0; i < N; i++) { | |
| sum += a[i] * b[i]; | |
| } | |
| return sum; | |
| } | |
| int main() { | |
| int b[] = #{s}; | |
| printf("%d\\n", func(b)); | |
| } | |
| EOS |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ ruby dump.rb 10 > test.cpp $ clang++ -O3 test.cpp -S