├── .gitignore ├── Makefile ├── README.md ├── reorder.py └── testcases ├── lv1 ├── 0_main.c ├── 1_comments.c ├── 2_int_dec.c ├── 3_int_oct.c ├── 4_int_hex.c ├── 5_compact.c └── 6_whitespaces.c ├── lv3 ├── 00_pos.c ├── 01_neg_0.c ├── 02_neg_2.c ├── 03_neg_max.c ├── 04_not_0.c ├── 05_not_10.c ├── 06_complex_unary.c ├── 07_add.c ├── 08_add_neg.c ├── 09_sub.c ├── 10_sub_neg.c ├── 11_mul.c ├── 12_mul_neg.c ├── 13_div.c ├── 14_div_neg.c ├── 15_mod.c ├── 16_mod_neg.c ├── 17_lt.c ├── 18_gt.c ├── 19_le.c ├── 20_ge.c ├── 21_eq.c ├── 22_ne.c ├── 23_lor.c ├── 24_land.c ├── 25_int_min.c ├── 26_parentheses.c └── 27_complex_binary.c ├── lv4 ├── 00_const.c ├── 01_const_expr.c ├── 02_multiple_consts.c ├── 03_complex_const.c ├── 04_var.c ├── 05_var_init.c ├── 06_var_expr.c ├── 07_var_main.c ├── 08_multiple_vars.c ├── 09_complex_vars.c ├── 10_assign.c ├── 11_assign_read.c ├── 12_multiple_assigns.c └── 13_complex.c ├── lv5 ├── 0_block.c ├── 1_ret_from_block.c ├── 2_blocks.c ├── 3_exp.c ├── 4_empty_exp.c ├── 5_scope.c └── 6_complex_scopes.c ├── lv6 ├── 0_if.c ├── 1_if_else.c ├── 2_multiple_if_else.c ├── 3_nested_if.c ├── 4_logical.c ├── 5_more_logical.c ├── 6_multiple_returns.c └── 7_complex.c ├── lv7 ├── 00_while.c ├── 01_while_pow.c ├── 02_while_false.c ├── 03_while_true.c ├── 04_while_if.c ├── 05_if_while.c ├── 06_nested_while.c ├── 07_break.c ├── 08_if_break.c ├── 09_continue.c ├── 10_if_continue.c └── 11_complex.c ├── lv8 ├── 00_int_func.c ├── 01_void_func.c ├── 02_params.c ├── 03_more_params.c ├── 04_param_name.c ├── 05_func_name.c ├── 06_complex_call.c ├── 07_recursion.c ├── 08_lib_funcs.c ├── 08_lib_funcs.in ├── 09_globals.c ├── 10_complex.c └── 11_short_circuit.c ├── lv9 ├── 00_local_arr_1d.c ├── 01_local_arr_nd.c ├── 02_global_arr.c ├── 03_arr_init_1d.c ├── 04_arr_init_nd.c ├── 05_global_arr_init.c ├── 06_long_array.c ├── 07_const_array.c ├── 08_arr_access.c ├── 09_const_arr_read.c ├── 10_arr_in_loop.c ├── 11_arr_params.c ├── 12_more_arr_params.c ├── 13_complex_arr_params.c ├── 14_arr_lib_funcs.c ├── 14_arr_lib_funcs.in ├── 15_sort1.c ├── 16_sort2.c ├── 17_sort3.c ├── 18_sort4.c ├── 19_sort5.c ├── 20_sort6.c ├── 21_sort7.c └── 21_sort7.in └── perf ├── 00_bitset1.c ├── 00_bitset1.in ├── 01_bitset2.c ├── 01_bitset2.in ├── 02_bitset3.c ├── 02_bitset3.in ├── 03_mm1.c ├── 03_mm1.in ├── 04_mm2.c ├── 04_mm2.in ├── 05_mm3.c ├── 05_mm3.in ├── 06_mv1.c ├── 06_mv1.in ├── 07_mv2.c ├── 07_mv2.in ├── 08_mv3.c ├── 08_mv3.in ├── 09_spmv1.c ├── 09_spmv1.in ├── 10_spmv2.c ├── 10_spmv2.in ├── 11_spmv3.c ├── 11_spmv3.in ├── 12_fft0.c ├── 12_fft0.in ├── 13_fft1.c ├── 13_fft1.in ├── 14_fft2.c ├── 14_fft2.in ├── 15_transpose0.c ├── 15_transpose0.in ├── 16_transpose1.c ├── 16_transpose1.in ├── 17_transpose2.c ├── 17_transpose2.in ├── 18_brainfuck-bootstrap.c ├── 18_brainfuck-bootstrap.in ├── 19_brainfuck-calculator.c └── 19_brainfuck-calculator.in /.gitignore: -------------------------------------------------------------------------------- 1 | # macOS 2 | *.DS_Store 3 | 4 | # VS Code 5 | .vscode 6 | 7 | # debugging 8 | debug 9 | 10 | # building 11 | build 12 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # install directory 2 | INSTALL_DIR ?= 3 | 4 | # library directory 5 | LIB_DIR ?= 6 | 7 | # C compiler 8 | CFLAGS := -Wall -Werror 9 | CFLAGS += -Wno-implicit-function-declaration -Wno-unused-variable 10 | CFLAGS += -Wno-unused-value -Wno-dangling-else -Wno-logical-op-parentheses 11 | CFLAGS += -Wno-empty-body -Wno-missing-braces -Wno-constant-logical-operand 12 | CFLAGS += -Wno-tautological-overlap-compare -Wno-unused-but-set-variable 13 | CFLAGS += -Wno-gnu-folding-constant 14 | CFLAGS += -O3 -fsanitize=address -fsanitize=undefined 15 | CC := clang $(CFLAGS) 16 | 17 | # directories 18 | TOP_DIR := $(shell pwd) 19 | TEST_CASES_DIR := $(TOP_DIR)/testcases 20 | BUILD_DIR := $(TOP_DIR)/build 21 | 22 | # files 23 | TEST_SRC := $(shell find $(TEST_CASES_DIR) -name '*.c') 24 | TEST_IN := $(shell find $(TEST_CASES_DIR) -name '*.in') 25 | 26 | # targets 27 | TEST_EXEC := $(patsubst $(TEST_CASES_DIR)/%.c, $(BUILD_DIR)/%, $(TEST_SRC)) 28 | TEST_OUT := $(patsubst $(TEST_CASES_DIR)/%.c, $(BUILD_DIR)/%.out, $(TEST_SRC)) 29 | INSTALL_SRC := $(patsubst $(TEST_CASES_DIR)/%.c, $(INSTALL_DIR)/%.c, $(TEST_SRC)) 30 | INSTALL_IN := $(patsubst $(TEST_CASES_DIR)/%.in, $(INSTALL_DIR)/%.in, $(TEST_IN)) 31 | INSTALL_OUT := $(patsubst $(TEST_CASES_DIR)/%.c, $(INSTALL_DIR)/%.out, $(TEST_SRC)) 32 | 33 | 34 | .PHONY: all install clean check-install-dir check-lib-dir 35 | 36 | all: check-lib-dir $(TEST_OUT) 37 | 38 | install: check-install-dir check-lib-dir $(INSTALL_SRC) $(INSTALL_IN) $(INSTALL_OUT) 39 | 40 | clean: 41 | -rm -rf $(BUILD_DIR) 42 | 43 | check-install-dir: 44 | ifeq ($(INSTALL_DIR),) 45 | $(error "INSTALL_DIR must be set") 46 | endif 47 | 48 | check-lib-dir: 49 | ifeq ($(LIB_DIR),) 50 | $(error "LIB_DIR must be set") 51 | endif 52 | 53 | $(BUILD_DIR)/%.out: $(BUILD_DIR)/% $(TEST_CASES_DIR)/%.in 54 | mkdir -p $(dir $@) 55 | $< < $(word 2, $^) > $@; ret=$$?; if [ -z "$$(tail -c 1 "$@")" ]; then echo "$$ret" >> "$@"; else printf "\n$$ret\n" >> "$@"; fi 56 | 57 | $(BUILD_DIR)/%.out: $(BUILD_DIR)/% 58 | mkdir -p $(dir $@) 59 | $^ > $@; ret=$$?; if [ -z "$$(tail -c 1 "$@")" ]; then echo "$$ret" >> "$@"; else printf "\n$$ret\n" >> "$@"; fi 60 | 61 | $(BUILD_DIR)/%: $(TEST_CASES_DIR)/%.c $(LIB_DIR)/libsysy.a 62 | mkdir -p $(dir $@) 63 | $(CC) $^ -o $@ -L$(LIB_DIR) -lsysy 64 | 65 | $(INSTALL_DIR)/%.c: $(TEST_CASES_DIR)/%.c 66 | mkdir -p $(dir $@) 67 | cp $^ $@ 68 | 69 | $(INSTALL_DIR)/%.in: $(TEST_CASES_DIR)/%.in 70 | mkdir -p $(dir $@) 71 | cp $^ $@ 72 | 73 | $(INSTALL_DIR)/%.out: $(BUILD_DIR)/%.out 74 | mkdir -p $(dir $@) 75 | cp $^ $@ 76 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # compiler-dev-test-cases 2 | 3 | 为 SysY 编译器设计的本地测试用例, 已经包含于[编译器开发环境](https://github.com/pku-minic/compiler-dev). 4 | 5 | `testcases` 目录内存放了测试用例的源文件, 并且已经按照[编译实践在线文档](https://pku-minic.github.io/online-doc/)的章节划分分类. 6 | 7 | ## 使用方法 8 | 9 | 由于 `compiler-dev` 已经包含了全部测试用例, 我们不建议你直接使用该仓库. 10 | 11 | 如果你需要另行构建测试用例, 可以执行: 12 | 13 | ```sh 14 | LIB_DIR="SysY运行时库目录" INSTALL_DIR="测试用例安装目录" make install -j`nproc` 15 | ``` 16 | 17 | `make` 将使用 `clang` 编译并运行所有测试用例, 自动获取参考输出, 然后将测试用例及参考输入/输出复制至 `INSTALL_DIR`. 18 | 19 | ## 其他测试用例 20 | 21 | 本仓库只包含了一些结构较为简单的 SysY 测试用例, 如果你想进一步测试你的 SysY 编译器, 请参考之前版本的[开放测试用例仓库](https://github.com/pku-minic/open-test-cases). 22 | -------------------------------------------------------------------------------- /reorder.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | ''' 4 | Scan all test cases ('*.c'), rename each test case to the format 5 | '{id}_name.c', and make sure they all have unique and continuous ids. 6 | 7 | Usage: 8 | reorder.py # reorder all files in directories in the configuration 9 | reorder.py DIR # reorder all files in DIR 10 | reorder.py DIR COUNT # reorder all files in DIR, start counting from COUNT 11 | ''' 12 | 13 | import os 14 | import re 15 | 16 | 17 | # ========== configurations begin ========== 18 | test_case_dirs = [ 19 | 'testcases', 20 | ] 21 | # ========== configurations end ========== 22 | 23 | __NAME_PATTERN = re.compile(r'(\d+_)?(.+).c') 24 | 25 | 26 | def get_id(zero_count: int, count: int) -> str: 27 | id = str(count) 28 | assert zero_count >= len(id) 29 | return (zero_count - len(id)) * '0' + id 30 | 31 | 32 | def rename_file(root: str, old_name: str, new_name: str): 33 | cur_file = os.path.join(root, old_name) 34 | new_file = os.path.join(root, new_name) 35 | os.rename(cur_file, new_file) 36 | 37 | 38 | def scan_and_rename(dir: str, start_count: int = 0): 39 | for root, _, files in os.walk(dir): 40 | cases = [f for f in sorted(files) if f.endswith('.c')] 41 | zeros = len(str(len(cases) + start_count - 1)) 42 | count = start_count 43 | for f in cases: 44 | cur_id = get_id(zeros, count) 45 | # rename test case 46 | case_name = __NAME_PATTERN.findall(f)[0][1] 47 | new_case_name = f'{cur_id}_{case_name}.c' 48 | rename_file(root, f, new_case_name) 49 | # check & rename test input 50 | in_name = f'{f[:-2]}.in' 51 | if os.path.exists(os.path.join(root, in_name)): 52 | new_in_name = f'{cur_id}_{case_name}.in' 53 | rename_file(root, in_name, new_in_name) 54 | count += 1 55 | 56 | 57 | if __name__ == '__main__': 58 | import sys 59 | if len(sys.argv) >= 2: 60 | start_count = 0 61 | if len(sys.argv) >= 3: 62 | start_count = int(sys.argv[2]) 63 | scan_and_rename(sys.argv[1], start_count) 64 | else: 65 | for i in test_case_dirs: 66 | scan_and_rename(i) 67 | -------------------------------------------------------------------------------- /testcases/lv1/0_main.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 0; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv1/1_comments.c: -------------------------------------------------------------------------------- 1 | /* This is a comment. */ 2 | 3 | int main() { 4 | // This is also a comment. 5 | return 3; 6 | } 7 | -------------------------------------------------------------------------------- /testcases/lv1/2_int_dec.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 2077; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv1/3_int_oct.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 01234; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv1/4_int_hex.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 0x133fAb; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv1/5_compact.c: -------------------------------------------------------------------------------- 1 | int main(){return 1;} -------------------------------------------------------------------------------- /testcases/lv1/6_whitespaces.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int 4 | 5 | 6 | main() 7 | { return 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 6 17 | 18 | 19 | ; 20 | 21 | } 22 | 23 | -------------------------------------------------------------------------------- /testcases/lv3/00_pos.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return +2; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/01_neg_0.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return -0; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/02_neg_2.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return -2; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/03_neg_max.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return -2147483647; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/04_not_0.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return !0; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/05_not_10.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return !10; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/06_complex_unary.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return +-+!(!-10000); 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/07_add.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 1 + 2; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/08_add_neg.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 1 + -2; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/09_sub.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 1 - 2; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/10_sub_neg.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 1 - -2; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/11_mul.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 2 * 4; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/12_mul_neg.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 2 * -4; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/13_div.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 10 / 2; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/14_div_neg.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 10 / -3; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/15_mod.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 7 % 4; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/16_mod_neg.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 7 % -4; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/17_lt.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 1 < 2; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/18_gt.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 9 > 10; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/19_le.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 9 <= 3; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/20_ge.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 10 >= 7; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/21_eq.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 1 == 2; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/22_ne.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 1 != 0; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/23_lor.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 11 || 0; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/24_land.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 2 && 4; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/25_int_min.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return -2147483647 - 1; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/26_parentheses.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 1 + 2 * (3 + 4); 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv3/27_complex_binary.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 1 + 2 * (!3 || 4) < 5 != 6 && -7; 3 | } 4 | -------------------------------------------------------------------------------- /testcases/lv4/00_const.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | const int x = 1; 3 | return x; 4 | } 5 | -------------------------------------------------------------------------------- /testcases/lv4/01_const_expr.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | const int x = 1 + 2 * 3 - 4; 3 | return x; 4 | } 5 | -------------------------------------------------------------------------------- /testcases/lv4/02_multiple_consts.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | const int x = 2, y = x + 1, z = x * y; 3 | return z; 4 | } 5 | -------------------------------------------------------------------------------- /testcases/lv4/03_complex_const.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | const int x = 1 * 2 || 2 * 3 && 3 * 4; 3 | const int y = x * 3 > 10; 4 | return y + 4 - x; 5 | } 6 | -------------------------------------------------------------------------------- /testcases/lv4/04_var.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x; 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /testcases/lv4/05_var_init.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 1; 3 | return x; 4 | } 5 | -------------------------------------------------------------------------------- /testcases/lv4/06_var_expr.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 1; 3 | return x + 1; 4 | } 5 | -------------------------------------------------------------------------------- /testcases/lv4/07_var_main.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int main = 10; 3 | return main; 4 | } 5 | -------------------------------------------------------------------------------- /testcases/lv4/08_multiple_vars.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 1, y = 2, z = 3; 3 | return x + y + z; 4 | } 5 | -------------------------------------------------------------------------------- /testcases/lv4/09_complex_vars.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 10; 3 | int y = x + 1; 4 | int z = x * y + 1; 5 | return z % 66; 6 | } 7 | -------------------------------------------------------------------------------- /testcases/lv4/10_assign.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x; 3 | x = 1; 4 | return x; 5 | } 6 | -------------------------------------------------------------------------------- /testcases/lv4/11_assign_read.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 1; 3 | x = x + 1; 4 | return x; 5 | } 6 | -------------------------------------------------------------------------------- /testcases/lv4/12_multiple_assigns.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int y; 3 | y = 1; 4 | int x; 5 | x = y + 1; 6 | return x; 7 | } 8 | -------------------------------------------------------------------------------- /testcases/lv4/13_complex.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x; 3 | const int k = 10 + 11; 4 | int y = k; 5 | x = y + 1; 6 | const int n = k * 7; 7 | int z = n - x, w = n - y; 8 | w = w * 1 * 1 * 1; 9 | return z + w; 10 | } 11 | -------------------------------------------------------------------------------- /testcases/lv5/0_block.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | {} 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /testcases/lv5/1_ret_from_block.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | { 3 | return 20; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /testcases/lv5/2_blocks.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | {{{}}} 3 | {} {} 4 | { 5 | { } { 6 | {} 7 | } 8 | } {} { 9 | {{}} { } {} { 10 | {} 11 | } 12 | } 13 | return 1; 14 | } 15 | -------------------------------------------------------------------------------- /testcases/lv5/3_exp.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | 1 + 2; 3 | return 1; 4 | } 5 | -------------------------------------------------------------------------------- /testcases/lv5/4_empty_exp.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | ; 3 | return 6; 4 | } 5 | -------------------------------------------------------------------------------- /testcases/lv5/5_scope.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int a = 1; 3 | { 4 | a = a + 2; 5 | int a = 3; 6 | a = a + 4; 7 | } 8 | a = a + 5; 9 | return a; 10 | } 11 | -------------------------------------------------------------------------------- /testcases/lv5/6_complex_scopes.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int a = 1, sum = 0; 3 | { 4 | a = a + 2; 5 | int b = a + 3; 6 | b = b + 4; 7 | sum = sum + a + b; 8 | { 9 | b = b + 5; 10 | int c = b + 6; 11 | a = a + c; 12 | sum = sum + a + b + c; 13 | { 14 | b = b + a; 15 | int a = c + 7; 16 | a = a + 8; 17 | sum = sum + a + b + c; 18 | { 19 | b = b + a; 20 | int b = c + 9; 21 | a = a + 10; 22 | const int a = 11; 23 | b = b + 12; 24 | sum = sum + a + b + c; 25 | { 26 | c = c + b; 27 | int c = b + 13; 28 | c = c + a; 29 | sum = sum + a + b + c; 30 | } 31 | sum = sum - c; 32 | } 33 | sum = sum - b; 34 | } 35 | sum = sum - a; 36 | } 37 | } 38 | return sum % 77; 39 | } 40 | -------------------------------------------------------------------------------- /testcases/lv6/0_if.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | if (1) return 1; 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /testcases/lv6/1_if_else.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | if (0) return 1; 3 | else return 2; 4 | return 3; 5 | } 6 | -------------------------------------------------------------------------------- /testcases/lv6/2_multiple_if_else.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int a = 10; 3 | if (a > 1) 4 | if (a > 2) 5 | if (a < 3) 6 | return a; 7 | else 8 | if (a > 4) 9 | if (a < 5) 10 | return a + 1; 11 | else 12 | return a + 2; 13 | return -1; 14 | } 15 | -------------------------------------------------------------------------------- /testcases/lv6/3_nested_if.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int a = 10; 3 | if (a > 1) { 4 | a = a - 1; 5 | int a = 5; 6 | if (a < -1) { 7 | return 10; 8 | } else { 9 | int a; 10 | a = 98; 11 | } 12 | } 13 | if (a == 9) { 14 | int b = a - 1; 15 | int a = b - 1; 16 | if (a != b) { 17 | if (!a) { 18 | return 0; 19 | } 20 | return a; 21 | } else { 22 | return b; 23 | } 24 | } 25 | return -1; 26 | } 27 | -------------------------------------------------------------------------------- /testcases/lv6/4_logical.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int a = 1, b = 0; 3 | if (a || b) { 4 | b = 1; 5 | a = 0; 6 | } 7 | if (a && b) { 8 | return 0; 9 | } 10 | return 77; 11 | } 12 | -------------------------------------------------------------------------------- /testcases/lv6/5_more_logical.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int a = 1 || 2 && 3; 3 | int b = 0 && 1 || 0; 4 | int c = (1 && 0 || 1) * 4; 5 | int d = 5; 6 | const int e = 6 || 7 && 8; 7 | if (a == 1 || a == 2); 8 | if (b == 0 || b == 1) d = d + 1; else; 9 | if (a && b || c && d) d = d + e; 10 | return d || !c; 11 | return d || e; 12 | } 13 | -------------------------------------------------------------------------------- /testcases/lv6/6_multiple_returns.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 5; 3 | return 4; 4 | return 3; 5 | } 6 | -------------------------------------------------------------------------------- /testcases/lv6/7_complex.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int a = 0; 3 | const int b = 1 - 1 * 2 + 1; 4 | int c = 1, d = 2; 5 | if (a || b) { 6 | c = 3; 7 | } else { 8 | d = 3; 9 | int a = 1; 10 | if (a || b) { 11 | c = 4; 12 | } else { 13 | d = 4; 14 | } 15 | if (a == 0) return 1; 16 | else if (a == 0 && a == -1) return 2; 17 | } 18 | return a + b + c + d; 19 | } 20 | -------------------------------------------------------------------------------- /testcases/lv7/00_while.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int i = 0; 3 | while (i < 10) i = i + 1; 4 | return i; 5 | } 6 | -------------------------------------------------------------------------------- /testcases/lv7/01_while_pow.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int i = 0, pow = 1; 3 | while (i < 7) { 4 | pow = pow * 2; 5 | i = i + 1; 6 | } 7 | return pow; 8 | } 9 | -------------------------------------------------------------------------------- /testcases/lv7/02_while_false.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int a = 0; 3 | while (0) a = 1; 4 | return a; 5 | } 6 | -------------------------------------------------------------------------------- /testcases/lv7/03_while_true.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | while (1) return 1; 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /testcases/lv7/04_while_if.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int i = 0, sum = 0; 3 | while (i < 10) { 4 | if (i == 5) { 5 | sum = sum + 1; 6 | } else { 7 | sum = sum + i; 8 | } 9 | if (sum > 10) sum = sum - 1; 10 | i = i + 1; 11 | } 12 | return sum; 13 | } 14 | -------------------------------------------------------------------------------- /testcases/lv7/05_if_while.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int a = 1; 3 | if (a > 1) { 4 | while (1); 5 | } else { 6 | while (a < 10) { 7 | a = a + 2; 8 | } 9 | } 10 | return a; 11 | } 12 | -------------------------------------------------------------------------------- /testcases/lv7/06_nested_while.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int a = 1, b = 2; 3 | while (a < 10) { 4 | a = a + 1; 5 | while (a < 5 && b < 10) { 6 | b = b + 1; 7 | } 8 | while (b < 20) { 9 | while (b < 6 || b == 6) { 10 | b = b + 1; 11 | } 12 | b = b + 2; 13 | } 14 | } 15 | return a + b; 16 | } 17 | -------------------------------------------------------------------------------- /testcases/lv7/07_break.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | while (1) break; 3 | return 2; 4 | } 5 | -------------------------------------------------------------------------------- /testcases/lv7/08_if_break.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int i = 0; 3 | while (i < 10) { 4 | if (i == 5) { 5 | break; 6 | } 7 | i = i + 1; 8 | } 9 | return i; 10 | } 11 | -------------------------------------------------------------------------------- /testcases/lv7/09_continue.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int i = 0; 3 | while (i < 10) { 4 | i = 20; 5 | continue; 6 | i = i + 1; 7 | } 8 | return i; 9 | } 10 | -------------------------------------------------------------------------------- /testcases/lv7/10_if_continue.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int i = 0, sum = 0; 3 | while (i < 10) { 4 | if (i == 5) { 5 | sum = sum + 7; 6 | i = i + 1; 7 | continue; 8 | } 9 | sum = sum + i; 10 | i = i + 1; 11 | } 12 | return sum; 13 | } 14 | -------------------------------------------------------------------------------- /testcases/lv7/11_complex.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | while (1) { 3 | int a = 1, b = 2; 4 | { 5 | if (a == 1) { 6 | while (a < b) { 7 | while (a < b || b - 1 == 0) { 8 | a = a + 1; 9 | } 10 | b = 1; 11 | a = a + 1; 12 | if (3) continue; 13 | } 14 | } else if (b == 6) { 15 | break; 16 | } 17 | int b = 6; 18 | if (b == 6) return 8 * (10 || b); 19 | else while (0); 20 | } 21 | } 22 | return -1; 23 | } 24 | -------------------------------------------------------------------------------- /testcases/lv8/00_int_func.c: -------------------------------------------------------------------------------- 1 | int f() { 2 | return 0; 3 | } 4 | 5 | int main() { 6 | return f(); 7 | } 8 | -------------------------------------------------------------------------------- /testcases/lv8/01_void_func.c: -------------------------------------------------------------------------------- 1 | void f() {} 2 | 3 | int main() { 4 | f(); 5 | return 1; 6 | } 7 | -------------------------------------------------------------------------------- /testcases/lv8/02_params.c: -------------------------------------------------------------------------------- 1 | int add(int a, int b) { 2 | return a + b; 3 | } 4 | 5 | int main() { 6 | return add(1, 2); 7 | } 8 | -------------------------------------------------------------------------------- /testcases/lv8/03_more_params.c: -------------------------------------------------------------------------------- 1 | int sum(int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7) { 2 | return a0 + a1 + a2 + a3 + a4 + a5 + a6 + a7; 3 | } 4 | 5 | int sum2(int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, 6 | int a9, int a10, int a11, int a12, int a13, int a14, int a15) { 7 | return a0 + a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12 + 8 | a13 + a14 + a15; 9 | } 10 | 11 | int main() { 12 | int x = sum(1, 2, 3, 4, 5, 6, 7, 8); 13 | int y = sum2(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); 14 | return x + y; 15 | } 16 | -------------------------------------------------------------------------------- /testcases/lv8/04_param_name.c: -------------------------------------------------------------------------------- 1 | int f(int f) { 2 | return f * 2; 3 | } 4 | 5 | int main() { 6 | return f(10); 7 | } 8 | -------------------------------------------------------------------------------- /testcases/lv8/05_func_name.c: -------------------------------------------------------------------------------- 1 | int f() { 2 | return 10; 3 | } 4 | 5 | int main() { 6 | int f = 20; 7 | return f; 8 | } 9 | -------------------------------------------------------------------------------- /testcases/lv8/06_complex_call.c: -------------------------------------------------------------------------------- 1 | int add(int a, int b) { 2 | return a + b; 3 | } 4 | 5 | int sub(int a, int b) { 6 | return a - b; 7 | } 8 | 9 | int mul(int a, int b) { 10 | return a * b; 11 | } 12 | 13 | int div(int a, int b) { 14 | return a / b; 15 | } 16 | 17 | int main() { 18 | int x = add(sub(1, 2), mul(3, div(4, 5))); 19 | int y = add(1 || 0, 0 && sub(1, x) || mul(3, div(x || add(1, 2) > 10, 5))); 20 | return x + y; 21 | } 22 | -------------------------------------------------------------------------------- /testcases/lv8/07_recursion.c: -------------------------------------------------------------------------------- 1 | int fib(int n) { 2 | if (n < 2) { 3 | return n; 4 | } 5 | return fib(n - 1) + fib(n - 2); 6 | } 7 | 8 | int main() { 9 | return fib(20); 10 | } 11 | -------------------------------------------------------------------------------- /testcases/lv8/08_lib_funcs.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = getint(); 3 | int y = getint(); 4 | putint(x + y); 5 | int c = getch(); 6 | putch(c); 7 | putch(33); 8 | putch(10); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /testcases/lv8/08_lib_funcs.in: -------------------------------------------------------------------------------- 1 | 11 32 a 2 | -------------------------------------------------------------------------------- /testcases/lv8/09_globals.c: -------------------------------------------------------------------------------- 1 | int x; 2 | const int y = 10; 3 | const int z = y + 1; 4 | int init = 1; 5 | 6 | int main() { 7 | putint(x); 8 | putch(32); 9 | putint(y); 10 | putch(32); 11 | putint(z); 12 | putch(32); 13 | putint(init); 14 | putch(10); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /testcases/lv8/10_complex.c: -------------------------------------------------------------------------------- 1 | int a = 10; 2 | 3 | int inc() { 4 | a = a + 1; 5 | return a; 6 | } 7 | 8 | void print_a() { 9 | putint(a); 10 | putch(10); 11 | } 12 | 13 | int main() { 14 | int i = 0; 15 | while (i < 10) { 16 | inc(); 17 | int a = 1; 18 | a = a + 2; 19 | putint(a); 20 | putch(10); 21 | print_a(); 22 | i = i + 1; 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /testcases/lv8/11_short_circuit.c: -------------------------------------------------------------------------------- 1 | int x, y; 2 | 3 | int t() { 4 | x = x + 1; 5 | return 1; 6 | } 7 | 8 | int f() { 9 | y = y + 1; 10 | return 0; 11 | } 12 | 13 | int main() { 14 | int sum = 0; 15 | sum = sum + (f() || f()); 16 | sum = sum + (f() || t()); 17 | sum = sum + (t() || f()); 18 | sum = sum + (t() || t()); 19 | sum = sum + (f() && f()); 20 | sum = sum + (f() && t()); 21 | sum = sum + (t() && f()); 22 | sum = sum + (t() && t()); 23 | t() || t() && t(); 24 | f() || t() && t(); 25 | f() || f() && t(); 26 | t() && t() || t(); 27 | f() && t() || t(); 28 | f() && f() || f(); 29 | putint(x); 30 | putch(32); 31 | putint(y); 32 | putch(10); 33 | return sum; 34 | } 35 | -------------------------------------------------------------------------------- /testcases/lv9/00_local_arr_1d.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int a[10]; 3 | const int len = 10; 4 | int b[8 + 2], c, d[len]; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /testcases/lv9/01_local_arr_nd.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int a[5][6]; 3 | int b[5][6], c, d[5][6]; 4 | return 1; 5 | } 6 | -------------------------------------------------------------------------------- /testcases/lv9/02_global_arr.c: -------------------------------------------------------------------------------- 1 | int a[10]; 2 | const int len = 10; 3 | int b[8 + 2], c, d[len]; 4 | int e[5][6]; 5 | int f[5][6], g, h[5][6]; 6 | 7 | int main() { 8 | return 2; 9 | } 10 | -------------------------------------------------------------------------------- /testcases/lv9/03_arr_init_1d.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int a[3] = {}; 3 | int b[4] = {0, 1}; 4 | int c[7] = {2, 8, 6, 3, 9, 1, 5}; 5 | int d[11]; 6 | int e[2] = {22, 33}, f[6], g[9] = {85, 0, 1, 29}; 7 | return 3; 8 | } 9 | -------------------------------------------------------------------------------- /testcases/lv9/04_arr_init_nd.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int a[5][3]; 3 | int b[5][3] = {}; 4 | int c[5][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 5 | int d[5][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}, {13, 14, 15}}, 6 | e[5][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, 10, 11, 12, 13, 14, 15}; 7 | int f[5], g[5][3] = {1, 2, 3, {4}, {7}, 10, 11, 12}, h[3]; 8 | int i[2][3][4] = {1, 2, 3, 4, {5}, {}}; 9 | return 4; 10 | } 11 | -------------------------------------------------------------------------------- /testcases/lv9/05_global_arr_init.c: -------------------------------------------------------------------------------- 1 | int a0[3] = {}; 2 | int b0[4] = {0, 1}; 3 | int c0[7] = {2, 8, 6, 3, 9, 1, 5}; 4 | int d0[11]; 5 | int e0[2] = {22, 33}, f0[6], g0[9] = {85, 0, 1, 29}; 6 | 7 | int a[5][3]; 8 | int b[5][3] = {}; 9 | int c[5][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 10 | int d[5][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}, {13, 14, 15}}, 11 | e[5][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, 10, 11, 12, 13, 14, 15}; 12 | int f[5], g[5][3] = {1, 2, 3, {4}, {7}, 10, 11, 12}, h[3]; 13 | int i[2][3][4] = {1, 2, 3, 4, {5}, {}}; 14 | 15 | int main() { 16 | return 5; 17 | } 18 | -------------------------------------------------------------------------------- /testcases/lv9/06_long_array.c: -------------------------------------------------------------------------------- 1 | int arr[65536]; 2 | 3 | int main() { 4 | int arr[4096] = {1}; 5 | return arr[0]; 6 | } 7 | -------------------------------------------------------------------------------- /testcases/lv9/07_const_array.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | const int a0[3] = {}; 3 | const int b0[4] = {0, 1}; 4 | const int c0[7] = {2, 8, 6, 3, 9, 1, 5}; 5 | const int e0[2] = {22, 33}, g0[9] = {85, 0, 1, 29}; 6 | 7 | const int b[5][3] = {}; 8 | const int c[5][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 9 | const int d[5][3] = {{1, 2, 3}, 10 | {4, 5, 6}, 11 | {7, 8, 9}, 12 | {10, 11, 12}, 13 | {13, 14, 15}}, 14 | e[5][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, 10, 11, 12, 13, 14, 15}; 15 | const int g[5][3] = {1, 2, 3, {4}, {7}, 10, 11, 12}; 16 | const int i[2][3][4] = {1, 2, 3, 4, {5}, {}}; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /testcases/lv9/08_arr_access.c: -------------------------------------------------------------------------------- 1 | int ga[10], gb[2][3] = {5, 6, 7, 8}; 2 | 3 | int main() { 4 | int a[10], b[2][3] = {1, 2, 3, 4}, sum = 0; 5 | int i = 0; 6 | while (i < 2) { 7 | int j = 0; 8 | while (j < 3) { 9 | sum = sum + b[i][j] + gb[i][j]; 10 | j = j + 1; 11 | } 12 | i = i + 1; 13 | } 14 | i = 0; 15 | while (i < 10) { 16 | a[i] = sum + i; 17 | ga[i] = sum + i; 18 | i = i + 1; 19 | } 20 | return sum; 21 | } 22 | -------------------------------------------------------------------------------- /testcases/lv9/09_const_arr_read.c: -------------------------------------------------------------------------------- 1 | const int garr[10] = {6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 2 | 3 | int main() { 4 | const int arr[10] = {1, 2, 3, 4, 5}; 5 | int i = 0, sum = 0; 6 | while (i < 10) { 7 | sum = sum + arr[i] + garr[i]; 8 | i = i + 1; 9 | } 10 | return sum; 11 | } 12 | -------------------------------------------------------------------------------- /testcases/lv9/10_arr_in_loop.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int arr[10] = {1, 2, 3, 4, 5}; 3 | int i = 0; 4 | while (i < 10) { 5 | int x[10] = {}; 6 | arr[i] = arr[i] + i + x[i]; 7 | x[i] = arr[i]; 8 | i = i + 1; 9 | } 10 | return arr[9]; 11 | } 12 | -------------------------------------------------------------------------------- /testcases/lv9/11_arr_params.c: -------------------------------------------------------------------------------- 1 | void f1d(int arr[]) { 2 | int i = 0; 3 | while (i < 10) { 4 | arr[i] = i; 5 | i = i + 1; 6 | } 7 | } 8 | 9 | void f2d(int arr[][8 + 2]) { 10 | arr[1][2] = 3; 11 | int i = 0; 12 | while (i < 10) { 13 | f1d(arr[i]); 14 | i = i + 1; 15 | } 16 | } 17 | 18 | int main() { 19 | return 33; 20 | } 21 | -------------------------------------------------------------------------------- /testcases/lv9/12_more_arr_params.c: -------------------------------------------------------------------------------- 1 | void init(int arr[][10][10]) { 2 | int i = 0; 3 | while (i < 10) { 4 | int j = 0; 5 | while (j < 10) { 6 | int k = 0; 7 | while (k < 10) { 8 | arr[i][j][k] = i * 100 + j * 10 + k; 9 | k = k + 1; 10 | } 11 | j = j + 1; 12 | } 13 | i = i + 1; 14 | } 15 | } 16 | 17 | int f1(int a0[], int a1[], int a2[], int a3[], int a4[], int a5[], int a6[], 18 | int a7[], int a8[], int a9[]) { 19 | return a0[0] + a1[1] + a2[2] + a3[3] + a4[4] + a5[5] + a6[6] + a7[7] + a8[8] + 20 | a9[9]; 21 | } 22 | 23 | int f2(int a0[][10], int a1[], int a2, int a3[], int a4[], int a5[][10][10], 24 | int a6[], int a7[], int a8, int a9[][10]) { 25 | return a0[0][9] + a1[1] + a2 + a3[3] + a4[4] + a5[5][5][5] + a6[6] + a7[7] + 26 | a8 + a9[9][8]; 27 | } 28 | 29 | int main() { 30 | int arr[10][10][10], sum = 0; 31 | init(arr); 32 | sum = sum + f1(arr[0][0], arr[1][1], arr[2][2], arr[3][3], arr[4][4], 33 | arr[5][5], arr[6][6], arr[7][7], arr[8][8], arr[9][9]); 34 | sum = sum + f2(arr[0], arr[1][1], arr[2][2][2], arr[3][3], arr[4][4], arr, 35 | arr[6][6], arr[7][7], arr[8][8][8], arr[9]); 36 | putint(sum); 37 | putch(10); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /testcases/lv9/13_complex_arr_params.c: -------------------------------------------------------------------------------- 1 | int init = 0; 2 | 3 | void init1d(int n, int arr[]) { 4 | int i = 0; 5 | while (i < n) { 6 | arr[i] = init; 7 | init = init + 1; 8 | i = i + 1; 9 | } 10 | } 11 | 12 | void init2d(int n, int arr[][10]) { 13 | int i = 0; 14 | while (i < n) { 15 | init1d(10, arr[i]); 16 | i = i + 1; 17 | } 18 | } 19 | 20 | void init3d(int n, int arr[][10][10]) { 21 | int i = 0; 22 | while (i < n) { 23 | init2d(10, arr[i]); 24 | i = i + 1; 25 | } 26 | } 27 | 28 | int sum1d(int n, int arr[]) { 29 | int i = 0, sum = 0; 30 | while (i < n) { 31 | sum = sum + arr[i]; 32 | i = i + 1; 33 | } 34 | return sum; 35 | } 36 | 37 | int sum2d(int n, int arr[][10]) { 38 | int i = 0, sum = 0; 39 | while (i < n) { 40 | sum = sum + sum1d(10, arr[i]); 41 | i = i + 1; 42 | } 43 | return sum; 44 | } 45 | 46 | int sum3d(int n, int arr[][10][10]) { 47 | int i = 0, sum = 0; 48 | while (i < n) { 49 | sum = sum + sum2d(10, arr[i]); 50 | i = i + 1; 51 | } 52 | return sum; 53 | } 54 | 55 | int main() { 56 | int arr[10][10][10]; 57 | init3d(10, arr); 58 | int sum = sum3d(10, arr); 59 | sum = sum + sum2d(10, arr[1]); 60 | sum = sum + sum1d(10, arr[2][3]); 61 | putint(sum); 62 | putch(10); 63 | return sum; 64 | } 65 | -------------------------------------------------------------------------------- /testcases/lv9/14_arr_lib_funcs.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int arr[10], n = getarray(arr); 3 | int i = 0; 4 | while (i < 10) { 5 | if (i < n) { 6 | arr[i] = arr[i] + i; 7 | } else { 8 | arr[i] = arr[i - 1] + i; 9 | } 10 | i = i + 1; 11 | } 12 | putarray(n, arr); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /testcases/lv9/14_arr_lib_funcs.in: -------------------------------------------------------------------------------- 1 | 5 1 2 3 4 6 2 | -------------------------------------------------------------------------------- /testcases/lv9/15_sort1.c: -------------------------------------------------------------------------------- 1 | int n; 2 | int bubblesort(int arr[]) 3 | { 4 | int i; 5 | int j; 6 | i =0; 7 | while(i < n-1){ 8 | // Last i elements are already in place 9 | j = 0; 10 | while(j < n-i-1){ 11 | if (arr[j] > arr[j+1]) { 12 | // swap(&arr[j], &arr[j+1]); 13 | int tmp; 14 | tmp = arr[j+1]; 15 | arr[j+1] = arr[j]; 16 | arr[j] = tmp; 17 | } 18 | j = j + 1; 19 | } 20 | i = i + 1; 21 | } 22 | return 0; 23 | } 24 | 25 | int main(){ 26 | n = 10; 27 | int a[10]; 28 | a[0]=4;a[1]=3;a[2]=9;a[3]=2;a[4]=0; 29 | a[5]=1;a[6]=6;a[7]=5;a[8]=7;a[9]=8; 30 | int i; 31 | i = bubblesort(a); 32 | while (i < n) { 33 | int tmp; 34 | tmp = a[i]; 35 | putint(tmp); 36 | tmp = 10; 37 | putch(tmp); 38 | i = i + 1; 39 | } 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /testcases/lv9/16_sort2.c: -------------------------------------------------------------------------------- 1 | int n; 2 | int insertsort(int a[]) 3 | { 4 | int i; 5 | i = 1; 6 | while(i-1&&temp k - 1) 15 | { 16 | j = j - 1; 17 | } 18 | 19 | if(i < j) 20 | { 21 | arr[i] = arr[j]; 22 | i = i + 1; 23 | } 24 | 25 | while(i < j && arr[i] < k) 26 | { 27 | i = i + 1; 28 | } 29 | 30 | if(i < j) 31 | { 32 | arr[j] = arr[i]; 33 | j = j - 1; 34 | } 35 | } 36 | 37 | arr[i] = k; 38 | int tmp; 39 | tmp = i - 1; 40 | tmp = QuickSort(arr, low, tmp); 41 | tmp = i + 1; 42 | tmp = QuickSort(arr, tmp, high); 43 | } 44 | return 0; 45 | } 46 | 47 | int main(){ 48 | n = 10; 49 | int a[10]; 50 | a[0]=4;a[1]=3;a[2]=9;a[3]=2;a[4]=0; 51 | a[5]=1;a[6]=6;a[7]=5;a[8]=7;a[9]=8; 52 | int i; 53 | i = 0; 54 | int tmp; 55 | tmp = 9; 56 | i = QuickSort(a, i, tmp); 57 | while (i < n) { 58 | int tmp; 59 | tmp = a[i]; 60 | putint(tmp); 61 | tmp = 10; 62 | putch(tmp); 63 | i = i + 1; 64 | } 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /testcases/lv9/18_sort4.c: -------------------------------------------------------------------------------- 1 | int n; 2 | int select_sort(int A[],int n) 3 | { 4 | int i; 5 | int j; 6 | int min; 7 | i =0; 8 | while(i < n-1) 9 | { 10 | min=i;// 11 | j = i + 1; 12 | while(j < n) 13 | { 14 | if(A[min]>A[j]) 15 | { 16 | min=j; 17 | } 18 | j=j+1; 19 | } 20 | if(min!=i) 21 | { 22 | int tmp; 23 | tmp = A[min]; 24 | A[min] = A[i]; 25 | A[i] = tmp; 26 | } 27 | i = i + 1; 28 | } 29 | return 0; 30 | } 31 | 32 | int main(){ 33 | n = 10; 34 | int a[10]; 35 | a[0]=4;a[1]=3;a[2]=9;a[3]=2;a[4]=0; 36 | a[5]=1;a[6]=6;a[7]=5;a[8]=7;a[9]=8; 37 | int i; 38 | i = 0; 39 | i = select_sort(a, n); 40 | while (i < n) { 41 | int tmp; 42 | tmp = a[i]; 43 | putint(tmp); 44 | tmp = 10; 45 | putch(tmp); 46 | i = i + 1; 47 | } 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /testcases/lv9/19_sort5.c: -------------------------------------------------------------------------------- 1 | int n; 2 | int swap (int array[], int i, int j){ 3 | int temp; 4 | temp = array[i]; 5 | array[i] = array[j]; 6 | array[j] = temp; 7 | return 0; 8 | } 9 | int heap_ajust(int arr[], int start, int end) { 10 | int dad; 11 | dad = start; 12 | int son; 13 | son = dad * 2 + 1; 14 | while (son < end + 1) { // 15 | if (son < end && arr[son] < arr[son + 1]) 16 | son = son + 1; 17 | if (arr[dad] > arr[son]) 18 | return 0; 19 | else { 20 | dad = swap(arr,dad,son); 21 | dad = son; 22 | son = dad * 2 + 1; 23 | } 24 | } 25 | return 0; 26 | } 27 | int heap_sort(int arr[], int len) { 28 | int i; 29 | int tmp; 30 | i = len / 2 - 1; 31 | while ( i > -1) { 32 | tmp = len - 1; 33 | tmp = heap_ajust(arr, i, tmp); 34 | i = i - 1; 35 | } 36 | i = len - 1; 37 | while ( i > 0) { 38 | int tmp0; 39 | tmp0 = 0; 40 | tmp = swap(arr,tmp0,i); 41 | tmp = i - 1; 42 | tmp = heap_ajust(arr, tmp0, tmp); 43 | i = i-1; 44 | } 45 | return 0; 46 | } 47 | 48 | int main(){ 49 | n = 10; 50 | int a[10]; 51 | a[0]=4;a[1]=3;a[2]=9;a[3]=2;a[4]=0; 52 | a[5]=1;a[6]=6;a[7]=5;a[8]=7;a[9]=8; 53 | int i; 54 | i = 0; 55 | i = heap_sort(a, n); 56 | while (i < n) { 57 | int tmp; 58 | tmp = a[i]; 59 | putint(tmp); 60 | tmp = 10; 61 | putch(tmp); 62 | i = i + 1; 63 | } 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /testcases/lv9/20_sort6.c: -------------------------------------------------------------------------------- 1 | int n; 2 | 3 | int counting_sort(int ini_arr[], int sorted_arr[], int n) { 4 | int count_arr[10]; 5 | int i; 6 | int j; 7 | int k; 8 | k = 0; 9 | i = 0; 10 | j = 0; 11 | while(k < 10){ 12 | count_arr[k] = 0; 13 | k = k + 1; 14 | } 15 | while(i < n) 16 | { 17 | count_arr[ini_arr[i]] = count_arr[ini_arr[i]] + 1; 18 | i = i + 1; 19 | } 20 | k = 1; 21 | while(k < 10){ 22 | count_arr[k] = count_arr[k] + count_arr[k - 1]; 23 | k = k + 1; 24 | } 25 | j = n; 26 | while( j > 0){ 27 | count_arr[ini_arr[j - 1]] = count_arr[ini_arr[j - 1]] - 1; 28 | sorted_arr[count_arr[ini_arr[j - 1]]] = ini_arr[j - 1]; 29 | j = j - 1; 30 | } 31 | return 0; 32 | } 33 | 34 | 35 | int main(){ 36 | n = 10; 37 | int a[10]; 38 | a[0]=4;a[1]=3;a[2]=9;a[3]=2;a[4]=0; 39 | a[5]=1;a[6]=6;a[7]=5;a[8]=7;a[9]=8; 40 | int i; 41 | i = 0; 42 | int b[10]; 43 | i = counting_sort(a, b, n); 44 | while (i < n) { 45 | int tmp; 46 | tmp = b[i]; 47 | putint(tmp); 48 | tmp = 10; 49 | putch(tmp); 50 | i = i + 1; 51 | } 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /testcases/lv9/21_sort7.c: -------------------------------------------------------------------------------- 1 | int buf[2][100]; 2 | 3 | // sort [l, r) 4 | void merge_sort(int l, int r) 5 | { 6 | if (l + 1 >= r) 7 | return; 8 | 9 | int mid = (l + r) / 2; 10 | merge_sort(l, mid); 11 | merge_sort(mid, r); 12 | 13 | int i = l, j = mid, k = l; 14 | while (i < mid && j < r) { 15 | if (buf[0][i] < buf[0][j]) { 16 | buf[1][k] = buf[0][i]; 17 | i = i + 1; 18 | } else { 19 | buf[1][k] = buf[0][j]; 20 | j = j + 1; 21 | } 22 | k = k + 1; 23 | } 24 | while (i < mid) { 25 | buf[1][k] = buf[0][i]; 26 | i = i + 1; 27 | k = k + 1; 28 | } 29 | while (j < r) { 30 | buf[1][k] = buf[0][j]; 31 | j = j + 1; 32 | k = k + 1; 33 | } 34 | 35 | while (l < r) { 36 | buf[0][l] = buf[1][l]; 37 | l = l + 1; 38 | } 39 | } 40 | 41 | int main() 42 | { 43 | int n = getarray(buf[0]); 44 | merge_sort(0, n); 45 | putarray(n, buf[0]); 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /testcases/lv9/21_sort7.in: -------------------------------------------------------------------------------- 1 | 97 2 | -10525 -9882 48155 -22162 -38879 52218 -44913 14799 -52541 19859 3 | 23040 38767 -39850 -2221 -63865 51868 64903 -3812 -58581 -14684 4 | -29113 12117 -32032 -58451 -59283 -24783 -10753 -18185 28370 7266 5 | 760 30956 -35818 -52888 -37486 21562 14967 53534 46231 -46019 6 | -46994 -62145 24886 18009 63111 -14203 40779 51479 36163 14992 7 | 57399 -58381 5335 -38236 4245 -33049 33608 -63687 37320 -32676 8 | 6602 40444 1715 11292 2406 16023 1996 -60066 -52763 -16559 9 | 53676 22077 57606 46802 -2033 -64412 -58092 61266 59389 -38805 10 | 1155 59786 35700 52562 9161 -2723 -57451 46501 -2730 38395 11 | -2556 -38481 52802 -47314 -21799 -18640 60818 12 | -------------------------------------------------------------------------------- /testcases/perf/00_bitset1.c: -------------------------------------------------------------------------------- 1 | int set(int a[], int pos, int d){ 2 | const int bitcount = 30; 3 | int x[bitcount + 1] = {}; 4 | 5 | x[0] = 1; 6 | x[1] = x[0] * 2; 7 | x[2] = x[1] * 2; 8 | x[3] = x[2] * 2; 9 | x[4] = x[3] * 2; 10 | x[5] = x[4] * 2; 11 | x[6] = x[5] * 2; 12 | x[7] = x[6] * 2; 13 | x[8] = x[7] * 2; 14 | x[9] = x[8] * 2; 15 | x[10] = x[9] * 2; 16 | 17 | int i = 10; 18 | while (i < bitcount){ 19 | i = i + 1; 20 | x[i] = x[i - 1] * 2; 21 | } 22 | 23 | int v = 0; 24 | 25 | if (pos / bitcount >= 10000) return 0; 26 | 27 | if (a[pos / bitcount] / (x[pos % bitcount]) % 2 != d){ 28 | if (a[pos / bitcount] / (x[pos % bitcount]) % 2 == 0) 29 | if (d == 1) 30 | v = x[pos % bitcount]; 31 | 32 | if (a[pos / bitcount] / x[pos % bitcount] % 2 == 1) 33 | if (d == 0) 34 | v = v - x[pos % bitcount]; 35 | } 36 | 37 | a[pos / bitcount] = a[pos / bitcount] + v; 38 | return 0; 39 | } 40 | 41 | int seed[3] = {19971231, 19981013, 1000000000 + 7}; 42 | int staticvalue = 0; 43 | 44 | int rand(){ 45 | staticvalue = staticvalue * seed[0] + seed[1]; 46 | staticvalue = staticvalue % seed[2]; 47 | if (staticvalue < 0) staticvalue = seed[2] + staticvalue; 48 | return staticvalue; 49 | } 50 | 51 | int a[10000] = {}; 52 | int main(){ 53 | 54 | int n = getint(); 55 | staticvalue = getint(); 56 | starttime(); 57 | int x, y; 58 | while (n > 0){ 59 | n = n - 1; 60 | x = rand() % 300000; 61 | y = rand() % 2; 62 | set(a, x, y); 63 | } 64 | stoptime(); 65 | putarray(10000, a); 66 | return 0; 67 | } -------------------------------------------------------------------------------- /testcases/perf/00_bitset1.in: -------------------------------------------------------------------------------- 1 | 10000000 197123 -------------------------------------------------------------------------------- /testcases/perf/01_bitset2.c: -------------------------------------------------------------------------------- 1 | int set(int a[], int pos, int d){ 2 | const int bitcount = 30; 3 | int x[bitcount + 1] = {}; 4 | 5 | x[0] = 1; 6 | x[1] = x[0] * 2; 7 | x[2] = x[1] * 2; 8 | x[3] = x[2] * 2; 9 | x[4] = x[3] * 2; 10 | x[5] = x[4] * 2; 11 | x[6] = x[5] * 2; 12 | x[7] = x[6] * 2; 13 | x[8] = x[7] * 2; 14 | x[9] = x[8] * 2; 15 | x[10] = x[9] * 2; 16 | 17 | int i = 10; 18 | while (i < bitcount){ 19 | i = i + 1; 20 | x[i] = x[i - 1] * 2; 21 | } 22 | 23 | int v = 0; 24 | 25 | if (pos / bitcount >= 10000) return 0; 26 | 27 | if (a[pos / bitcount] / (x[pos % bitcount]) % 2 != d){ 28 | if (a[pos / bitcount] / (x[pos % bitcount]) % 2 == 0) 29 | if (d == 1) 30 | v = x[pos % bitcount]; 31 | 32 | if (a[pos / bitcount] / x[pos % bitcount] % 2 == 1) 33 | if (d == 0) 34 | v = v - x[pos % bitcount]; 35 | } 36 | 37 | a[pos / bitcount] = a[pos / bitcount] + v; 38 | return 0; 39 | } 40 | 41 | int seed[3] = {19971231, 19981013, 1000000000 + 7}; 42 | int staticvalue = 0; 43 | 44 | int rand(){ 45 | staticvalue = staticvalue * seed[0] + seed[1]; 46 | staticvalue = staticvalue % seed[2]; 47 | if (staticvalue < 0) staticvalue = seed[2] + staticvalue; 48 | return staticvalue; 49 | } 50 | 51 | int a[10000] = {}; 52 | int main(){ 53 | 54 | int n = getint(); 55 | staticvalue = getint(); 56 | starttime(); 57 | int x, y; 58 | while (n > 0){ 59 | n = n - 1; 60 | x = rand() % 300000; 61 | y = rand() % 2; 62 | set(a, x, y); 63 | } 64 | stoptime(); 65 | putarray(10000, a); 66 | return 0; 67 | } -------------------------------------------------------------------------------- /testcases/perf/01_bitset2.in: -------------------------------------------------------------------------------- 1 | 20000000 1231 -------------------------------------------------------------------------------- /testcases/perf/02_bitset3.c: -------------------------------------------------------------------------------- 1 | int set(int a[], int pos, int d){ 2 | const int bitcount = 30; 3 | int x[bitcount + 1] = {}; 4 | 5 | x[0] = 1; 6 | x[1] = x[0] * 2; 7 | x[2] = x[1] * 2; 8 | x[3] = x[2] * 2; 9 | x[4] = x[3] * 2; 10 | x[5] = x[4] * 2; 11 | x[6] = x[5] * 2; 12 | x[7] = x[6] * 2; 13 | x[8] = x[7] * 2; 14 | x[9] = x[8] * 2; 15 | x[10] = x[9] * 2; 16 | 17 | int i = 10; 18 | while (i < bitcount){ 19 | i = i + 1; 20 | x[i] = x[i - 1] * 2; 21 | } 22 | 23 | int v = 0; 24 | 25 | if (pos / bitcount >= 10000) return 0; 26 | 27 | if (a[pos / bitcount] / (x[pos % bitcount]) % 2 != d){ 28 | if (a[pos / bitcount] / (x[pos % bitcount]) % 2 == 0) 29 | if (d == 1) 30 | v = x[pos % bitcount]; 31 | 32 | if (a[pos / bitcount] / x[pos % bitcount] % 2 == 1) 33 | if (d == 0) 34 | v = v - x[pos % bitcount]; 35 | } 36 | 37 | a[pos / bitcount] = a[pos / bitcount] + v; 38 | return 0; 39 | } 40 | 41 | int seed[3] = {19971231, 19981013, 1000000000 + 7}; 42 | int staticvalue = 0; 43 | 44 | int rand(){ 45 | staticvalue = staticvalue * seed[0] + seed[1]; 46 | staticvalue = staticvalue % seed[2]; 47 | if (staticvalue < 0) staticvalue = seed[2] + staticvalue; 48 | return staticvalue; 49 | } 50 | 51 | int a[10000] = {}; 52 | int main(){ 53 | 54 | int n = getint(); 55 | staticvalue = getint(); 56 | starttime(); 57 | int x, y; 58 | while (n > 0){ 59 | n = n - 1; 60 | x = rand() % 300000; 61 | y = rand() % 2; 62 | set(a, x, y); 63 | } 64 | stoptime(); 65 | putarray(10000, a); 66 | return 0; 67 | } -------------------------------------------------------------------------------- /testcases/perf/02_bitset3.in: -------------------------------------------------------------------------------- 1 | 30000000 0 -------------------------------------------------------------------------------- /testcases/perf/03_mm1.c: -------------------------------------------------------------------------------- 1 | const int N = 1024; 2 | 3 | void mm(int n, int A[][N], int B[][N], int C[][N]){ 4 | int i, j, k; 5 | 6 | i = 0; j = 0; 7 | while (i < n){ 8 | j = 0; 9 | while (j < n){ 10 | C[i][j] = 0; 11 | j = j + 1; 12 | } 13 | i = i + 1; 14 | } 15 | 16 | i = 0; j = 0; k = 0; 17 | 18 | while (k < n){ 19 | i = 0; 20 | while (i < n){ 21 | if (A[i][k] == 0){ 22 | i = i + 1; 23 | continue; 24 | } 25 | j = 0; 26 | while (j < n){ 27 | C[i][j] = C[i][j] + A[i][k] * B[k][j]; 28 | j = j + 1; 29 | } 30 | i = i + 1; 31 | } 32 | k = k + 1; 33 | } 34 | } 35 | 36 | int A[N][N]; 37 | int B[N][N]; 38 | int C[N][N]; 39 | 40 | int main(){ 41 | int n = getint(); 42 | int i, j; 43 | 44 | i = 0; 45 | j = 0; 46 | while (i < n){ 47 | j = 0; 48 | while (j < n){ 49 | A[i][j] = getint(); 50 | j = j + 1; 51 | } 52 | i = i + 1; 53 | } 54 | i = 0; 55 | j = 0; 56 | while (i < n){ 57 | j = 0; 58 | while (j < n){ 59 | B[i][j] = getint(); 60 | j = j + 1; 61 | } 62 | i = i + 1; 63 | } 64 | 65 | starttime(); 66 | 67 | i = 0; 68 | while (i < 5){ 69 | mm(n, A, B, C); 70 | mm(n, A, C, B); 71 | i = i + 1; 72 | } 73 | 74 | int ans = 0; 75 | i = 0; 76 | while (i < n){ 77 | j = 0; 78 | while (j < n){ 79 | ans = ans + B[i][j]; 80 | j = j + 1; 81 | } 82 | i = i + 1; 83 | } 84 | stoptime(); 85 | putint(ans); 86 | putch(10); 87 | 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /testcases/perf/04_mm2.c: -------------------------------------------------------------------------------- 1 | const int N = 1024; 2 | 3 | void mm(int n, int A[][N], int B[][N], int C[][N]){ 4 | int i, j, k; 5 | 6 | i = 0; j = 0; 7 | while (i < n){ 8 | j = 0; 9 | while (j < n){ 10 | C[i][j] = 0; 11 | j = j + 1; 12 | } 13 | i = i + 1; 14 | } 15 | 16 | i = 0; j = 0; k = 0; 17 | 18 | while (k < n){ 19 | i = 0; 20 | while (i < n){ 21 | if (A[i][k] == 0){ 22 | i = i + 1; 23 | continue; 24 | } 25 | j = 0; 26 | while (j < n){ 27 | C[i][j] = C[i][j] + A[i][k] * B[k][j]; 28 | j = j + 1; 29 | } 30 | i = i + 1; 31 | } 32 | k = k + 1; 33 | } 34 | } 35 | 36 | int A[N][N]; 37 | int B[N][N]; 38 | int C[N][N]; 39 | 40 | int main(){ 41 | int n = getint(); 42 | int i, j; 43 | 44 | i = 0; 45 | j = 0; 46 | while (i < n){ 47 | j = 0; 48 | while (j < n){ 49 | A[i][j] = getint(); 50 | j = j + 1; 51 | } 52 | i = i + 1; 53 | } 54 | i = 0; 55 | j = 0; 56 | while (i < n){ 57 | j = 0; 58 | while (j < n){ 59 | B[i][j] = getint(); 60 | j = j + 1; 61 | } 62 | i = i + 1; 63 | } 64 | 65 | starttime(); 66 | 67 | i = 0; 68 | while (i < 5){ 69 | mm(n, A, B, C); 70 | mm(n, A, C, B); 71 | i = i + 1; 72 | } 73 | 74 | int ans = 0; 75 | i = 0; 76 | while (i < n){ 77 | j = 0; 78 | while (j < n){ 79 | ans = ans + B[i][j]; 80 | j = j + 1; 81 | } 82 | i = i + 1; 83 | } 84 | stoptime(); 85 | putint(ans); 86 | putch(10); 87 | 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /testcases/perf/05_mm3.c: -------------------------------------------------------------------------------- 1 | const int N = 1024; 2 | 3 | void mm(int n, int A[][N], int B[][N], int C[][N]){ 4 | int i, j, k; 5 | 6 | i = 0; j = 0; 7 | while (i < n){ 8 | j = 0; 9 | while (j < n){ 10 | C[i][j] = 0; 11 | j = j + 1; 12 | } 13 | i = i + 1; 14 | } 15 | 16 | i = 0; j = 0; k = 0; 17 | 18 | while (k < n){ 19 | i = 0; 20 | while (i < n){ 21 | if (A[i][k] == 0){ 22 | i = i + 1; 23 | continue; 24 | } 25 | j = 0; 26 | while (j < n){ 27 | C[i][j] = C[i][j] + A[i][k] * B[k][j]; 28 | j = j + 1; 29 | } 30 | i = i + 1; 31 | } 32 | k = k + 1; 33 | } 34 | } 35 | 36 | int A[N][N]; 37 | int B[N][N]; 38 | int C[N][N]; 39 | 40 | int main(){ 41 | int n = getint(); 42 | int i, j; 43 | 44 | i = 0; 45 | j = 0; 46 | while (i < n){ 47 | j = 0; 48 | while (j < n){ 49 | A[i][j] = getint(); 50 | j = j + 1; 51 | } 52 | i = i + 1; 53 | } 54 | i = 0; 55 | j = 0; 56 | while (i < n){ 57 | j = 0; 58 | while (j < n){ 59 | B[i][j] = getint(); 60 | j = j + 1; 61 | } 62 | i = i + 1; 63 | } 64 | 65 | starttime(); 66 | 67 | i = 0; 68 | while (i < 5){ 69 | mm(n, A, B, C); 70 | mm(n, A, C, B); 71 | i = i + 1; 72 | } 73 | 74 | int ans = 0; 75 | i = 0; 76 | while (i < n){ 77 | j = 0; 78 | while (j < n){ 79 | ans = ans + B[i][j]; 80 | j = j + 1; 81 | } 82 | i = i + 1; 83 | } 84 | stoptime(); 85 | putint(ans); 86 | putch(10); 87 | 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /testcases/perf/06_mv1.c: -------------------------------------------------------------------------------- 1 | int x; 2 | 3 | const int N = 2010; 4 | 5 | void mv(int n, int A[][N], int b[], int res[]){ 6 | int x, y; 7 | y = 0; 8 | x = 11; 9 | int i, j; 10 | 11 | i = 0; 12 | while(i < n){ 13 | res[i] = 0; 14 | i = i + 1; 15 | } 16 | 17 | i = 0; 18 | j = 0; 19 | while (i < n){ 20 | j = 0; 21 | while (j < n){ 22 | if (A[i][j] == 0){ 23 | x = x * b[i] + b[j]; 24 | y = y - x; 25 | }else{ 26 | res[i] = res[i] + A[i][j] * b[j]; 27 | } 28 | j = j + 1; 29 | } 30 | i = i + 1; 31 | } 32 | } 33 | 34 | int A[N][N]; 35 | int B[N]; 36 | int C[N]; 37 | 38 | int main(){ 39 | int n = getint(); 40 | int i, j; 41 | 42 | i = 0; 43 | 44 | while (i < n){ 45 | j = 0; 46 | while (j < n){ 47 | A[i][j] = getint(); 48 | j = j + 1; 49 | } 50 | i = i + 1; 51 | } 52 | 53 | i = 0; 54 | while (i < n){ 55 | B[i] = getint(); 56 | i = i + 1; 57 | } 58 | 59 | starttime(); 60 | 61 | i = 0; 62 | while (i < 50){ 63 | mv(n, A, B, C); 64 | mv(n, A, C, B); 65 | i = i + 1; 66 | } 67 | stoptime(); 68 | 69 | putarray(n, C); 70 | return 0; 71 | } -------------------------------------------------------------------------------- /testcases/perf/07_mv2.c: -------------------------------------------------------------------------------- 1 | int x; 2 | 3 | const int N = 2010; 4 | 5 | void mv(int n, int A[][N], int b[], int res[]){ 6 | int x, y; 7 | y = 0; 8 | x = 11; 9 | int i, j; 10 | 11 | i = 0; 12 | while(i < n){ 13 | res[i] = 0; 14 | i = i + 1; 15 | } 16 | 17 | i = 0; 18 | j = 0; 19 | while (i < n){ 20 | j = 0; 21 | while (j < n){ 22 | if (A[i][j] == 0){ 23 | x = x * b[i] + b[j]; 24 | y = y - x; 25 | }else{ 26 | res[i] = res[i] + A[i][j] * b[j]; 27 | } 28 | j = j + 1; 29 | } 30 | i = i + 1; 31 | } 32 | } 33 | 34 | int A[N][N]; 35 | int B[N]; 36 | int C[N]; 37 | 38 | int main(){ 39 | int n = getint(); 40 | int i, j; 41 | 42 | i = 0; 43 | 44 | while (i < n){ 45 | j = 0; 46 | while (j < n){ 47 | A[i][j] = getint(); 48 | j = j + 1; 49 | } 50 | i = i + 1; 51 | } 52 | 53 | i = 0; 54 | while (i < n){ 55 | B[i] = getint(); 56 | i = i + 1; 57 | } 58 | 59 | starttime(); 60 | 61 | i = 0; 62 | while (i < 50){ 63 | mv(n, A, B, C); 64 | mv(n, A, C, B); 65 | i = i + 1; 66 | } 67 | stoptime(); 68 | 69 | putarray(n, C); 70 | return 0; 71 | } -------------------------------------------------------------------------------- /testcases/perf/08_mv3.c: -------------------------------------------------------------------------------- 1 | int x; 2 | 3 | const int N = 2010; 4 | 5 | void mv(int n, int A[][N], int b[], int res[]){ 6 | int x, y; 7 | y = 0; 8 | x = 11; 9 | int i, j; 10 | 11 | i = 0; 12 | while(i < n){ 13 | res[i] = 0; 14 | i = i + 1; 15 | } 16 | 17 | i = 0; 18 | j = 0; 19 | while (i < n){ 20 | j = 0; 21 | while (j < n){ 22 | if (A[i][j] == 0){ 23 | x = x * b[i] + b[j]; 24 | y = y - x; 25 | }else{ 26 | res[i] = res[i] + A[i][j] * b[j]; 27 | } 28 | j = j + 1; 29 | } 30 | i = i + 1; 31 | } 32 | } 33 | 34 | int A[N][N]; 35 | int B[N]; 36 | int C[N]; 37 | 38 | int main(){ 39 | int n = getint(); 40 | int i, j; 41 | 42 | i = 0; 43 | 44 | while (i < n){ 45 | j = 0; 46 | while (j < n){ 47 | A[i][j] = getint(); 48 | j = j + 1; 49 | } 50 | i = i + 1; 51 | } 52 | 53 | i = 0; 54 | while (i < n){ 55 | B[i] = getint(); 56 | i = i + 1; 57 | } 58 | 59 | starttime(); 60 | 61 | i = 0; 62 | while (i < 50){ 63 | mv(n, A, B, C); 64 | mv(n, A, C, B); 65 | i = i + 1; 66 | } 67 | stoptime(); 68 | 69 | putarray(n, C); 70 | return 0; 71 | } -------------------------------------------------------------------------------- /testcases/perf/09_spmv1.c: -------------------------------------------------------------------------------- 1 | void spmv(int n,int xptr[], int yidx[], int vals[], int b[], int x[]){ 2 | int i, j, k; 3 | i = 0; 4 | while (i < n){ 5 | x[i] = 0; 6 | i = i + 1; 7 | } 8 | 9 | i = 0; 10 | while (i < n){ 11 | j = xptr[i]; 12 | while (j < xptr[i + 1]){ 13 | x[yidx[j]] = x[yidx[j]] + vals[j]; 14 | j = j + 1; 15 | } 16 | 17 | j = xptr[i]; 18 | while (j < xptr[i + 1]){ 19 | x[yidx[j]] = x[yidx[j]] + vals[j] * (b[i] - 1); 20 | j = j + 1; 21 | } 22 | i = i + 1; 23 | } 24 | } 25 | 26 | const int N = 100010; 27 | const int M = 3000000; 28 | 29 | int x[N], y[M], v[M]; 30 | int a[N], b[N], c[N]; 31 | 32 | int main(){ 33 | int n = getarray(x) - 1; 34 | int m = getarray(y); 35 | getarray(v); 36 | 37 | getarray(a); 38 | 39 | starttime(); 40 | 41 | int i = 0; 42 | while (i < 100){ 43 | spmv(n, x, y, v, a, b); 44 | spmv(n, x, y, v, b, a); 45 | i=i+1; 46 | } 47 | stoptime(); 48 | putarray(n, b); 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /testcases/perf/10_spmv2.c: -------------------------------------------------------------------------------- 1 | void spmv(int n,int xptr[], int yidx[], int vals[], int b[], int x[]){ 2 | int i, j, k; 3 | i = 0; 4 | while (i < n){ 5 | x[i] = 0; 6 | i = i + 1; 7 | } 8 | 9 | i = 0; 10 | while (i < n){ 11 | j = xptr[i]; 12 | while (j < xptr[i + 1]){ 13 | x[yidx[j]] = x[yidx[j]] + vals[j]; 14 | j = j + 1; 15 | } 16 | 17 | j = xptr[i]; 18 | while (j < xptr[i + 1]){ 19 | x[yidx[j]] = x[yidx[j]] + vals[j] * (b[i] - 1); 20 | j = j + 1; 21 | } 22 | i = i + 1; 23 | } 24 | } 25 | 26 | const int N = 100010; 27 | const int M = 3000000; 28 | 29 | int x[N], y[M], v[M]; 30 | int a[N], b[N], c[N]; 31 | 32 | int main(){ 33 | int n = getarray(x) - 1; 34 | int m = getarray(y); 35 | getarray(v); 36 | 37 | getarray(a); 38 | 39 | starttime(); 40 | 41 | int i = 0; 42 | while (i < 100){ 43 | spmv(n, x, y, v, a, b); 44 | spmv(n, x, y, v, b, a); 45 | i=i+1; 46 | } 47 | stoptime(); 48 | putarray(n, b); 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /testcases/perf/11_spmv3.c: -------------------------------------------------------------------------------- 1 | void spmv(int n,int xptr[], int yidx[], int vals[], int b[], int x[]){ 2 | int i, j, k; 3 | i = 0; 4 | while (i < n){ 5 | x[i] = 0; 6 | i = i + 1; 7 | } 8 | 9 | i = 0; 10 | while (i < n){ 11 | j = xptr[i]; 12 | while (j < xptr[i + 1]){ 13 | x[yidx[j]] = x[yidx[j]] + vals[j]; 14 | j = j + 1; 15 | } 16 | 17 | j = xptr[i]; 18 | while (j < xptr[i + 1]){ 19 | x[yidx[j]] = x[yidx[j]] + vals[j] * (b[i] - 1); 20 | j = j + 1; 21 | } 22 | i = i + 1; 23 | } 24 | } 25 | 26 | const int N = 100010; 27 | const int M = 3000000; 28 | 29 | int x[N], y[M], v[M]; 30 | int a[N], b[N], c[N]; 31 | 32 | int main(){ 33 | int n = getarray(x) - 1; 34 | int m = getarray(y); 35 | getarray(v); 36 | 37 | getarray(a); 38 | 39 | starttime(); 40 | 41 | int i = 0; 42 | while (i < 100){ 43 | spmv(n, x, y, v, a, b); 44 | spmv(n, x, y, v, b, a); 45 | i=i+1; 46 | } 47 | stoptime(); 48 | putarray(n, b); 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /testcases/perf/12_fft0.c: -------------------------------------------------------------------------------- 1 | const int mod = 998244353; 2 | int d; 3 | 4 | int multiply(int a, int b){ 5 | if (b == 0) return 0; 6 | if (b == 1) return a % mod; 7 | int cur = multiply(a, b/2); 8 | cur = (cur + cur) % mod; 9 | if (b % 2 == 1) return (cur + a) % mod; 10 | else return cur; 11 | } 12 | 13 | int power(int a, int b){ 14 | if (b == 0) return 1; 15 | int cur = power(a, b/2); 16 | cur = multiply(cur, cur); 17 | if (b % 2 == 1) return multiply(cur, a); 18 | else return cur; 19 | } 20 | const int maxlen = 2097152; 21 | int temp[maxlen], a[maxlen], b[maxlen], c[maxlen]; 22 | 23 | int MemMove(int dst[], int dst_pos, int src[], int len){ 24 | int i = 0; 25 | while (i < len){ 26 | dst[dst_pos + i] = src[i]; 27 | i = i + 1; 28 | } 29 | return i; 30 | } 31 | 32 | int fft(int arr[], int begin_pos, int n, int w){ 33 | if (n == 1) return 1; 34 | int i = 0; 35 | while (i < n){ 36 | if (i % 2 == 0) temp[i / 2] = arr[i + begin_pos]; 37 | else temp[n / 2 + i / 2] = arr[i + begin_pos]; 38 | i = i + 1; 39 | } 40 | 41 | MemMove(arr, begin_pos, temp, n); 42 | fft(arr, begin_pos, n / 2, multiply(w, w)); 43 | fft(arr, begin_pos + n / 2, n / 2, multiply(w, w)); 44 | i = 0; 45 | int wn = 1; 46 | while (i < n / 2){ 47 | int x = arr[begin_pos + i]; 48 | int y = arr[begin_pos + i + n / 2]; 49 | arr[begin_pos + i] = (x + multiply(wn, y)) % mod; 50 | arr[begin_pos + i + n / 2] = (x - multiply(wn, y) + mod) % mod; 51 | wn = multiply(wn, w); 52 | i = i + 1; 53 | } 54 | return 0; 55 | } 56 | 57 | int main(){ 58 | int n = getarray(a); 59 | int m = getarray(b); 60 | starttime(); 61 | d = 1; 62 | while (d < n + m - 1){ 63 | d = d * 2; 64 | } 65 | fft(a, 0, d, power(3, (mod - 1) / d)); 66 | fft(b, 0, d, power(3, (mod - 1) / d)); 67 | 68 | int i = 0; 69 | while (i < d){ 70 | a[i] = multiply(a[i], b[i]); 71 | i = i + 1; 72 | } 73 | fft(a, 0, d, power(3, mod-1 - (mod-1)/d)); 74 | i = 0; 75 | while (i < d){ 76 | a[i] = multiply(a[i], power(d, mod-2)); 77 | i = i + 1; 78 | } 79 | stoptime(); 80 | putarray(n + m - 1, a); 81 | return 0; 82 | } -------------------------------------------------------------------------------- /testcases/perf/13_fft1.c: -------------------------------------------------------------------------------- 1 | const int mod = 998244353; 2 | int d; 3 | 4 | int multiply(int a, int b){ 5 | if (b == 0) return 0; 6 | if (b == 1) return a % mod; 7 | int cur = multiply(a, b/2); 8 | cur = (cur + cur) % mod; 9 | if (b % 2 == 1) return (cur + a) % mod; 10 | else return cur; 11 | } 12 | 13 | int power(int a, int b){ 14 | if (b == 0) return 1; 15 | int cur = power(a, b/2); 16 | cur = multiply(cur, cur); 17 | if (b % 2 == 1) return multiply(cur, a); 18 | else return cur; 19 | } 20 | const int maxlen = 2097152; 21 | int temp[maxlen], a[maxlen], b[maxlen], c[maxlen]; 22 | 23 | int MemMove(int dst[], int dst_pos, int src[], int len){ 24 | int i = 0; 25 | while (i < len){ 26 | dst[dst_pos + i] = src[i]; 27 | i = i + 1; 28 | } 29 | return i; 30 | } 31 | 32 | int fft(int arr[], int begin_pos, int n, int w){ 33 | if (n == 1) return 1; 34 | int i = 0; 35 | while (i < n){ 36 | if (i % 2 == 0) temp[i / 2] = arr[i + begin_pos]; 37 | else temp[n / 2 + i / 2] = arr[i + begin_pos]; 38 | i = i + 1; 39 | } 40 | 41 | MemMove(arr, begin_pos, temp, n); 42 | fft(arr, begin_pos, n / 2, multiply(w, w)); 43 | fft(arr, begin_pos + n / 2, n / 2, multiply(w, w)); 44 | i = 0; 45 | int wn = 1; 46 | while (i < n / 2){ 47 | int x = arr[begin_pos + i]; 48 | int y = arr[begin_pos + i + n / 2]; 49 | arr[begin_pos + i] = (x + multiply(wn, y)) % mod; 50 | arr[begin_pos + i + n / 2] = (x - multiply(wn, y) + mod) % mod; 51 | wn = multiply(wn, w); 52 | i = i + 1; 53 | } 54 | return 0; 55 | } 56 | 57 | int main(){ 58 | int n = getarray(a); 59 | int m = getarray(b); 60 | starttime(); 61 | d = 1; 62 | while (d < n + m - 1){ 63 | d = d * 2; 64 | } 65 | fft(a, 0, d, power(3, (mod - 1) / d)); 66 | fft(b, 0, d, power(3, (mod - 1) / d)); 67 | 68 | int i = 0; 69 | while (i < d){ 70 | a[i] = multiply(a[i], b[i]); 71 | i = i + 1; 72 | } 73 | fft(a, 0, d, power(3, mod-1 - (mod-1)/d)); 74 | i = 0; 75 | while (i < d){ 76 | a[i] = multiply(a[i], power(d, mod-2)); 77 | i = i + 1; 78 | } 79 | stoptime(); 80 | putarray(n + m - 1, a); 81 | return 0; 82 | } -------------------------------------------------------------------------------- /testcases/perf/14_fft2.c: -------------------------------------------------------------------------------- 1 | const int mod = 998244353; 2 | int d; 3 | 4 | int multiply(int a, int b){ 5 | if (b == 0) return 0; 6 | if (b == 1) return a % mod; 7 | int cur = multiply(a, b/2); 8 | cur = (cur + cur) % mod; 9 | if (b % 2 == 1) return (cur + a) % mod; 10 | else return cur; 11 | } 12 | 13 | int power(int a, int b){ 14 | if (b == 0) return 1; 15 | int cur = power(a, b/2); 16 | cur = multiply(cur, cur); 17 | if (b % 2 == 1) return multiply(cur, a); 18 | else return cur; 19 | } 20 | const int maxlen = 2097152; 21 | int temp[maxlen], a[maxlen], b[maxlen], c[maxlen]; 22 | 23 | int MemMove(int dst[], int dst_pos, int src[], int len){ 24 | int i = 0; 25 | while (i < len){ 26 | dst[dst_pos + i] = src[i]; 27 | i = i + 1; 28 | } 29 | return i; 30 | } 31 | 32 | int fft(int arr[], int begin_pos, int n, int w){ 33 | if (n == 1) return 1; 34 | int i = 0; 35 | while (i < n){ 36 | if (i % 2 == 0) temp[i / 2] = arr[i + begin_pos]; 37 | else temp[n / 2 + i / 2] = arr[i + begin_pos]; 38 | i = i + 1; 39 | } 40 | 41 | MemMove(arr, begin_pos, temp, n); 42 | fft(arr, begin_pos, n / 2, multiply(w, w)); 43 | fft(arr, begin_pos + n / 2, n / 2, multiply(w, w)); 44 | i = 0; 45 | int wn = 1; 46 | while (i < n / 2){ 47 | int x = arr[begin_pos + i]; 48 | int y = arr[begin_pos + i + n / 2]; 49 | arr[begin_pos + i] = (x + multiply(wn, y)) % mod; 50 | arr[begin_pos + i + n / 2] = (x - multiply(wn, y) + mod) % mod; 51 | wn = multiply(wn, w); 52 | i = i + 1; 53 | } 54 | return 0; 55 | } 56 | 57 | int main(){ 58 | int n = getarray(a); 59 | int m = getarray(b); 60 | starttime(); 61 | d = 1; 62 | while (d < n + m - 1){ 63 | d = d * 2; 64 | } 65 | fft(a, 0, d, power(3, (mod - 1) / d)); 66 | fft(b, 0, d, power(3, (mod - 1) / d)); 67 | 68 | int i = 0; 69 | while (i < d){ 70 | a[i] = multiply(a[i], b[i]); 71 | i = i + 1; 72 | } 73 | fft(a, 0, d, power(3, mod-1 - (mod-1)/d)); 74 | i = 0; 75 | while (i < d){ 76 | a[i] = multiply(a[i], power(d, mod-2)); 77 | i = i + 1; 78 | } 79 | stoptime(); 80 | putarray(n + m - 1, a); 81 | return 0; 82 | } -------------------------------------------------------------------------------- /testcases/perf/15_transpose0.c: -------------------------------------------------------------------------------- 1 | int matrix[20000000]; 2 | int a[100000]; 3 | 4 | int transpose(int n, int matrix[], int rowsize){ 5 | int colsize = n / rowsize; 6 | int i = 0; 7 | int j = 0; 8 | while (i < colsize){ 9 | j = 0; 10 | while (j < rowsize){ 11 | if (i < j){ 12 | j = j + 1; 13 | continue; 14 | } 15 | int curr = matrix[i * rowsize + j]; 16 | matrix[j * colsize + i] = matrix[i * rowsize + j]; 17 | matrix[i * rowsize + j] = curr; 18 | j = j + 1; 19 | } 20 | i = i + 1; 21 | } 22 | return -1; 23 | } 24 | 25 | int main(){ 26 | int n = getint(); 27 | int len = getarray(a); 28 | starttime(); 29 | int i = 0; 30 | while (i < n){ 31 | matrix[i] = i; 32 | i = i + 1; 33 | } 34 | i = 0; 35 | while (i < len){ 36 | transpose(n, matrix, a[i]); 37 | i = i + 1; 38 | } 39 | 40 | int ans = 0; 41 | i = 0; 42 | while (i < len){ 43 | ans = ans + i * i * matrix[i]; 44 | i = i + 1; 45 | } 46 | if (ans < 0) ans = -ans; 47 | stoptime(); 48 | putint(ans); 49 | putch(10); 50 | return 0; 51 | } -------------------------------------------------------------------------------- /testcases/perf/15_transpose0.in: -------------------------------------------------------------------------------- 1 | 10000000 2 | 30 2 5 4 25 8 125 16 625 32 3125 2 5 4 25 8 125 16 625 32 3125 2 5 4 25 8 125 16 625 32 3125 -------------------------------------------------------------------------------- /testcases/perf/16_transpose1.c: -------------------------------------------------------------------------------- 1 | int matrix[20000000]; 2 | int a[100000]; 3 | 4 | int transpose(int n, int matrix[], int rowsize){ 5 | int colsize = n / rowsize; 6 | int i = 0; 7 | int j = 0; 8 | while (i < colsize){ 9 | j = 0; 10 | while (j < rowsize){ 11 | if (i < j){ 12 | j = j + 1; 13 | continue; 14 | } 15 | int curr = matrix[i * rowsize + j]; 16 | matrix[j * colsize + i] = matrix[i * rowsize + j]; 17 | matrix[i * rowsize + j] = curr; 18 | j = j + 1; 19 | } 20 | i = i + 1; 21 | } 22 | return -1; 23 | } 24 | 25 | int main(){ 26 | int n = getint(); 27 | int len = getarray(a); 28 | starttime(); 29 | int i = 0; 30 | while (i < n){ 31 | matrix[i] = i; 32 | i = i + 1; 33 | } 34 | i = 0; 35 | while (i < len){ 36 | transpose(n, matrix, a[i]); 37 | i = i + 1; 38 | } 39 | 40 | int ans = 0; 41 | i = 0; 42 | while (i < len){ 43 | ans = ans + i * i * matrix[i]; 44 | i = i + 1; 45 | } 46 | if (ans < 0) ans = -ans; 47 | stoptime(); 48 | putint(ans); 49 | putch(10); 50 | return 0; 51 | } -------------------------------------------------------------------------------- /testcases/perf/16_transpose1.in: -------------------------------------------------------------------------------- 1 | 11741730 2 | 40 2 3 5 7 11 13 17 23 2 3 5 7 11 13 17 23 2 3 5 7 11 13 17 23 2 3 5 7 11 13 17 23 2 3 5 7 11 13 17 23 -------------------------------------------------------------------------------- /testcases/perf/17_transpose2.c: -------------------------------------------------------------------------------- 1 | int matrix[20000000]; 2 | int a[100000]; 3 | 4 | int transpose(int n, int matrix[], int rowsize){ 5 | int colsize = n / rowsize; 6 | int i = 0; 7 | int j = 0; 8 | while (i < colsize){ 9 | j = 0; 10 | while (j < rowsize){ 11 | if (i < j){ 12 | j = j + 1; 13 | continue; 14 | } 15 | int curr = matrix[i * rowsize + j]; 16 | matrix[j * colsize + i] = matrix[i * rowsize + j]; 17 | matrix[i * rowsize + j] = curr; 18 | j = j + 1; 19 | } 20 | i = i + 1; 21 | } 22 | return -1; 23 | } 24 | 25 | int main(){ 26 | int n = getint(); 27 | int len = getarray(a); 28 | starttime(); 29 | int i = 0; 30 | while (i < n){ 31 | matrix[i] = i; 32 | i = i + 1; 33 | } 34 | i = 0; 35 | while (i < len){ 36 | transpose(n, matrix, a[i]); 37 | i = i + 1; 38 | } 39 | 40 | int ans = 0; 41 | i = 0; 42 | while (i < len){ 43 | ans = ans + i * i * matrix[i]; 44 | i = i + 1; 45 | } 46 | if (ans < 0) ans = -ans; 47 | stoptime(); 48 | putint(ans); 49 | putch(10); 50 | return 0; 51 | } -------------------------------------------------------------------------------- /testcases/perf/17_transpose2.in: -------------------------------------------------------------------------------- 1 | 9072000 2 | 100 22400 32400 3780 576 3360 1575 1125 6750 14175 1296000 1008000 42 2 3375 181440 31500 141750 1296 120960 2625 50 200 1680 12 875 201600 600 2268000 378 604800 33600 4480 120960 181440 189000 604800 756000 210 630 576 42000 2160 70 168 90720 18000 1120 700 72 6 336000 283500 25200 405 5670 2700 7200 10500 4480 2016 1814400 120 3375 81 10368 56 9072000 43200 10125 2240 453600 240 8400 1296 13440 47250 4032 432 86400 1050 750 33600 2100 448 126 1050 24000 45 90720 6300 2160 3360 51840 2100 9450 81000 8100 2800 36 105 3150 810 72576 2880 1 448 225 84 21000 48 42 1008 189 25920 2268 216 8100 907200 280 28000 64 226800 27 6048 525 28350 10368 567 1750 7200 1134000 600 5670 1134000 1125 4800 201600 63 56700 1512 113400 64 3780 140 200 189000 350 5040 108 224 1440 81000 896 1680 3375 288 4480 8100 160 63000 324 12096 900 8000 15 16200 7000 3500 24000 9450 3600 20160 14000 1680 21600 216 42 672 81 1500 2160 21000 60480 9600 141750 81 5 150 378000 14400 6720 560 37800 11200 756 30240 360 36 31500 1600 200 67200 756 81 5040 189000 700 480 189000 8100 7560 15 280 320 504000 129600 126000 43200 378 6750 8100 1890 259200 960 25 144 1890 144 1600 1600 162 1575 100800 3 5 6750 9072000 36000 604800 5760 2520 6 378000 16 162 1680 2160 2520 200 2000 10080 70875 56700 70875 120960 1512 900 226800 2688 56700 336000 4032 150 192 756000 12600 80 1600 3780 300 70 350 720 32 1575 864 576 75 6300 27000 2800 216 450 90720 25920 144000 504 225 1814400 64 54000 168 100800 20160 18000 96 12960 5250 9450 960 -------------------------------------------------------------------------------- /testcases/perf/18_brainfuck-bootstrap.c: -------------------------------------------------------------------------------- 1 | // Brainfuck Interpreter 2 | // Reads program from stdin, interprets and outputs to stdout. 3 | // 4 | // Main optimization targets: 5 | // jump table, inline variables, etc. 6 | 7 | int program_length = 0; 8 | int program[65536] = {}; 9 | int tape[65536] = {}; 10 | int input[65536] = {}; 11 | int input_length = 0; 12 | int output[65536] = {}; 13 | int output_length = 0; 14 | 15 | int get_bf_char() { 16 | int get = getch(); 17 | while (get != 62 && get != 60 && get != 43 && get != 45 && get != 91 && 18 | get != 93 && get != 46 && get != 44 && get != 35) { 19 | get = getch(); 20 | } 21 | return get; 22 | } 23 | 24 | void read_program() { 25 | int get = get_bf_char(); 26 | while (get != 35) { 27 | program[program_length] = get; 28 | get = get_bf_char(); 29 | program_length = program_length + 1; 30 | } 31 | 32 | // read input 33 | // input starts with an `i` 34 | int verify = getch(); 35 | if (verify != 105) { 36 | return; 37 | } 38 | // and a length 39 | input_length = getint(); 40 | // and a random char 41 | getch(); 42 | int i = 0; 43 | while (i < input_length) { 44 | input[i] = getch(); 45 | i = i + 1; 46 | } 47 | } 48 | 49 | void run_program() { 50 | int ip = 0; 51 | int read_head = 0; 52 | int input_head = 0; 53 | int return_address[512] = {}; 54 | int return_address_top = 0; 55 | output_length = 0; 56 | while (ip < program_length) { 57 | int code = program[ip]; 58 | if (code == 62) { 59 | read_head = read_head + 1; 60 | } else if (code == 60) { 61 | read_head = read_head - 1; 62 | } else if (code == 43) { 63 | tape[read_head] = tape[read_head] + 1; 64 | } else if (code == 45) { 65 | tape[read_head] = tape[read_head] - 1; 66 | } else if (code == 91) { 67 | int val = tape[read_head]; 68 | if (val != 0) { 69 | return_address[return_address_top] = ip; 70 | return_address_top = return_address_top + 1; 71 | } else { 72 | // find the matching ] 73 | int loop = 1; 74 | while (loop > 0) { 75 | ip = ip + 1; 76 | if (program[ip] == 93) { 77 | loop = loop - 1; 78 | } 79 | if (program[ip] == 91) { 80 | loop = loop + 1; 81 | } 82 | } 83 | } 84 | } else if (code == 93) { 85 | int val = tape[read_head]; 86 | if (val == 0) { 87 | return_address_top = return_address_top - 1; 88 | } else { 89 | ip = return_address[return_address_top - 1]; 90 | } 91 | } else if (code == 46) { 92 | output[output_length] = tape[read_head]; 93 | output_length = output_length + 1; 94 | } else if (code == 44) { 95 | if (input_head >= input_length) { 96 | tape[read_head] = 0; 97 | } else { 98 | tape[read_head] = input[input_head]; 99 | input_head = input_head + 1; 100 | } 101 | } 102 | ip = ip + 1; 103 | } 104 | } 105 | 106 | void output_() { 107 | int i = 0; 108 | while (i < output_length) { 109 | putch(output[i]); 110 | i = i + 1; 111 | } 112 | } 113 | 114 | int main() { 115 | read_program(); 116 | starttime(); 117 | run_program(); 118 | stoptime(); 119 | output_(); 120 | return 0; 121 | } 122 | -------------------------------------------------------------------------------- /testcases/perf/18_brainfuck-bootstrap.in: -------------------------------------------------------------------------------- 1 | >>>+[[-]>>[-]++>+>+++++++[<++++>>++<-]++>>+>+>+++++[>++>++++++<<-]+>>>,<++[[>[ 2 | ->>]<[>>]<<-]<[<]<+>>[>]>[<+>-[[<+>-]>]<[[[-]<]++<-[<+++++++++>[<->-]>>]>>]]<< 3 | ]<]<[[<]>[[>]>>[>>]+[<<]<[<]<+>>-]>[>]+[->>]<<<<[[<<]<[<]+<<[+>+<<-[>-->+<<-[> 4 | +<[>>+<<-]]]>[<+>-]<]++>>-->[>]>>[>>]]<<[>>+<[[<]<]>[[<<]<[<]+[-<+>>-[<<+>++>- 5 | [<->[<<+>>-]]]<[>+<-]>]>[>]>]>[>>]>>]<<[>>+>>+>>]<<[->>>>>>>>]<<[>.>>>>>>>]<<[ 6 | >->>>>>]<<[>,>>>]<<[>+>]<<[+<<]<] 7 | [input a brainfuck program and its input, separated by an exclamation point. 8 | Daniel B Cristofani (cristofdathevanetdotcom) 9 | http://www.hevanet.com/cristofd/brainfuck/] 10 | #i896#>>>>>++++++++[<+++++++++>-]<+[>>[>]+[<]<-]>++++++++++[<+++++ 11 | +++++>-]<[>>[+>]<[<]<-]<++++++++[>++++++++[>>->->->>>>>>>>>> 12 | >->>>->>>>>>->->->->>->>>->>>>->>>>>->->>>>>>->>>>->>>>>->-> 13 | >>>>->>>->>>>>>>->-[<]<-]>>++>++>->>+>++>++>+>>>>++>>->+>>-> 14 | >>>++>>+>+>+>--->>->+>+>->++>>>->++>>+>+>+>--->>-->>+>>->+>+ 15 | >>->>+>++>+>+>->+>>++>++>->>++>->>++>+>++>+>>+>---[<]<<-]>>> 16 | ++++>++++>+++>--->++>->->->>[-]>->-->[-]>+++>++>+>+++>--->>> 17 | --->[-]>+>+>+>--->[-]>+++>++>+>+++>->+++>>+++>++>---->->->+> 18 | --->[-]>->---->-->>+++>++>+>>+++>->++>++>+>->+++>+++>---->-- 19 | >-->+++>++++>->+++>---->--->++>>+>->->---[[<]<]+++++++++[<+< 20 | +++++++++++>>-]<<[>>>>>[<]>[.>]>--[>.>]<[<<]>++>>>[.>]>[>]>[ 21 | .>]<[[<]<]>>[.>]>--[>.>]<[<<]>++>>>[.>]>[.>]>[>]>[.>]<[[<]<] 22 | <<[<]>>>+<[>-]>[>]<[+++++++++[<+<->>>>>+<<<-]+<<[>>-]>>>[<]< 23 | <<++++++++++>>[>>[-]+<<-]>>-<<]>>>-[>]>-<<[<]>[.>]>--[>.>]<[ 24 | <<]>++>>>[.>]>[>]>[.>]<.[[<]<]<<[<]>>-<-]! 25 | -------------------------------------------------------------------------------- /testcases/perf/19_brainfuck-calculator.c: -------------------------------------------------------------------------------- 1 | // Brainfuck Interpreter 2 | // Reads program from stdin, interprets and outputs to stdout. 3 | // 4 | // Main optimization targets: 5 | // jump table, inline variables, etc. 6 | 7 | int program_length = 0; 8 | int program[65536] = {}; 9 | int tape[65536] = {}; 10 | int input[65536] = {}; 11 | int input_length = 0; 12 | int output[65536] = {}; 13 | int output_length = 0; 14 | 15 | int get_bf_char() { 16 | int get = getch(); 17 | while (get != 62 && get != 60 && get != 43 && get != 45 && get != 91 && 18 | get != 93 && get != 46 && get != 44 && get != 35) { 19 | get = getch(); 20 | } 21 | return get; 22 | } 23 | 24 | void read_program() { 25 | int get = get_bf_char(); 26 | while (get != 35) { 27 | program[program_length] = get; 28 | get = get_bf_char(); 29 | program_length = program_length + 1; 30 | } 31 | 32 | // read input 33 | // input starts with an `i` 34 | int verify = getch(); 35 | if (verify != 105) { 36 | return; 37 | } 38 | // and a length 39 | input_length = getint(); 40 | // and a random char 41 | getch(); 42 | int i = 0; 43 | while (i < input_length) { 44 | input[i] = getch(); 45 | i = i + 1; 46 | } 47 | } 48 | 49 | void run_program() { 50 | int ip = 0; 51 | int read_head = 0; 52 | int input_head = 0; 53 | int return_address[512] = {}; 54 | int return_address_top = 0; 55 | output_length = 0; 56 | while (ip < program_length) { 57 | int code = program[ip]; 58 | if (code == 62) { 59 | read_head = read_head + 1; 60 | } else if (code == 60) { 61 | read_head = read_head - 1; 62 | } else if (code == 43) { 63 | tape[read_head] = tape[read_head] + 1; 64 | } else if (code == 45) { 65 | tape[read_head] = tape[read_head] - 1; 66 | } else if (code == 91) { 67 | int val = tape[read_head]; 68 | if (val != 0) { 69 | return_address[return_address_top] = ip; 70 | return_address_top = return_address_top + 1; 71 | } else { 72 | // find the matching ] 73 | int loop = 1; 74 | while (loop > 0) { 75 | ip = ip + 1; 76 | if (program[ip] == 93) { 77 | loop = loop - 1; 78 | } 79 | if (program[ip] == 91) { 80 | loop = loop + 1; 81 | } 82 | } 83 | } 84 | } else if (code == 93) { 85 | int val = tape[read_head]; 86 | if (val == 0) { 87 | return_address_top = return_address_top - 1; 88 | } else { 89 | ip = return_address[return_address_top - 1]; 90 | } 91 | } else if (code == 46) { 92 | output[output_length] = tape[read_head]; 93 | output_length = output_length + 1; 94 | } else if (code == 44) { 95 | if (input_head >= input_length) { 96 | tape[read_head] = 0; 97 | } else { 98 | tape[read_head] = input[input_head]; 99 | input_head = input_head + 1; 100 | } 101 | } 102 | ip = ip + 1; 103 | } 104 | } 105 | 106 | void output_() { 107 | int i = 0; 108 | while (i < output_length) { 109 | putch(output[i]); 110 | i = i + 1; 111 | } 112 | } 113 | 114 | int main() { 115 | read_program(); 116 | starttime(); 117 | run_program(); 118 | stoptime(); 119 | output_(); 120 | return 0; 121 | } 122 | -------------------------------------------------------------------------------- /testcases/perf/19_brainfuck-calculator.in: -------------------------------------------------------------------------------- 1 | + 2 | [-,>+>+>+>+>+>+<<<<<<----------[>-<----------------------[>>-<<----------[ 3 | >>>-<<<-[>>>>-<<<<--[>>>>>-<<<<<--[>>>>>>[-]>+<<<<<<<-]]]]]]> 4 | [->->->->->-<<<<<]>[->->->->-<<<<<<+>>]> 5 | [->->->-<<<<<<<-<-[>[>+>+<<-]>>[<<+>>-]<<<-]+>[-]+>[<<+>>-]>>]> 6 | [->->-<<<<<<<-[<+>-]+>>>>]>[->-<<<<<<<-[<->-]+>>>>>]> 7 | [-<<<<<<<-[>+>+<<-]>->[<<+>>-]<<<-[>>>>+<<[>+>[-]<<-]>[<+>-]> 8 | [-<<<[>+>+<<-]>>[<<+>>-]>>+<]<<-<<-]+>[-]+> 9 | [-]>>>[<<<<<+>>>>>-]>>]>[<+>>,>++++++++[<---->-]<[>+++++[<--->-],>++++++++ 10 | [<---->-]<]<[<]>>[<-[>++++++++++<-]+>>]<[[<]>+[>]<-]< 11 | [-<]>[<<<<<<+>>>>>>-]<<<<<+>>>>>>>]<<<<<<<]<[>>+<<-]>+>-[>+<< 12 | [-]>-]>[<+>-]<[>+++++++++<[>>>+<<[>+> 13 | [-]<<-]>[<+>-]>[<<++++++++++>>>+<-]<<-<-]<++++++++++>>[<<->>-]>> 14 | [-]>[<<<+>>>-]<<<]<[>]<[->++++++++[<++++++>-]<.[-]<]>> 15 | rpn calculator 16 | by Patrick Schultz patrickschultz@usa dot net 17 | #i45#1 2 + 3 4 5 6 * + 7 - * 20 * 11 15 + * 315 * 18 | 19 | --------------------------------------------------------------------------------