Skip to content

Commit

Permalink
ci: Add a basic CI setup (#5)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
SamuelRiedel authored Aug 29, 2023
1 parent f40ed9d commit 803acfd
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 65 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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`
20 changes: 20 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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

3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "1.63.0"
components = [ "rustfmt" ]
17 changes: 2 additions & 15 deletions src/dram_preload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<const N: usize>(
bin_path: &str,
Expand All @@ -43,8 +32,6 @@ pub fn generic_bin_read<const N: usize>(
} else {
panic!("Error reading file: {}", e);
}

return Err(e.into());
}

// we convert the buffer into a u32
Expand Down
6 changes: 3 additions & 3 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
11 changes: 3 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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!()
Expand Down Expand Up @@ -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();

Expand Down
16 changes: 8 additions & 8 deletions src/tran.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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),
Expand Down
Binary file modified tests/bin/fsqrt
Binary file not shown.
52 changes: 23 additions & 29 deletions tests/dump/fsqrt.dump
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,18 +51,18 @@ 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
800100c4: 53 a5 50 a2 feq.d a0, ft1, ft5
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
Expand All @@ -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 <unknown>
80010154: b8 1e <unknown>
80010156: 09 40 <unknown>
80010158: cd bd <unknown>
8001015a: ed 67 <unknown>
8001015c: 21 5a <unknown>
8001015e: fc 3f <unknown>
80010160: c3 f5 48 40 fmadd.s fa1, fa7, ft4, fs0
...
8001016c: 00 00 <unknown>
8001016e: f8 3f <unknown>
80010140 <.sdata>:
80010140: 1f 85 eb 51 <unknown>
80010144: b8 1e <unknown>
80010146: 09 40 <unknown>
80010148: cd bd <unknown>
8001014a: ed 67 <unknown>
8001014c: 21 5a <unknown>
8001014e: fc 3f <unknown>
80010150: c3 f5 48 40 fmadd.s fa1, fa7, ft4, fs0

Disassembly of section .comment:

Expand Down
3 changes: 1 addition & 2 deletions tests/fsqrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ int main() {

double res =
1.7720045146669350401991125097536315250736085161629429668177719702909929723489025514725611511539091877503688586880283471705309723721012586751956463721779299361108965365785172200533307761033262439251035823876630437358544911321775625334001046371917616395365848355896213899000527657212021528895927246779480097429154300464010005952680240848463115459297328553780312231691503242208599015793499587440362444180066185238563026710308225242753943500300975957184358461499870626091843809846077091336709541509137661458088335053343825975151460070607357734811548345743955015534456467218552322095954133171880799362477308250252188131416973988993582005350715319952451457013468109231195117000461048554576068707669842993562588266797580347406917516902405285501779620381080421964911692468676654496394088290796641726097314467544452471907934937761385072173706953649409390505097456326820687124319479077069857723545275763448424743526123095082523671605076154911770441368544369157939980880039073716064343031720647930305982767909663674127659266536508742233853866486751460736968681734171024601234112111109848603356126829499008554468260892880962422318346551725814678224017826347226250095335499135772956177452621508573027889814601862343733080464610165218611014506469796480839953159053907987963746888229539303938033616475560292508959607852522732628587506900848010359146262337399502719182926411345876346411763682962300200620810946167615503832294702928298154203757353278145481441408173828749702691477702693921981501005117987820425263365883247955854902748660833891001213443228098779002847019799486769225068962106798362492845149943553231162640282955097571324701122433023245811092998880746343360680949191418953273981637109829068110425865251662526085947317016662135990699159458389649426337612397578070919724346301810733843583118526604802387577793788975059774410388320563908349065276980811546400821449562904652037828180265505648380982709553254282570388714170386081582151498563957038798648495307704883419522824305078934219573760102006376672734918202648872366047279461901050575212008546447170395166840447114506461340651090;
double resf8 = 1.5;

uint32_t cmp = 0;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 803acfd

Please sign in to comment.