From 803acfd44f5527ff20ca098f0f8784e3a31680b2 Mon Sep 17 00:00:00 2001 From: Samuel Riedel Date: Tue, 29 Aug 2023 15:54:18 +0200 Subject: [PATCH] ci: Add a basic CI setup (#5) * ci: Add a GitHub CI * ci: Add a Clippy * ci: Remove formatter flow * ci: Switch to maintained Rust actions * ci: Fetch submodules * src: Fix linter warnings * tests: Update `fsqrt` test to round to nearest mode --- .github/workflows/ci.yml | 33 +++++++++++++++++++++++ .github/workflows/lint.yml | 20 ++++++++++++++ rust-toolchain.toml | 3 +++ src/dram_preload.rs | 17 ++---------- src/engine.rs | 6 ++--- src/main.rs | 11 +++----- src/tran.rs | 16 ++++++------ tests/bin/fsqrt | Bin 5052 -> 5024 bytes tests/dump/fsqrt.dump | 52 ++++++++++++++++--------------------- tests/fsqrt.c | 3 +-- 10 files changed, 96 insertions(+), 65 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/lint.yml create mode 100644 rust-toolchain.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2e68590 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,33 @@ +# Copyright 2023 ETH Zurich and University of Bologna. +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 + +name: ci +on: [push, pull_request] + +jobs: + ################## + # Build and Test # + ################## + Banshee: + runs-on: ubuntu-latest + timeout-minutes: 20 + strategy: + matrix: + rust: + - 1.63.0 # minimum supported version + steps: + - uses: actions/checkout@v3 + with: + submodules: 'true' + - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + - name: Install LLVM + run: sudo apt install llvm-12-dev + - name: Build Banshee + run: cargo build + - name: Run Banshee tests + run: cargo test --all + - name: Run software test + run: make test TERM=xterm-256color LOG_FAILED=`mktemp` LOG_TOTAL=`mktemp` diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..de0c2a1 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,20 @@ +# Copyright 2023 ETH Zurich and University of Bologna. +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 + +name: lint +on: [push, pull_request] + +jobs: + ######## + # Rust # + ######## + Rust: + name: Format + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + - name: Rustfmt Check + uses: actions-rust-lang/rustfmt@v1 + diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..07d72a9 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "1.63.0" +components = [ "rustfmt" ] diff --git a/src/dram_preload.rs b/src/dram_preload.rs index b78b99d..5321075 100644 --- a/src/dram_preload.rs +++ b/src/dram_preload.rs @@ -2,24 +2,13 @@ // Licensed under the Apache License, Version 2.0, see LICENSE for details. // SPDX-License-Identifier: Apache-2.0 -use bytebuffer::ByteBuffer; -use byteorder::{BigEndian, LittleEndian, ReadBytesExt}; +use byteorder::{LittleEndian, ReadBytesExt}; use std::{ collections::HashMap, - env, error::Error, - fs, fs::File, - io::prelude::*, - io::{BufReader, ErrorKind, Read, Seek, SeekFrom, Write}, - process, - str::FromStr, - sync::{ - atomic::{AtomicBool, AtomicU32, AtomicUsize, Ordering}, - Mutex, - }, + io::{BufReader, ErrorKind, Read}, }; -use to_binary::{BinaryError, BinaryString}; pub fn generic_bin_read( bin_path: &str, @@ -43,8 +32,6 @@ pub fn generic_bin_read( } else { panic!("Error reading file: {}", e); } - - return Err(e.into()); } // we convert the buffer into a u32 diff --git a/src/engine.rs b/src/engine.rs index e33ff0b..44d4ef1 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -312,7 +312,7 @@ impl Engine { pub fn init_periphs(&mut self) { debug!("Adding peripherals"); - (0..self.num_clusters).for_each(|i| { + (0..self.num_clusters).for_each(|_| { self.peripherals .add_cluster(&self.config.memory.periphs.callbacks) }) @@ -499,7 +499,7 @@ impl Engine { ); } } - if ((ssr.dims != 0) && !(ssr.done)) { + if (ssr.dims != 0) && !(ssr.done) { trace!( "Final state hart {}: SSR {} NOT fully consumed.", cpu.hartid, @@ -509,7 +509,7 @@ impl Engine { "Final state hart {}: SSR {} NOT fully consumed.", cpu.hartid, ssr_id ); - } else if ((ssr.dims != 0) && ssr.done) { + } else if (ssr.dims != 0) && ssr.done { trace!( "Final state hart {}: SSR {} fully consumed.", cpu.hartid, diff --git a/src/main.rs b/src/main.rs index 6e0248c..8c73563 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,10 +15,7 @@ use llvm_sys::{ bit_writer::*, core::*, execution_engine::*, initialization::*, support::*, target::*, }; -use std::{ - collections::HashMap, ffi::CString, fs, fs::File, io::prelude::*, num::ParseIntError, - os::raw::c_int, path::Path, ptr::null_mut, str::FromStr, -}; +use std::{ffi::CString, os::raw::c_int, path::Path, ptr::null_mut}; pub mod bootroms; pub mod configuration; @@ -33,8 +30,6 @@ pub mod util; use crate::configuration::*; use crate::engine::*; -use byteorder::{BigEndian, LittleEndian, ReadBytesExt}; - fn main() -> Result<()> { // Parse the command line arguments. let matches = app_from_crate!() @@ -315,9 +310,9 @@ fn main() -> Result<()> { file_path, mem_offset ); // get memory offset from argument - let mut memory_offset = mem_offset.trim_start_matches("0x"); + let memory_offset = mem_offset.trim_start_matches("0x"); // turn the string into a u64 - let mut mem_offset = u64::from_str_radix(memory_offset, 16).unwrap(); + let mem_offset = u64::from_str_radix(memory_offset, 16).unwrap(); let data = dram_preload::generic_bin_read::<4>(file_path, mem_offset).unwrap(); diff --git a/src/tran.rs b/src/tran.rs index 18933ab..866b9d9 100644 --- a/src/tran.rs +++ b/src/tran.rs @@ -6624,13 +6624,13 @@ impl<'a> InstructionTranslator<'a> { /// to that location in the TCDM. unsafe fn emit_tcdm_check(&self, addr: LLVMValueRef) -> (LLVMValueRef, LLVMValueRef) { let tcdm_start = LLVMConstInt(LLVMInt32Type(), self.section.elf.tcdm_start as u64, 0); - let tcdm_end = LLVMConstInt(LLVMInt32Type(), self.section.elf.tcdm_end as u64, 0); - let mut in_range = LLVMBuildAnd( - self.builder, - LLVMBuildICmp(self.builder, LLVMIntUGE, addr, tcdm_start, NONAME), - LLVMBuildICmp(self.builder, LLVMIntULT, addr, tcdm_end, NONAME), - NONAME, - ); + // let tcdm_end = LLVMConstInt(LLVMInt32Type(), self.section.elf.tcdm_end as u64, 0); + // let mut in_range = LLVMBuildAnd( + // self.builder, + // LLVMBuildICmp(self.builder, LLVMIntUGE, addr, tcdm_start, NONAME), + // LLVMBuildICmp(self.builder, LLVMIntULT, addr, tcdm_end, NONAME), + // NONAME, + // ); let index = LLVMBuildSub(self.builder, addr, tcdm_start, NONAME); let pty32 = LLVMPointerType(LLVMInt32Type(), 0); let pty8 = LLVMPointerType(LLVMInt8Type(), 0); @@ -6654,7 +6654,7 @@ impl<'a> InstructionTranslator<'a> { ) -> (LLVMValueRef, LLVMValueRef) { let tcdm_start = LLVMConstInt(LLVMInt32Type(), tcdm_ext.1 as u64, 0); let tcdm_end = LLVMConstInt(LLVMInt32Type(), tcdm_ext.2 as u64, 0); - let mut in_range = LLVMBuildAnd( + let in_range = LLVMBuildAnd( self.builder, LLVMBuildICmp(self.builder, LLVMIntUGE, addr, tcdm_start, NONAME), LLVMBuildICmp(self.builder, LLVMIntULT, addr, tcdm_end, NONAME), diff --git a/tests/bin/fsqrt b/tests/bin/fsqrt index 9c6c7d29dfc7f79bbffd21fc4ff69cc28286c63f..81edb9b7737eeca722aac1b9f2f7504cfa33d7aa 100755 GIT binary patch delta 157 zcmdm^zCe9~0%ONSMP*eRMg|5DW@P{Z0R{#jlfgj{h#46hKv)FG7ulFOkDqbMWDbGF zyqxR?tPJ8n)xxZ;oRfD5$TMcZ0geT_+3or^#t`$~i^%7!Wu$%l)NEiTGZy_@P delta 189 zcmZ3WzDIq60^^d2ipr`Uj0_AQ%*p@+0t^g5CPRQA5Hm71fUp9Pudp$59zWyM$s7WU zdAZmPSQ*5Ds)bowxhC%rkZ0tad_%xSY&uYAa;qyV`vz8q$w2nyPmFQF#gpX(l_uK= zO7H+pfr20Qn?nR=Ff#6#{8mVw6KoC8I)%xi!pe*VlP!hS8TBV83ad+`2{AC(!88GB Iki$R#0CP+tO#lD@ diff --git a/tests/dump/fsqrt.dump b/tests/dump/fsqrt.dump index 575adc1..88fd111 100644 --- a/tests/dump/fsqrt.dump +++ b/tests/dump/fsqrt.dump @@ -6,7 +6,7 @@ Disassembly of section .text: 80010000 <.text>: 80010000: 97 11 00 00 auipc gp, 1 -80010004: 93 81 01 95 addi gp, gp, -1712 +80010004: 93 81 01 94 addi gp, gp, -1728 80010008: 6f 00 40 00 j 0x8001000c <.text+0xc> 8001000c: 17 01 ff bf auipc sp, 786416 80010010: 13 01 c1 ff addi sp, sp, -4 @@ -51,10 +51,10 @@ Disassembly of section .text.main: 8001009c: d3 81 05 f0 fmv.w.x ft3, a1 800100a0: 53 02 05 f0 fmv.w.x ft4, a0 800100a4: 17 05 00 00 auipc a0, 0 -800100a8: 13 05 c5 0a addi a0, a0, 172 +800100a8: 13 05 c5 09 addi a0, a0, 156 800100ac: 07 30 05 00 fld ft0, 0(a0) 800100b0: 17 05 00 00 auipc a0, 0 -800100b4: 13 05 85 0a addi a0, a0, 168 +800100b4: 13 05 85 09 addi a0, a0, 152 800100b8: 87 30 05 00 fld ft1, 0(a0) 800100bc: 13 05 00 00 mv a0, zero 800100c0: d3 72 00 5a fsqrt.d ft5, ft0 @@ -62,7 +62,7 @@ Disassembly of section .text.main: 800100c8: 13 05 f5 ff addi a0, a0, -1 800100cc: 13 35 15 00 seqz a0, a0 800100d0: 97 05 00 00 auipc a1, 0 -800100d4: 93 85 05 09 addi a1, a1, 144 +800100d4: 93 85 05 08 addi a1, a1, 128 800100d8: 07 a0 05 00 flw ft0, 0(a1) 800100dc: 93 05 00 00 mv a1, zero 800100e0: d3 72 00 58 fsqrt.s ft5, ft0 @@ -78,34 +78,28 @@ Disassembly of section .text.main: 80010108: 93 85 f5 ff addi a1, a1, -1 8001010c: 93 b5 15 00 seqz a1, a1 80010110: 33 05 b5 00 add a0, a0, a1 -80010114: 97 05 00 00 auipc a1, 0 -80010118: 93 85 45 05 addi a1, a1, 84 -8001011c: 07 b0 05 00 fld ft0, 0(a1) -80010120: 93 05 00 00 mv a1, zero -80010124: d3 f2 01 5e fsqrt.b ft5, ft3 -80010128: 53 73 10 46 fcvt.b.d ft6, ft0 -8001012c: d3 25 53 a6 feq.b a1, ft6, ft5 -80010130: 93 85 f5 ff addi a1, a1, -1 -80010134: 93 b5 15 00 seqz a1, a1 -80010138: 33 05 b5 00 add a0, a0, a1 -8001013c: 93 05 40 00 addi a1, zero, 4 -80010140: 33 85 a5 40 sub a0, a1, a0 -80010144: 67 80 00 00 ret +80010114: 93 05 00 00 mv a1, zero +80010118: d3 f2 01 5e fsqrt.b ft5, ft3 +8001011c: 53 f3 10 46 fcvt.b.d ft6, ft1 +80010120: d3 25 53 a6 feq.b a1, ft6, ft5 +80010124: 93 85 f5 ff addi a1, a1, -1 +80010128: 93 b5 15 00 seqz a1, a1 +8001012c: 33 05 b5 00 add a0, a0, a1 +80010130: 93 05 40 00 addi a1, zero, 4 +80010134: 33 85 a5 40 sub a0, a1, a0 +80010138: 67 80 00 00 ret Disassembly of section .sdata: -80010150 <.sdata>: -80010150: 1f 85 eb 51 -80010154: b8 1e -80010156: 09 40 -80010158: cd bd -8001015a: ed 67 -8001015c: 21 5a -8001015e: fc 3f -80010160: c3 f5 48 40 fmadd.s fa1, fa7, ft4, fs0 - ... -8001016c: 00 00 -8001016e: f8 3f +80010140 <.sdata>: +80010140: 1f 85 eb 51 +80010144: b8 1e +80010146: 09 40 +80010148: cd bd +8001014a: ed 67 +8001014c: 21 5a +8001014e: fc 3f +80010150: c3 f5 48 40 fmadd.s fa1, fa7, ft4, fs0 Disassembly of section .comment: diff --git a/tests/fsqrt.c b/tests/fsqrt.c index 18e57e6..ddae863 100644 --- a/tests/fsqrt.c +++ b/tests/fsqrt.c @@ -13,7 +13,6 @@ int main() { double res = 1.7720045146669350401991125097536315250736085161629429668177719702909929723489025514725611511539091877503688586880283471705309723721012586751956463721779299361108965365785172200533307761033262439251035823876630437358544911321775625334001046371917616395365848355896213899000527657212021528895927246779480097429154300464010005952680240848463115459297328553780312231691503242208599015793499587440362444180066185238563026710308225242753943500300975957184358461499870626091843809846077091336709541509137661458088335053343825975151460070607357734811548345743955015534456467218552322095954133171880799362477308250252188131416973988993582005350715319952451457013468109231195117000461048554576068707669842993562588266797580347406917516902405285501779620381080421964911692468676654496394088290796641726097314467544452471907934937761385072173706953649409390505097456326820687124319479077069857723545275763448424743526123095082523671605076154911770441368544369157939980880039073716064343031720647930305982767909663674127659266536508742233853866486751460736968681734171024601234112111109848603356126829499008554468260892880962422318346551725814678224017826347226250095335499135772956177452621508573027889814601862343733080464610165218611014506469796480839953159053907987963746888229539303938033616475560292508959607852522732628587506900848010359146262337399502719182926411345876346411763682962300200620810946167615503832294702928298154203757353278145481441408173828749702691477702693921981501005117987820425263365883247955854902748660833891001213443228098779002847019799486769225068962106798362492845149943553231162640282955097571324701122433023245811092998880746343360680949191418953273981637109829068110425865251662526085947317016662135990699159458389649426337612397578070919724346301810733843583118526604802387577793788975059774410388320563908349065276980811546400821449562904652037828180265505648380982709553254282570388714170386081582151498563957038798648495307704883419522824305078934219573760102006376672734918202648872366047279461901050575212008546447170395166840447114506461340651090; - double resf8 = 1.5; uint32_t cmp = 0; @@ -57,7 +56,7 @@ int main() { "fsqrt.b ft5, ft3\n" "fcvt.b.d ft6, %0\n" "feq.b %1, ft6, ft5\n" - : "+f"(resf8), "+r"(cmp)); + : "+f"(res), "+r"(cmp)); errs -= (cmp == 0x1); cmp = 0;