From 97fffe16687786432553c0927a83d8855b67958f Mon Sep 17 00:00:00 2001 From: Byeongkeun Ahn <7p54ks3@naver.com> Date: Sat, 2 Dec 2023 21:55:15 +0900 Subject: [PATCH 1/3] CI: test short --- .github/workflows/build-linux.yml | 21 ++++++++++++++++++++- .github/workflows/release-rs-short.sh | 1 + .github/workflows/release-short.sh | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100755 .github/workflows/release-rs-short.sh create mode 100755 .github/workflows/release-short.sh diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index 8790f156..66dd32a9 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -28,7 +28,7 @@ jobs: with: toolchain: nightly target: ${{ matrix.target }} - profile: minimal + profile: default override: true components: clippy - name: Install node.js @@ -39,6 +39,7 @@ jobs: run: | sudo apt update sudo apt install gcc-multilib nasm + rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu - name: Clippy run: cargo clippy env: @@ -57,6 +58,15 @@ jobs: python ./scripts/build-and-judge.py ${{ runner.temp }} ./release.sh C 64 ./tests/boj_3745.rs ./tests/boj_3745.in ./tests/boj_3745.out python ./scripts/build-and-judge.py ${{ runner.temp }} ./release.sh C 64 ./tests/boj_14939.rs ./tests/boj_14939.in ./tests/boj_14939.out python ./scripts/build-and-judge.py ${{ runner.temp }} ./release.sh C 64 ./tests/reloc.rs ./tests/reloc.in ./tests/reloc.out + - name: Check C (x86_64) - short + if: ${{ matrix.target == 'x86_64-unknown-linux-gnu' }} + run: | + python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-short.sh C 64 ./src/solution.rs ./tests/boj_1000.in ./tests/boj_1000.out + python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-short.sh C 64 ./tests/boj_1001.rs ./tests/boj_1001.in ./tests/boj_1001.out + python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-short.sh C 64 ./tests/boj_2751.rs ./tests/boj_2751.in.zip ./tests/boj_2751.out.zip + python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-short.sh C 64 ./tests/boj_3745.rs ./tests/boj_3745.in ./tests/boj_3745.out + python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-short.sh C 64 ./tests/boj_14939.rs ./tests/boj_14939.in ./tests/boj_14939.out + python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-short.sh C 64 ./tests/reloc.rs ./tests/reloc.in ./tests/reloc.out - name: Check C (x86) if: ${{ matrix.target == 'i686-unknown-linux-gnu' }} run: | @@ -75,6 +85,15 @@ jobs: python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-rs.sh Rust 64 ./tests/boj_3745.rs ./tests/boj_3745.in ./tests/boj_3745.out python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-rs.sh Rust 64 ./tests/boj_14939.rs ./tests/boj_14939.in ./tests/boj_14939.out python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-rs.sh Rust 64 ./tests/reloc.rs ./tests/reloc.in ./tests/reloc.out + - name: Check Rust (x86_64) - short + if: ${{ matrix.target == 'x86_64-unknown-linux-gnu' }} + run: | + python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-rs-short.sh Rust 64 ./src/solution.rs ./tests/boj_1000.in ./tests/boj_1000.out + python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-rs-short.sh Rust 64 ./tests/boj_1001.rs ./tests/boj_1001.in ./tests/boj_1001.out + python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-rs-short.sh Rust 64 ./tests/boj_2751.rs ./tests/boj_2751.in.zip ./tests/boj_2751.out.zip + python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-rs-short.sh Rust 64 ./tests/boj_3745.rs ./tests/boj_3745.in ./tests/boj_3745.out + python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-rs-short.sh Rust 64 ./tests/boj_14939.rs ./tests/boj_14939.in ./tests/boj_14939.out + python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-rs-short.sh Rust 64 ./tests/reloc.rs ./tests/reloc.in ./tests/reloc.out - name: Check wasm32 if: ${{ matrix.target == 'wasm32-unknown-unknown' }} run: | diff --git a/.github/workflows/release-rs-short.sh b/.github/workflows/release-rs-short.sh new file mode 100755 index 00000000..089ed938 --- /dev/null +++ b/.github/workflows/release-rs-short.sh @@ -0,0 +1 @@ +./release-rs.sh --features short \ No newline at end of file diff --git a/.github/workflows/release-short.sh b/.github/workflows/release-short.sh new file mode 100755 index 00000000..7855cb5d --- /dev/null +++ b/.github/workflows/release-short.sh @@ -0,0 +1 @@ +./release.sh --features short \ No newline at end of file From 041ec04ee22fa0d00fe7e50b5f96043dd4c0f6cf Mon Sep 17 00:00:00 2001 From: Byeongkeun Ahn <7p54ks3@naver.com> Date: Sat, 2 Dec 2023 22:06:11 +0900 Subject: [PATCH 2/3] CI: add Baekjoon Online Judge 2587 --- .github/workflows/build-linux.yml | 6 ++++++ .github/workflows/build-windows.yml | 3 +++ tests/boj_2587.in | 5 +++++ tests/boj_2587.out | 2 ++ tests/boj_2587.rs | 20 ++++++++++++++++++++ 5 files changed, 36 insertions(+) create mode 100644 tests/boj_2587.in create mode 100644 tests/boj_2587.out create mode 100644 tests/boj_2587.rs diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index 66dd32a9..609f904a 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -54,6 +54,7 @@ jobs: run: | python ./scripts/build-and-judge.py ${{ runner.temp }} ./release.sh C 64 ./src/solution.rs ./tests/boj_1000.in ./tests/boj_1000.out python ./scripts/build-and-judge.py ${{ runner.temp }} ./release.sh C 64 ./tests/boj_1001.rs ./tests/boj_1001.in ./tests/boj_1001.out + python ./scripts/build-and-judge.py ${{ runner.temp }} ./release.sh C 64 ./tests/boj_2587.rs ./tests/boj_2587.in ./tests/boj_2587.out python ./scripts/build-and-judge.py ${{ runner.temp }} ./release.sh C 64 ./tests/boj_2751.rs ./tests/boj_2751.in.zip ./tests/boj_2751.out.zip python ./scripts/build-and-judge.py ${{ runner.temp }} ./release.sh C 64 ./tests/boj_3745.rs ./tests/boj_3745.in ./tests/boj_3745.out python ./scripts/build-and-judge.py ${{ runner.temp }} ./release.sh C 64 ./tests/boj_14939.rs ./tests/boj_14939.in ./tests/boj_14939.out @@ -63,6 +64,7 @@ jobs: run: | python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-short.sh C 64 ./src/solution.rs ./tests/boj_1000.in ./tests/boj_1000.out python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-short.sh C 64 ./tests/boj_1001.rs ./tests/boj_1001.in ./tests/boj_1001.out + python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-short.sh C 64 ./tests/boj_2587.rs ./tests/boj_2587.in ./tests/boj_2587.out python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-short.sh C 64 ./tests/boj_2751.rs ./tests/boj_2751.in.zip ./tests/boj_2751.out.zip python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-short.sh C 64 ./tests/boj_3745.rs ./tests/boj_3745.in ./tests/boj_3745.out python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-short.sh C 64 ./tests/boj_14939.rs ./tests/boj_14939.in ./tests/boj_14939.out @@ -72,6 +74,7 @@ jobs: run: | python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-32bit.sh C 32 ./src/solution.rs ./tests/boj_1000.in ./tests/boj_1000.out python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-32bit.sh C 32 ./tests/boj_1001.rs ./tests/boj_1001.in ./tests/boj_1001.out + python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-32bit.sh C 32 ./tests/boj_2587.rs ./tests/boj_2587.in ./tests/boj_2587.out python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-32bit.sh C 32 ./tests/boj_2751.rs ./tests/boj_2751.in.zip ./tests/boj_2751.out.zip python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-32bit.sh C 32 ./tests/boj_3745.rs ./tests/boj_3745.in ./tests/boj_3745.out python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-32bit.sh C 32 ./tests/boj_14939.rs ./tests/boj_14939.in ./tests/boj_14939.out @@ -81,6 +84,7 @@ jobs: run: | python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-rs.sh Rust 64 ./src/solution.rs ./tests/boj_1000.in ./tests/boj_1000.out python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-rs.sh Rust 64 ./tests/boj_1001.rs ./tests/boj_1001.in ./tests/boj_1001.out + python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-rs.sh Rust 64 ./tests/boj_2587.rs ./tests/boj_2587.in ./tests/boj_2587.out python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-rs.sh Rust 64 ./tests/boj_2751.rs ./tests/boj_2751.in.zip ./tests/boj_2751.out.zip python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-rs.sh Rust 64 ./tests/boj_3745.rs ./tests/boj_3745.in ./tests/boj_3745.out python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-rs.sh Rust 64 ./tests/boj_14939.rs ./tests/boj_14939.in ./tests/boj_14939.out @@ -90,6 +94,7 @@ jobs: run: | python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-rs-short.sh Rust 64 ./src/solution.rs ./tests/boj_1000.in ./tests/boj_1000.out python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-rs-short.sh Rust 64 ./tests/boj_1001.rs ./tests/boj_1001.in ./tests/boj_1001.out + python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-rs-short.sh Rust 64 ./tests/boj_2587.rs ./tests/boj_2587.in ./tests/boj_2587.out python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-rs-short.sh Rust 64 ./tests/boj_2751.rs ./tests/boj_2751.in.zip ./tests/boj_2751.out.zip python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-rs-short.sh Rust 64 ./tests/boj_3745.rs ./tests/boj_3745.in ./tests/boj_3745.out python ./scripts/build-and-judge.py ${{ runner.temp }} ./.github/workflows/release-rs-short.sh Rust 64 ./tests/boj_14939.rs ./tests/boj_14939.in ./tests/boj_14939.out @@ -99,6 +104,7 @@ jobs: run: | python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-wasm32.sh JavaScript 32 ./src/solution.rs ./tests/boj_1000.in ./tests/boj_1000.out python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-wasm32.sh JavaScript 32 ./tests/boj_1001.rs ./tests/boj_1001.in ./tests/boj_1001.out + python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-wasm32.sh JavaScript 32 ./tests/boj_2587.rs ./tests/boj_2587.in ./tests/boj_2587.out python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-wasm32.sh JavaScript 32 ./tests/boj_2751.rs ./tests/boj_2751.in.zip ./tests/boj_2751.out.zip python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-wasm32.sh JavaScript 32 ./tests/boj_3745.rs ./tests/boj_3745.in ./tests/boj_3745.out python ./scripts/build-and-judge.py ${{ runner.temp }} ./release-wasm32.sh JavaScript 32 ./tests/boj_14939.rs ./tests/boj_14939.in ./tests/boj_14939.out diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index 98e03af8..0b08b3bf 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -55,6 +55,7 @@ jobs: run: | python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-64bit-windows.cmd C 64 .\src\solution.rs .\tests\boj_1000.in .\tests\boj_1000.out python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-64bit-windows.cmd C 64 .\tests\boj_1001.rs .\tests\boj_1001.in .\tests\boj_1001.out + python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-64bit-windows.cmd C 64 .\tests\boj_2587.rs .\tests\boj_2587.in .\tests\boj_2587.out python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-64bit-windows.cmd C 64 .\tests\boj_2751.rs .\tests\boj_2751.in.zip .\tests\boj_2751.out.zip python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-64bit-windows.cmd C 64 .\tests\boj_3745.rs .\tests\boj_3745.in .\tests\boj_3745.out python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-64bit-windows.cmd C 64 .\tests\boj_14939.rs .\tests\boj_14939.in .\tests\boj_14939.out @@ -64,6 +65,7 @@ jobs: run: | python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-64bit-windows-rs.cmd Rust 64 .\src\solution.rs .\tests\boj_1000.in .\tests\boj_1000.out python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-64bit-windows-rs.cmd Rust 64 .\tests\boj_1001.rs .\tests\boj_1001.in .\tests\boj_1001.out + python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-64bit-windows-rs.cmd Rust 64 .\tests\boj_2587.rs .\tests\boj_2587.in .\tests\boj_2587.out python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-64bit-windows-rs.cmd Rust 64 .\tests\boj_2751.rs .\tests\boj_2751.in.zip .\tests\boj_2751.out.zip python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-64bit-windows-rs.cmd Rust 64 .\tests\boj_3745.rs .\tests\boj_3745.in .\tests\boj_3745.out python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-64bit-windows-rs.cmd Rust 64 .\tests\boj_14939.rs .\tests\boj_14939.in .\tests\boj_14939.out @@ -73,6 +75,7 @@ jobs: run: | python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-wasm32.cmd JavaScript 32 .\src\solution.rs .\tests\boj_1000.in .\tests\boj_1000.out python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-wasm32.cmd JavaScript 32 .\tests\boj_1001.rs .\tests\boj_1001.in .\tests\boj_1001.out + python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-wasm32.cmd JavaScript 32 .\tests\boj_2587.rs .\tests\boj_2587.in .\tests\boj_2587.out python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-wasm32.cmd JavaScript 32 .\tests\boj_2751.rs .\tests\boj_2751.in.zip .\tests\boj_2751.out.zip python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-wasm32.cmd JavaScript 32 .\tests\boj_3745.rs .\tests\boj_3745.in .\tests\boj_3745.out python .\scripts\build-and-judge.py ${{ runner.temp }} .\release-wasm32.cmd JavaScript 32 .\tests\boj_14939.rs .\tests\boj_14939.in .\tests\boj_14939.out diff --git a/tests/boj_2587.in b/tests/boj_2587.in new file mode 100644 index 00000000..3fcb0955 --- /dev/null +++ b/tests/boj_2587.in @@ -0,0 +1,5 @@ +10 +40 +30 +60 +30 \ No newline at end of file diff --git a/tests/boj_2587.out b/tests/boj_2587.out new file mode 100644 index 00000000..f9e5d27b --- /dev/null +++ b/tests/boj_2587.out @@ -0,0 +1,2 @@ +34 +30 \ No newline at end of file diff --git a/tests/boj_2587.rs b/tests/boj_2587.rs new file mode 100644 index 00000000..02320531 --- /dev/null +++ b/tests/boj_2587.rs @@ -0,0 +1,20 @@ +use basm::platform::io::{Reader, Writer, Print}; +pub fn main() { + let mut reader = Reader::<128>::new(); + let mut writer = Writer::<128>::new(); + let mut x = [0; 5]; + let mut sum = 0; + for i in 0..5 { + x[i] = reader.u32(); + sum += x[i]; + } + for i in 0..5 { + for j in i+1..5 { + if x[i] > x[j] { + x.swap(i, j); + } + } + } + writer.println(sum / 5); + writer.println(x[2]); +} \ No newline at end of file From 8bbf4690461ee6f33b4fad7c3ff7467da4f178d9 Mon Sep 17 00:00:00 2001 From: Byeongkeun Ahn <7p54ks3@naver.com> Date: Sat, 2 Dec 2023 22:12:29 +0900 Subject: [PATCH 3/3] short: amd64-rust-shorter: fix rsp alignment --- scripts/static-pie-prestub-amd64-shorter.asm | 3 ++- scripts/static-pie-prestub-amd64-shorter.bin | 2 +- scripts/static-pie-template-amd64-shorter.rs | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/static-pie-prestub-amd64-shorter.asm b/scripts/static-pie-prestub-amd64-shorter.asm index 1316865d..7f698051 100644 --- a/scripts/static-pie-prestub-amd64-shorter.asm +++ b/scripts/static-pie-prestub-amd64-shorter.asm @@ -4,7 +4,7 @@ ; (prestub: the code that runs before the stub and sets the stage) ; ; build: nasm -f bin -O9 static-pie-prestub-amd64-shorter.asm -o static-pie-prestub-amd64-shorter.bin -; note: after building with the above command, run static-pie-prestub-amd64-print.py static-pie-prestub-amd64-shorter.bin +; note: after building with the above command, run static-pie-prestub-amd64-print.py static-pie-prestub-amd64-shorter.bin --octa ; to obtain the form that can be embedded in Rust as inline assembly. BITS 64 @@ -61,4 +61,5 @@ _decode_zeros: ; Jump to entrypoint _jump_to_entrypoint: sub rdi, qword [rdi-8] + and rsp, 0xfffffffffffffff0 call rdi \ No newline at end of file diff --git a/scripts/static-pie-prestub-amd64-shorter.bin b/scripts/static-pie-prestub-amd64-shorter.bin index 84271c4b..bd4d3117 100644 --- a/scripts/static-pie-prestub-amd64-shorter.bin +++ b/scripts/static-pie-prestub-amd64-shorter.bin @@ -1 +1 @@ -j X�E1�V1��Ʋj"AZj�AX^H���� �1�,#v�ȑ�,$k�[Ȫ����u����O��t�H+��� \ No newline at end of file +j X�E1�V1��Ʋj"AZj�AX^H���� �1�,#v�ȑ�,$k�[Ȫ����u����O��t�H+�H����� \ No newline at end of file diff --git a/scripts/static-pie-template-amd64-shorter.rs b/scripts/static-pie-template-amd64-shorter.rs index cca645c3..40636049 100644 --- a/scripts/static-pie-template-amd64-shorter.rs +++ b/scripts/static-pie-template-amd64-shorter.rs @@ -5,4 +5,4 @@ $$$$solution_src$$$$ } // SOLUTION END -#[no_link]extern crate std;#[no_mangle]unsafe fn _start(){std::arch::asm!(".octa 226a07b2c689ff3156c931459958096ah,0de0c11fb097485e050f5841ff6a5a41h,5bc06b242cac91c8fe1676232cc931ach,0ff4f86e0ebf77510c4f608e8c1aac801h,0d7fff87f2b48dc74aaf3h",in("rsi")r$$$$binary_raw_base91$$$$.as_ptr())} \ No newline at end of file +#[no_link]extern crate std;#[no_mangle]unsafe fn _start(){std::arch::asm!(".octa 226a07b2c689ff3156c931459958096ah,0de0c11fb097485e050f5841ff6a5a41h,5bc06b242cac91c8fe1676232cc931ach,0ff4f86e0ebf77510c4f608e8c1aac801h,0d7fff0e48348f87f2b48dc74aaf3h",in("rsi")r$$$$binary_raw_base91$$$$.as_ptr())} \ No newline at end of file