From 74c0039b64111e8c7b52a2f8622490e467811d68 Mon Sep 17 00:00:00 2001 From: agnusmor Date: Tue, 14 Jan 2025 17:14:03 +0100 Subject: [PATCH 1/4] Added scripts to update Rust version in Zisk-Rust repo --- tools/update-rust/git-utils.sh | 60 +++++++++++++ tools/update-rust/release-rust.sh | 86 +++++++++++++++++++ tools/update-rust/update-rust.sh | 134 ++++++++++++++++++++++++++++++ 3 files changed, 280 insertions(+) create mode 100755 tools/update-rust/git-utils.sh create mode 100755 tools/update-rust/release-rust.sh create mode 100755 tools/update-rust/update-rust.sh diff --git a/tools/update-rust/git-utils.sh b/tools/update-rust/git-utils.sh new file mode 100755 index 000000000..eb01b6b05 --- /dev/null +++ b/tools/update-rust/git-utils.sh @@ -0,0 +1,60 @@ +# git-utils.sh + +# Log a message with a specific level (color) +log_level() { + local level=$1 + local message=$2 + local color="" + + case $level in + info) color="\e[1;32m" ;; # Green + warn) color="\e[1;33m" ;; # Yellow + err) color="\e[1;31m" ;; # Red + *) color="\e[1;m" ;; # Default + esac + + echo -e "${color}$message\e[0m" +} + +# Log a message with info level +log_info() { + log_level "info" "$1" +} + +# Log a message with warn level +log_warn() { + log_level "warn" "$1" +} + +# Log a message with error level +log_err() { + log_level "err" "$1" +} + +# Log a message with no level +log() { + log_level "" "$1" +} + +# Execute a git command and print the output. Exits if the command fails. +exec_git() { + local command="$1" + local error_message="$2" + + output=$(eval "$command" 2>&1) + + # Exit if the command fails + if [[ $? -ne 0 ]]; then + # Print the error output + echo "$output" + # Print the error message + log_err ${error_message} + + exit 1 + fi + + # Print the output if it's not empty + if [[ -n "$output" ]]; then + echo "$output" + fi +} diff --git a/tools/update-rust/release-rust.sh b/tools/update-rust/release-rust.sh new file mode 100755 index 000000000..51d56e042 --- /dev/null +++ b/tools/update-rust/release-rust.sh @@ -0,0 +1,86 @@ +#!/bin/bash + +source ./git-utils.sh + +# Check if the script has the required parameters +if [[ $# -ne 3 ]]; then + log_err "Error invalid parameters" + log "Usage: $0 " + exit 1 +fi + +TO_VERSION=$1 +RELEASE_VERSION=$2 +ZISK_RUST_DIR="$(realpath "$3")/rust" + +# Change directory to Zisk Rust repository +cd ${ZISK_RUST_DIR} + +# Check if we are in ZISK_RUST_DIR directory +if [ "$(pwd)" != "$ZISK_RUST_DIR" ]; then + log_err "\e[1;31mError changing directory to '${ZISK_RUST_DIR}'" + exit 1 +fi + +# Verify current branch is zisk-rust-${TO_VERSION} +current_branch=$(git rev-parse --abbrev-ref HEAD) +if [[ "$current_branch" != "zisk-rust-${TO_VERSION}" ]]; then + log_err "Current branch is not 'zisk-rust-${TO_VERSION}'" + exit 1 +fi + +unstaged_files=$(git diff --name-only) +if ! [[ -z "$unstaged_files" ]]; then + log_info "Unstaged files in the working directory:" + echo "$unstaged_files" + read -p "$(log_warn 'There are unstaged files in the working directory. Continue? [y/N] ')" response + if [[ "$response" != "y" && "$response" != "yes" ]]; then + log "Exiting..." + exit 1 + fi +fi + +log_info "Committing all staged files to branch 'zisk-rust-${TO_VERSION}'" +log "Commit message 'Update Rust to version ${TO_VERSION}'" +exec_git \ + "git commit -m 'Update Rust to version ${TO_VERSION}'" \ + "Failed to commit changes" + +# Push zisk-rust-${TO_VERSION} branch to origin/zisk +log_info "Pushing 'zisk-rust-${TO_VERSION}' branch to origin/zisk" +exec_git \ + "git push origin zisk-rust-${TO_VERSION}:refs/heads/zisk --force" \ + "Failed to push 'zisk-rust-${TO_VERSION}' branch to origin/zisk" + +#Checkout zisk branch +log_info "Checking out 'zisk' branch" +exec_git \ + "git checkout zisk" \ + "Failed to checkout 'zisk' branch" +# Verify current branch is zisk-rust-${TO_VERSION} +current_branch=$(git rev-parse --abbrev-ref HEAD) +if [[ "$current_branch" != "zisk" ]]; then + log_err "Current branch is not 'zisk'" + exit 1 +fi + +# Resetting local zisk branch +log_info "Resetting local 'zisk' branch" +exec_git \ + "git reset --hard origin/zisk" \ + "Failed to pull 'zisk' branch" + +log_info "Tagging branch 'zisk' with tag 'zisk-${RELEASE_VERSION}'" +# Create tag +exec_git \ + "git tag zisk-${RELEASE_VERSION}" \ + "Failed to create local tag 'zisk-${RELEASE_VERSION}'" +# Push tag to origin +exec_git \ + "git push origin zisk-${RELEASE_VERSION}" \ + "Failed to push tag 'zisk-${RUST-ZISK-VERSION}' to origin" + +echo +log_info "Done! Now the release GHA should be running, check it" +echo + \ No newline at end of file diff --git a/tools/update-rust/update-rust.sh b/tools/update-rust/update-rust.sh new file mode 100755 index 000000000..3fb437772 --- /dev/null +++ b/tools/update-rust/update-rust.sh @@ -0,0 +1,134 @@ +#!/bin/bash + +source ./git-utils.sh + +# Check if the script has the required parameters +if [[ $# -ne 3 ]]; then + log_err "Error invalid parameters" + log "Usage: $0 " + exit 1 +fi + +FROM_VERSION=$1 +TO_VERSION=$2 +ZISK_RUST_DIR="$(realpath "$3")/rust" +REMOTE_NAME="upstream" +CURRENT_FOLDER=$(pwd) + +log_info "Updating Rust version from ${FROM_VERSION} to ${TO_VERSION}" + +if [ ! -d "$ZISK_RUST_DIR" ]; then + # Cloning Zisk Rust repository + log_info "Cloning Zisk Rust repository in directory ${ZISK_RUST_DIR} (this will take some minutes)" + exec_git \ + "git clone git@github.com:0xPolygonHermez/rust.git ${ZISK_RUST_DIR}" \ + "Failed to clone Zisk Rust repository" + + # Change directory to Zisk Rust repository + cd ${ZISK_RUST_DIR} + + # Updating submodules + log_info "Updating submodules (this will take some minutes)" + exec_git \ + "git submodule update --init --recursive --progress" \ + "Failed to update submodules" +else + log_info "Zisk Rust repository already exists in directory ${ZISK_RUST_DIR}" + # Change directory to Zisk Rust repository + cd ${ZISK_RUST_DIR} +fi + +# Check if we are in ZISK_RUST_DIR directory +if [ "$(pwd)" != "$ZISK_RUST_DIR" ]; then + log_err "\e[1;31mError changing directory to '${ZISK_RUST_DIR}'" + exit 1 +fi + +# Check and add the remote if it doesn't exist +log_info "Checking if remote '${REMOTE_NAME}' exists" +if ! git remote | grep -q "^${REMOTE_NAME}$"; then + log "Remote '${REMOTE_NAME}' does not exist. Adding it" + exec_git \ + "git remote add ${REMOTE_NAME} git@github.com:rust-lang/rust.git" \ + "Failed to add remote '${REMOTE_NAME}'" +else + log "Remote '${REMOTE_NAME}' already exists." +fi + +# Fetch remote +log_info "Fetching remote '${REMOTE_NAME}'" +exec_git \ + "git fetch ${REMOTE_NAME}" \ + "Failed to fetch remote '${REMOTE_NAME}' branches" + +# Create and checkout new branch zisk-rust-${TO_VERSION} from upstream/stable branch +log_info "Creating and check out new branch 'zisk-rust-${TO_VERSION}' from 'upstream/stable' branch" +exec_git \ + "git checkout -b zisk-rust-${TO_VERSION} ${REMOTE_NAME}/stable" \ + "Failed to create new branch 'zisk-rust-${TO_VERSION}'" + +# Checkout 'zisk' branch +log_info "Checking out 'zisk' branch" +exec_git \ + "git checkout zisk" \ + "Failed to checkout 'zisk' branch" +# Verify current branch is zisk +current_branch=$(git rev-parse --abbrev-ref HEAD) +if [[ "$current_branch" != "zisk" ]]; then + log_err "\e[1;31mCurrent branch is not 'zisk'." + exit 1 +fi + +# List cherry picks +log_info "List of cherry picks to apply:" +exec_git \ + "git log --oneline --no-decorate --reverse ${FROM_VERSION}..HEAD" \ + "Failed to list cherry picks" +# Store the list of cherry-pick commits to apply in an array +commits_array=$(exec_git \ + "git log --oneline --no-decorate --reverse ${FROM_VERSION}..HEAD" \ + "Failed to get cherry picks") +IFS=$'\n' read -d '' -r -a commits_array <<< "$commits_array" +log_warn "Press a key to continue..." +read -n1 -s + +# Checkout 'zisk-rust-${TO_VERSION}' branch +log_info "Checking out 'zisk-rust-${TO_VERSION}' branch" +exec_git \ + "git checkout zisk-rust-${TO_VERSION}" \ + "Failed to checkout 'zisk-rust-${TO_VERSION}' branch" +# Verify current branch is zisk-rust-${TO_VERSION} +current_branch=$(git rev-parse --abbrev-ref HEAD) +if [[ "$current_branch" != "zisk-rust-${TO_VERSION}" ]]; then + log_err "\e[1;31mCurrent branch is not 'zisk-rust-${TO_VERSION}'." + exit 1 +fi + +# Apply cherry picks to branch zisk-rust-${TO_VERSION} +for line in "${commits_array[@]}"; do + commit=$(echo "$line" | awk '{print $1}') + msg=$(echo "$line" | cut -d' ' -f2-) + + log_info "Applying cherry pick for commit: ${msg} (${commit})" + output=$(git cherry-pick $commit -n 2>&1) + if ! [[ $? -eq 0 ]]; then + if [[ "$output" == *"CONFLICT"* ]]; then + printf "%s\n" "$output" + log_warn "\e[1;33mThe are CONFLICTS, please resolve them and after press a key to continue" + read -n1 -s + else + log_err "\e[1;31mFailed to apply cherry pick for commit: ${msg} (${commit})" + printf "%s\n" "$output" + exit 1 + fi + fi +done + +# Final instructions +echo +log_info "Now test build Zisk tool chain using the rust code in the directory ${ZISK_RUST_DIR} and new branch 'zisk-rust-${TO_VERSION}'" +log_info "When successfully tested, execute the following command to commit/merge the changes to 'zisk' branch and generate the release:" +echo +log "./release-rust.sh ${TO_VERSION} " +log "Example: ./release-rust.sh ${TO_VERSION} 0.2.0 $(realpath "$3")" +echo From dad15a70615c574397d96ee77287c5694637c7cb Mon Sep 17 00:00:00 2001 From: agnusmor Date: Wed, 15 Jan 2025 13:24:19 +0100 Subject: [PATCH 2/4] Change branch to "zisk" when building toolchain --- cli/src/commands/build_toolchain.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/commands/build_toolchain.rs b/cli/src/commands/build_toolchain.rs index e33589ea6..5b36dbb1e 100644 --- a/cli/src/commands/build_toolchain.rs +++ b/cli/src/commands/build_toolchain.rs @@ -33,7 +33,7 @@ impl BuildToolchainCmd { repo_url, "--depth=1", "--single-branch", - "--branch=stable", + "--branch=zisk", "zisk-rust", ]) .current_dir(&temp_dir) From 9e8b36a9f854c44a9f378bc8c13b37e6b5df43ab Mon Sep 17 00:00:00 2001 From: agnusmor Date: Tue, 28 Jan 2025 16:18:40 +0100 Subject: [PATCH 3/4] Fix pr GHA --- .github/workflows/pr.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 9162a431a..1191080d6 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -48,10 +48,22 @@ jobs: - name: Setup CI uses: ./.github/actions/setup + - name: Clean rust toolchain + run: | + rustup self uninstall -y || true + rm -rf ~/.rustup ~/.cargo + + - name: Install rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + components: rustfmt + - name: Run cargo fmt uses: actions-rs/cargo@v1 with: - toolchain: nightly + toolchain: stable command: fmt args: --all -- --check env: From 39d4482120a377ad2f6a07896113bcb9e36912ed Mon Sep 17 00:00:00 2001 From: agnusmor Date: Tue, 28 Jan 2025 16:12:49 +0100 Subject: [PATCH 4/4] Fix Clippy format errors --- cli/src/commands/install_toolchain.rs | 8 +- core/src/elf2rom.rs | 6 +- core/src/zisk_inst.rs | 26 ++--- emulator/src/emu.rs | 34 +++--- emulator/src/emu_options.rs | 12 +- emulator/src/stats.rs | 28 ++--- rustfmt.toml | 18 +-- state-machines/arith/src/arith_full.rs | 16 +-- state-machines/arith/src/arith_operation.rs | 110 +++++++++--------- .../arith/src/arith_operation_test.rs | 42 +++---- .../arith/src/arith_range_table_helpers.rs | 12 +- .../arith/src/arith_table_helpers.rs | 40 +++---- state-machines/binary/src/binary_basic.rs | 30 ++--- .../binary/src/binary_basic_table.rs | 110 +++++++++--------- state-machines/binary/src/binary_extension.rs | 24 ++-- state-machines/mem/src/mem_align_rom_sm.rs | 6 +- state-machines/mem/src/mem_bus_helpers.rs | 12 +- state-machines/mem/src/mem_constants.rs | 6 +- state-machines/mem/src/mem_debug.rs | 18 +-- state-machines/mem/src/mem_helpers.rs | 8 +- state-machines/mem/src/mem_module_instance.rs | 6 +- state-machines/mem/src/mem_module_planner.rs | 20 ++-- state-machines/mem/src/mem_planner.rs | 6 +- 23 files changed, 300 insertions(+), 298 deletions(-) diff --git a/cli/src/commands/install_toolchain.rs b/cli/src/commands/install_toolchain.rs index 17be7b55e..d8c90f158 100644 --- a/cli/src/commands/install_toolchain.rs +++ b/cli/src/commands/install_toolchain.rs @@ -36,10 +36,10 @@ impl InstallToolchainCmd { if let Ok(entry) = entry { let entry_path = entry.path(); let entry_name = entry_path.file_name().unwrap(); - if entry_path.is_dir() && - entry_name != "bin" && - entry_name != "circuits" && - entry_name != "toolchains" + if entry_path.is_dir() + && entry_name != "bin" + && entry_name != "circuits" + && entry_name != "toolchains" { if let Err(err) = fs::remove_dir_all(&entry_path) { println!("Failed to remove directory {:?}: {}", entry_path, err); diff --git a/core/src/elf2rom.rs b/core/src/elf2rom.rs index 3c253638e..640213693 100644 --- a/core/src/elf2rom.rs +++ b/core/src/elf2rom.rs @@ -65,9 +65,9 @@ pub fn elf2rom(elf_file: String) -> Result> { // Add init data as a read/write memory section, initialized by code // If the data is a writable memory section, add it to the ROM memory using Zisk // copy instructions - if (section_header.sh_flags & SHF_WRITE as u64) != 0 && - addr >= RAM_ADDR && - addr + data.len() as u64 <= RAM_ADDR + RAM_SIZE + if (section_header.sh_flags & SHF_WRITE as u64) != 0 + && addr >= RAM_ADDR + && addr + data.len() as u64 <= RAM_ADDR + RAM_SIZE { //println! {"elf2rom() new RW from={:x} length={:x}={}", addr, data.len(), //data.len()}; diff --git a/core/src/zisk_inst.rs b/core/src/zisk_inst.rs index be6e575ce..989d6d507 100644 --- a/core/src/zisk_inst.rs +++ b/core/src/zisk_inst.rs @@ -228,19 +228,19 @@ impl ZiskInst { /// Constructs a `flags`` bitmap made of combinations of fields of the Zisk instruction. This /// field is used by the PIL to proof some of the operations. pub fn get_flags(&self) -> u64 { - let flags: u64 = 1 | - (((self.a_src == SRC_IMM) as u64) << 1) | - (((self.a_src == SRC_MEM) as u64) << 2) | - (((self.a_src == SRC_STEP) as u64) << 3) | - (((self.b_src == SRC_IMM) as u64) << 4) | - (((self.b_src == SRC_MEM) as u64) << 5) | - ((self.is_external_op as u64) << 6) | - ((self.store_ra as u64) << 7) | - (((self.store == STORE_MEM) as u64) << 8) | - (((self.store == STORE_IND) as u64) << 9) | - ((self.set_pc as u64) << 10) | - ((self.m32 as u64) << 11) | - (((self.b_src == SRC_IND) as u64) << 12); + let flags: u64 = 1 + | (((self.a_src == SRC_IMM) as u64) << 1) + | (((self.a_src == SRC_MEM) as u64) << 2) + | (((self.a_src == SRC_STEP) as u64) << 3) + | (((self.b_src == SRC_IMM) as u64) << 4) + | (((self.b_src == SRC_MEM) as u64) << 5) + | ((self.is_external_op as u64) << 6) + | ((self.store_ra as u64) << 7) + | (((self.store == STORE_MEM) as u64) << 8) + | (((self.store == STORE_IND) as u64) << 9) + | ((self.set_pc as u64) << 10) + | ((self.m32 as u64) << 11) + | (((self.b_src == SRC_IND) as u64) << 12); flags } diff --git a/emulator/src/emu.rs b/emulator/src/emu.rs index b29d627fe..6195d5050 100644 --- a/emulator/src/emu.rs +++ b/emulator/src/emu.rs @@ -39,9 +39,9 @@ impl MemBusHelpers { [ MEMORY_LOAD_OP, addr as u64, - MEM_STEP_BASE + - MAX_MEM_OPS_BY_MAIN_STEP * step + - MAX_MEM_OPS_BY_STEP_OFFSET * step_offset as u64, + MEM_STEP_BASE + + MAX_MEM_OPS_BY_MAIN_STEP * step + + MAX_MEM_OPS_BY_STEP_OFFSET * step_offset as u64, bytes as u64, mem_values[0], mem_values[1], @@ -59,9 +59,9 @@ impl MemBusHelpers { [ MEMORY_STORE_OP, addr as u64, - MEM_STEP_BASE + - MAX_MEM_OPS_BY_MAIN_STEP * step + - MAX_MEM_OPS_BY_STEP_OFFSET * step_offset as u64, + MEM_STEP_BASE + + MAX_MEM_OPS_BY_MAIN_STEP * step + + MAX_MEM_OPS_BY_STEP_OFFSET * step_offset as u64, bytes as u64, mem_values[0], mem_values[1], @@ -1343,9 +1343,9 @@ impl<'a> Emu<'a> { } // Log emulation step, if requested - if options.print_step.is_some() && - (options.print_step.unwrap() != 0) && - ((self.ctx.inst_ctx.step % options.print_step.unwrap()) == 0) + if options.print_step.is_some() + && (options.print_step.unwrap() != 0) + && ((self.ctx.inst_ctx.step % options.print_step.unwrap()) == 0) { println!("step={}", self.ctx.inst_ctx.step); } @@ -1520,9 +1520,9 @@ impl<'a> Emu<'a> { // Increment step counter self.ctx.inst_ctx.step += 1; - if self.ctx.inst_ctx.end || - ((self.ctx.inst_ctx.step - self.ctx.last_callback_step) == - self.ctx.callback_steps) + if self.ctx.inst_ctx.end + || ((self.ctx.inst_ctx.step - self.ctx.last_callback_step) + == self.ctx.callback_steps) { // In run() we have checked the callback consistency with ctx.do_callback let callback = callback.as_ref().unwrap(); @@ -1820,8 +1820,8 @@ impl<'a> Emu<'a> { let b = [inst_ctx.b & 0xFFFFFFFF, (inst_ctx.b >> 32) & 0xFFFFFFFF]; let c = [inst_ctx.c & 0xFFFFFFFF, (inst_ctx.c >> 32) & 0xFFFFFFFF]; - let addr1 = (inst.b_offset_imm0 as i64 + - if inst.b_src == SRC_IND { inst_ctx.a as i64 } else { 0 }) as u64; + let addr1 = (inst.b_offset_imm0 as i64 + + if inst.b_src == SRC_IND { inst_ctx.a as i64 } else { 0 }) as u64; let jmp_offset1 = if inst.jmp_offset1 >= 0 { F::from_canonical_u64(inst.jmp_offset1 as u64) @@ -1899,9 +1899,9 @@ impl<'a> Emu<'a> { m32: F::from_bool(inst.m32), addr1: F::from_canonical_u64(addr1), __debug_operation_bus_enabled: F::from_bool( - inst.op_type == ZiskOperationType::Arith || - inst.op_type == ZiskOperationType::Binary || - inst.op_type == ZiskOperationType::BinaryE, + inst.op_type == ZiskOperationType::Arith + || inst.op_type == ZiskOperationType::Binary + || inst.op_type == ZiskOperationType::BinaryE, ), } } diff --git a/emulator/src/emu_options.rs b/emulator/src/emu_options.rs index acd7bae1c..0703ab80c 100644 --- a/emulator/src/emu_options.rs +++ b/emulator/src/emu_options.rs @@ -98,11 +98,11 @@ impl fmt::Display for EmuOptions { impl EmuOptions { /// Returns true if the configuration allows to emulate in fast mode, maximizing the performance pub fn is_fast(&self) -> bool { - self.trace_steps.is_none() && - (self.print_step.is_none() || (self.print_step.unwrap() == 0)) && - self.trace.is_none() && - !self.log_step && - !self.verbose && - !self.tracerv + self.trace_steps.is_none() + && (self.print_step.is_none() || (self.print_step.unwrap() == 0)) + && self.trace.is_none() + && !self.log_step + && !self.verbose + && !self.tracerv } } diff --git a/emulator/src/stats.rs b/emulator/src/stats.rs index c6a16fee0..80b0ffecd 100644 --- a/emulator/src/stats.rs +++ b/emulator/src/stats.rs @@ -185,22 +185,22 @@ impl Stats { output += &format!(" COST_STEP: {:02} sec\n", COST_STEP); // Calculate some aggregated counters to be used in the logs - let total_mem_ops = self.mops.mread_na1 + - self.mops.mread_na2 + - self.mops.mread_a + - self.mops.mwrite_na1 + - self.mops.mwrite_na2 + - self.mops.mwrite_a; - let total_mem_align_steps = self.mops.mread_na1 + - self.mops.mread_na2 * 2 + - self.mops.mwrite_na1 * 2 + - self.mops.mwrite_na2 * 4; + let total_mem_ops = self.mops.mread_na1 + + self.mops.mread_na2 + + self.mops.mread_a + + self.mops.mwrite_na1 + + self.mops.mwrite_na2 + + self.mops.mwrite_a; + let total_mem_align_steps = self.mops.mread_na1 + + self.mops.mread_na2 * 2 + + self.mops.mwrite_na1 * 2 + + self.mops.mwrite_na2 * 4; let cost_mem = total_mem_ops as f64 * COST_MEM; - let cost_mem_align = self.mops.mread_na1 as f64 * COST_MEMA_R1 + - self.mops.mread_na2 as f64 * COST_MEMA_R2 + - self.mops.mwrite_na1 as f64 * COST_MEMA_W1 + - self.mops.mwrite_na2 as f64 * COST_MEMA_W2; + let cost_mem_align = self.mops.mread_na1 as f64 * COST_MEMA_R1 + + self.mops.mread_na2 as f64 * COST_MEMA_R2 + + self.mops.mwrite_na1 as f64 * COST_MEMA_W1 + + self.mops.mwrite_na2 as f64 * COST_MEMA_W2; // Declare some total counters for the opcodes let mut total_opcodes: u64 = 0; diff --git a/rustfmt.toml b/rustfmt.toml index 66b2930ca..da925d8cb 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,11 +1,13 @@ reorder_imports = true -imports_granularity = "Crate" use_small_heuristics = "Max" -comment_width = 100 -wrap_comments = true -binop_separator = "Back" -trailing_comma = "Vertical" -trailing_semicolon = false use_field_init_shorthand = true -format_code_in_doc_comments = true -doc_comment_code_block_width = 100 \ No newline at end of file + +## Nightly options: +# imports_granularity = "Crate" +# comment_width = 100 +# wrap_comments = true +# binop_separator = "Front" +# trailing_comma = "Vertical" +# trailing_semicolon = false +# format_code_in_doc_comments = true +# doc_comment_code_block_width = 100 \ No newline at end of file diff --git a/state-machines/arith/src/arith_full.rs b/state-machines/arith/src/arith_full.rs index 4d8975438..d496fe3cf 100644 --- a/state-machines/arith/src/arith_full.rs +++ b/state-machines/arith/src/arith_full.rs @@ -260,14 +260,14 @@ impl ArithFullSM { step, opcode, ZiskOperationType::Binary as u64, - aop.d[0] + - CHUNK_SIZE * aop.d[1] + - CHUNK_SIZE.pow(2) * (aop.d[2] + extension.0) + - CHUNK_SIZE.pow(3) * aop.d[3], - aop.b[0] + - CHUNK_SIZE * aop.b[1] + - CHUNK_SIZE.pow(2) * (aop.b[2] + extension.1) + - CHUNK_SIZE.pow(3) * aop.b[3], + aop.d[0] + + CHUNK_SIZE * aop.d[1] + + CHUNK_SIZE.pow(2) * (aop.d[2] + extension.0) + + CHUNK_SIZE.pow(3) * aop.d[3], + aop.b[0] + + CHUNK_SIZE * aop.b[1] + + CHUNK_SIZE.pow(2) * (aop.b[2] + extension.1) + + CHUNK_SIZE.pow(3) * aop.b[3], ) .to_vec()] } else { diff --git a/state-machines/arith/src/arith_operation.rs b/state-machines/arith/src/arith_operation.rs index a20c8c9e1..be9f9522b 100644 --- a/state-machines/arith/src/arith_operation.rs +++ b/state-machines/arith/src/arith_operation.rs @@ -146,22 +146,22 @@ impl ArithOperation { self.op = op; self.input_a = input_a; self.input_b = input_b; - self.div_by_zero = input_b == 0 && - (op == ZiskOp::Div.code() || - op == ZiskOp::Rem.code() || - op == ZiskOp::DivW.code() || - op == ZiskOp::RemW.code() || - op == ZiskOp::Divu.code() || - op == ZiskOp::Remu.code() || - op == ZiskOp::DivuW.code() || - op == ZiskOp::RemuW.code()); - - self.div_overflow = ((op == ZiskOp::Div.code() || op == ZiskOp::Rem.code()) && - input_a == 0x8000_0000_0000_0000 && - input_b == 0xFFFF_FFFF_FFFF_FFFF) || - ((op == ZiskOp::DivW.code() || op == ZiskOp::RemW.code()) && - input_a == 0x8000_0000 && - input_b == 0xFFFF_FFFF); + self.div_by_zero = input_b == 0 + && (op == ZiskOp::Div.code() + || op == ZiskOp::Rem.code() + || op == ZiskOp::DivW.code() + || op == ZiskOp::RemW.code() + || op == ZiskOp::Divu.code() + || op == ZiskOp::Remu.code() + || op == ZiskOp::DivuW.code() + || op == ZiskOp::RemuW.code()); + + self.div_overflow = ((op == ZiskOp::Div.code() || op == ZiskOp::Rem.code()) + && input_a == 0x8000_0000_0000_0000 + && input_b == 0xFFFF_FFFF_FFFF_FFFF) + || ((op == ZiskOp::DivW.code() || op == ZiskOp::RemW.code()) + && input_a == 0x8000_0000 + && input_b == 0xFFFF_FFFF); let [a, b, c, d] = Self::calculate_abcd_from_ab(op, input_a, input_b); self.a = Self::u64_to_chunks(a); @@ -618,15 +618,15 @@ impl ArithOperation { assert!(range_c1 == 0 || range_c3 == 0, "range_c1:{} range_c3:{}", range_c1, range_c3); assert!(range_d1 == 0 || range_d3 == 0, "range_d1:{} range_d3:{}", range_d1, range_d3); - self.range_ab = (range_a3 + range_a1) * 3 + - range_b3 + - range_b1 + - if (range_a1 + range_b1) > 0 { 8 } else { 0 }; + self.range_ab = (range_a3 + range_a1) * 3 + + range_b3 + + range_b1 + + if (range_a1 + range_b1) > 0 { 8 } else { 0 }; - self.range_cd = (range_c3 + range_c1) * 3 + - range_d3 + - range_d1 + - if (range_c1 + range_d1) > 0 { 8 } else { 0 }; + self.range_cd = (range_c3 + range_c1) * 3 + + range_d3 + + range_d1 + + if (range_c1 + range_d1) > 0 { 8 } else { 0 }; } /// Calculates the operation's output chunks for further processing. @@ -655,40 +655,40 @@ impl ArithOperation { let nb_fa = nb * (1 - 2 * na); chunks[0] = fab * a[0] * b[0] // chunk0 - - c[0] + - 2 * np * c[0] + - div * d[0] - - 2 * nr * d[0]; + - c[0] + + 2 * np * c[0] + + div * d[0] + - 2 * nr * d[0]; chunks[1] = fab * a[1] * b[0] // chunk1 - + fab * a[0] * b[1] - - c[1] + - 2 * np * c[1] + - div * d[1] - - 2 * nr * d[1]; + + fab * a[0] * b[1] + - c[1] + + 2 * np * c[1] + + div * d[1] + - 2 * nr * d[1]; chunks[2] = fab * a[2] * b[0] // chunk2 + fab * a[1] * b[1] + fab * a[0] * b[2] + a[0] * nb_fa * m32 - + b[0] * na_fb * m32 - - c[2] + - 2 * np * c[2] + - div * d[2] - - 2 * nr * d[2] - - np * div * m32 + - nr * m32; // div == 0 ==> nr = 0 + + b[0] * na_fb * m32 + - c[2] + + 2 * np * c[2] + + div * d[2] + - 2 * nr * d[2] + - np * div * m32 + + nr * m32; // div == 0 ==> nr = 0 chunks[3] = fab * a[3] * b[0] // chunk3 + fab * a[2] * b[1] + fab * a[1] * b[2] + fab * a[0] * b[3] + a[1] * nb_fa * m32 - + b[1] * na_fb * m32 - - c[3] + - 2 * np * c[3] + - div * d[3] - - 2 * nr * d[3]; + + b[1] * na_fb * m32 + - c[3] + + 2 * np * c[3] + + div * d[3] + - 2 * nr * d[3]; chunks[4] = fab * a[3] * b[1] // chunk4 + fab * a[2] * b[2] @@ -712,23 +712,23 @@ impl ArithOperation { chunks[5] = fab * a[3] * b[2] // chunk5 + fab * a[2] * b[3] + a[1] * nb_fa * (1 - m32) - + b[1] * na_fb * (1 - m32) - - d[1] * (1 - div) + - d[1] * 2 * np * (1 - div); + + b[1] * na_fb * (1 - m32) + - d[1] * (1 - div) + + d[1] * 2 * np * (1 - div); chunks[6] = fab * a[3] * b[3] // chunk6 + a[2] * nb_fa * (1 - m32) - + b[2] * na_fb * (1 - m32) - - d[2] * (1 - div) + - d[2] * 2 * np * (1 - div); + + b[2] * na_fb * (1 - m32) + - d[2] * (1 - div) + + d[2] * 2 * np * (1 - div); // 0x4000_0000_0000_0000__8000_0000_0000_0000 chunks[7] = 0x10000 * na * nb * (1 - m32) // chunk7 + a[3] * nb_fa * (1 - m32) - + b[3] * na_fb * (1 - m32) - - 0x10000 * np * (1 - div) * (1 - m32) - - d[3] * (1 - div) + - d[3] * 2 * np * (1 - div); + + b[3] * na_fb * (1 - m32) + - 0x10000 * np * (1 - div) * (1 - m32) + - d[3] * (1 - div) + + d[3] * 2 * np * (1 - div); chunks } diff --git a/state-machines/arith/src/arith_operation_test.rs b/state-machines/arith/src/arith_operation_test.rs index a42c74531..c82102b56 100644 --- a/state-machines/arith/src/arith_operation_test.rs +++ b/state-machines/arith/src/arith_operation_test.rs @@ -122,15 +122,15 @@ impl ArithOperationTest { fn is_m32_op(op: u8) -> bool { let zisk_op = ZiskOp::try_from_code(op).unwrap(); match zisk_op { - ZiskOp::Mul | - ZiskOp::Mulh | - ZiskOp::Mulsuh | - ZiskOp::Mulu | - ZiskOp::Muluh | - ZiskOp::Divu | - ZiskOp::Remu | - ZiskOp::Div | - ZiskOp::Rem => false, + ZiskOp::Mul + | ZiskOp::Mulh + | ZiskOp::Mulsuh + | ZiskOp::Mulu + | ZiskOp::Muluh + | ZiskOp::Divu + | ZiskOp::Remu + | ZiskOp::Div + | ZiskOp::Rem => false, ZiskOp::MulW | ZiskOp::DivuW | ZiskOp::RemuW | ZiskOp::DivW | ZiskOp::RemW => true, _ => panic!("ArithOperationTest::is_m32_op() Invalid opcode={}", op), } @@ -186,26 +186,26 @@ impl ArithOperationTest { println!("{:#?}", aop); const CHUNK_SIZE: u64 = 0x10000; - let bus_a_low: u64 = aop.div as u64 * (aop.c[0] + aop.c[1] * CHUNK_SIZE) + - (1 - aop.div as u64) * (aop.a[0] + aop.a[1] * CHUNK_SIZE); - let bus_a_high: u64 = aop.div as u64 * (aop.c[2] + aop.c[3] * CHUNK_SIZE) + - (1 - aop.div as u64) * (aop.a[2] + aop.a[3] * CHUNK_SIZE); + let bus_a_low: u64 = aop.div as u64 * (aop.c[0] + aop.c[1] * CHUNK_SIZE) + + (1 - aop.div as u64) * (aop.a[0] + aop.a[1] * CHUNK_SIZE); + let bus_a_high: u64 = aop.div as u64 * (aop.c[2] + aop.c[3] * CHUNK_SIZE) + + (1 - aop.div as u64) * (aop.a[2] + aop.a[3] * CHUNK_SIZE); let bus_b_low: u64 = aop.b[0] + CHUNK_SIZE * aop.b[1]; let bus_b_high: u64 = aop.b[2] + CHUNK_SIZE * aop.b[3]; let secondary_res: u64 = if aop.main_mul || aop.main_div { 0 } else { 1 }; - let bus_res_low = secondary_res * (aop.d[0] + aop.d[1] * CHUNK_SIZE) + - aop.main_mul as u64 * (aop.c[0] + aop.c[1] * CHUNK_SIZE) + - aop.main_div as u64 * (aop.a[0] + aop.a[1] * CHUNK_SIZE); + let bus_res_low = secondary_res * (aop.d[0] + aop.d[1] * CHUNK_SIZE) + + aop.main_mul as u64 * (aop.c[0] + aop.c[1] * CHUNK_SIZE) + + aop.main_div as u64 * (aop.a[0] + aop.a[1] * CHUNK_SIZE); - let bus_res_high_64 = secondary_res * (aop.d[2] + aop.d[3] * CHUNK_SIZE) + - aop.main_mul as u64 * (aop.c[2] + aop.c[3] * CHUNK_SIZE) + - aop.main_div as u64 * (aop.a[2] + aop.a[3] * CHUNK_SIZE); + let bus_res_high_64 = secondary_res * (aop.d[2] + aop.d[3] * CHUNK_SIZE) + + aop.main_mul as u64 * (aop.c[2] + aop.c[3] * CHUNK_SIZE) + + aop.main_div as u64 * (aop.a[2] + aop.a[3] * CHUNK_SIZE); - let bus_res_high = if aop.sext && !aop.div_overflow { 0xFFFF_FFFF } else { 0 } + - (1 - aop.m32 as u64) * bus_res_high_64; + let bus_res_high = if aop.sext && !aop.div_overflow { 0xFFFF_FFFF } else { 0 } + + (1 - aop.m32 as u64) * bus_res_high_64; let expected_a_low = a & 0xFFFF_FFFF; let expected_a_high = (a >> 32) & 0xFFFF_FFFF; diff --git a/state-machines/arith/src/arith_range_table_helpers.rs b/state-machines/arith/src/arith_range_table_helpers.rs index d83cb8ff7..59a294b04 100644 --- a/state-machines/arith/src/arith_range_table_helpers.rs +++ b/state-machines/arith/src/arith_range_table_helpers.rs @@ -104,16 +104,16 @@ impl ArithRangeTableHelpers { assert!(range_index < 43); assert!(value >= if range_type == NEG { 0x8000 } else { 0 }); assert!( - value <= - match range_type { + value + <= match range_type { FULL => 0xFFFF, POS => 0x7FFF, NEG => 0xFFFF, _ => panic!("Invalid range type"), } ); - OFFSETS[range_index as usize] * 0x8000 + - if range_type == NEG { value - 0x8000 } else { value } as usize + OFFSETS[range_index as usize] * 0x8000 + + if range_type == NEG { value - 0x8000 } else { value } as usize } /// Calculates the row index for a carry range check based on the value. @@ -278,8 +278,8 @@ impl Iterator for ArithRangeTableInputsIterator<'_> { /// Retrieves the next row with non-zero multiplicity. fn next(&mut self) -> Option { if !self.iter_hash { - while self.iter_row < ROWS as u32 && - self.inputs.multiplicity[self.iter_row as usize] == 0 + while self.iter_row < ROWS as u32 + && self.inputs.multiplicity[self.iter_row as usize] == 0 { self.iter_row += 1; } diff --git a/state-machines/arith/src/arith_table_helpers.rs b/state-machines/arith/src/arith_table_helpers.rs index d3ae7df0c..336d9ab14 100644 --- a/state-machines/arith/src/arith_table_helpers.rs +++ b/state-machines/arith/src/arith_table_helpers.rs @@ -37,14 +37,14 @@ impl ArithTableHelpers { div_overflow: bool, ) -> usize { // Calculate the index into the ARITH_TABLE_ROWS lookup table. - let index = (op - FIRST_OP) as u64 * 128 + - na as u64 + - nb as u64 * 2 + - np as u64 * 4 + - nr as u64 * 8 + - sext as u64 * 16 + - div_by_zero as u64 * 32 + - div_overflow as u64 * 64; + let index = (op - FIRST_OP) as u64 * 128 + + na as u64 + + nb as u64 * 2 + + np as u64 * 4 + + nr as u64 * 8 + + sext as u64 * 16 + + div_by_zero as u64 * 32 + + div_overflow as u64 * 64; // Ensure the index is within the valid range. debug_assert!(index < ARITH_TABLE_ROWS.len() as u64); @@ -126,18 +126,18 @@ impl ArithTableHelpers { use crate::ARITH_TABLE; // Calculate flags for the operation. - let flags = if m32 { 1 } else { 0 } + - if div { 2 } else { 0 } + - if na { 4 } else { 0 } + - if nb { 8 } else { 0 } + - if np { 16 } else { 0 } + - if nr { 32 } else { 0 } + - if sext { 64 } else { 0 } + - if div_by_zero { 128 } else { 0 } + - if div_overflow { 256 } else { 0 } + - if main_mul { 512 } else { 0 } + - if main_div { 1024 } else { 0 } + - if signed { 2048 } else { 0 }; + let flags = if m32 { 1 } else { 0 } + + if div { 2 } else { 0 } + + if na { 4 } else { 0 } + + if nb { 8 } else { 0 } + + if np { 16 } else { 0 } + + if nr { 32 } else { 0 } + + if sext { 64 } else { 0 } + + if div_by_zero { 128 } else { 0 } + + if div_overflow { 256 } else { 0 } + + if main_mul { 512 } else { 0 } + + if main_div { 1024 } else { 0 } + + if signed { 2048 } else { 0 }; // Retrieve the row using the direct method. let row = Self::direct_get_row(op, na, nb, np, nr, sext, div_by_zero, div_overflow); diff --git a/state-machines/binary/src/binary_basic.rs b/state-machines/binary/src/binary_basic.rs index 7298f376a..9f92ecb57 100644 --- a/state-machines/binary/src/binary_basic.rs +++ b/state-machines/binary/src/binary_basic.rs @@ -229,9 +229,9 @@ impl BinaryBasicSM { } // If the chunk is signed, then the result is the sign of a - if (binary_basic_table_op == BinaryBasicTableOp::Min) && - (plast[i] == 1) && - (a_bytes[i] & 0x80) != (b_bytes[i] & 0x80) + if (binary_basic_table_op == BinaryBasicTableOp::Min) + && (plast[i] == 1) + && (a_bytes[i] & 0x80) != (b_bytes[i] & 0x80) { cout = if (a_bytes[i] & 0x80) != 0 { 1 } else { 0 }; } @@ -296,9 +296,9 @@ impl BinaryBasicSM { } // If the chunk is signed, then the result is the sign of a - if (binary_basic_table_op == BinaryBasicTableOp::Max) && - (plast[i] == 1) && - (a_bytes[i] & 0x80) != (b_bytes[i] & 0x80) + if (binary_basic_table_op == BinaryBasicTableOp::Max) + && (plast[i] == 1) + && (a_bytes[i] & 0x80) != (b_bytes[i] & 0x80) { cout = if (a_bytes[i] & 0x80) != 0 { 0 } else { 1 }; } @@ -473,9 +473,9 @@ impl BinaryBasicSM { } // If the chunk is signed, then the result is the sign of a - if (binary_basic_table_op.eq(&BinaryBasicTableOp::Lt)) && - (plast[i] == 1) && - (a_bytes[i] & 0x80) != (b_bytes[i] & 0x80) + if (binary_basic_table_op.eq(&BinaryBasicTableOp::Lt)) + && (plast[i] == 1) + && (a_bytes[i] & 0x80) != (b_bytes[i] & 0x80) { cout = if a_bytes[i] & 0x80 != 0 { 1 } else { 0 }; } @@ -715,9 +715,9 @@ impl BinaryBasicSM { if a_bytes[i] <= b_bytes[i] { cout = 1; } - if (binary_basic_table_op == BinaryBasicTableOp::Le) && - (plast[i] == 1) && - (a_bytes[i] & 0x80) != (b_bytes[i] & 0x80) + if (binary_basic_table_op == BinaryBasicTableOp::Le) + && (plast[i] == 1) + && (a_bytes[i] & 0x80) != (b_bytes[i] & 0x80) { cout = c; } @@ -861,9 +861,9 @@ impl BinaryBasicSM { // Set free_in_a_or_c and free_in_b_or_zero for i in 0..HALF_BYTES { - row.free_in_a_or_c[i] = mode64 * - (row.free_in_a[i + HALF_BYTES] - row.free_in_c[HALF_BYTES - 1]) + - row.free_in_c[HALF_BYTES - 1]; + row.free_in_a_or_c[i] = mode64 + * (row.free_in_a[i + HALF_BYTES] - row.free_in_c[HALF_BYTES - 1]) + + row.free_in_c[HALF_BYTES - 1]; row.free_in_b_or_zero[i] = mode64 * row.free_in_b[i + HALF_BYTES]; } diff --git a/state-machines/binary/src/binary_basic_table.rs b/state-machines/binary/src/binary_basic_table.rs index be52b2e68..4d4d105e0 100644 --- a/state-machines/binary/src/binary_basic_table.rs +++ b/state-machines/binary/src/binary_basic_table.rs @@ -139,23 +139,23 @@ impl BinaryBasicTableSM { /// Determines if the given opcode requires a "last" flag. fn opcode_has_last(opcode: BinaryBasicTableOp) -> bool { match opcode { - BinaryBasicTableOp::Minu | - BinaryBasicTableOp::Min | - BinaryBasicTableOp::Maxu | - BinaryBasicTableOp::Max | - BinaryBasicTableOp::LtAbsNP | - BinaryBasicTableOp::LtAbsPN | - BinaryBasicTableOp::Ltu | - BinaryBasicTableOp::Lt | - BinaryBasicTableOp::Gt | - BinaryBasicTableOp::Eq | - BinaryBasicTableOp::Add | - BinaryBasicTableOp::Sub | - BinaryBasicTableOp::Leu | - BinaryBasicTableOp::Le | - BinaryBasicTableOp::And | - BinaryBasicTableOp::Or | - BinaryBasicTableOp::Xor => true, + BinaryBasicTableOp::Minu + | BinaryBasicTableOp::Min + | BinaryBasicTableOp::Maxu + | BinaryBasicTableOp::Max + | BinaryBasicTableOp::LtAbsNP + | BinaryBasicTableOp::LtAbsPN + | BinaryBasicTableOp::Ltu + | BinaryBasicTableOp::Lt + | BinaryBasicTableOp::Gt + | BinaryBasicTableOp::Eq + | BinaryBasicTableOp::Add + | BinaryBasicTableOp::Sub + | BinaryBasicTableOp::Leu + | BinaryBasicTableOp::Le + | BinaryBasicTableOp::And + | BinaryBasicTableOp::Or + | BinaryBasicTableOp::Xor => true, BinaryBasicTableOp::Ext32 => false, } } @@ -163,50 +163,50 @@ impl BinaryBasicTableSM { /// Determines if the given opcode requires a carry-in value. fn opcode_has_cin(opcode: BinaryBasicTableOp) -> bool { match opcode { - BinaryBasicTableOp::Minu | - BinaryBasicTableOp::Min | - BinaryBasicTableOp::Maxu | - BinaryBasicTableOp::Max | - BinaryBasicTableOp::LtAbsNP | - BinaryBasicTableOp::LtAbsPN | - BinaryBasicTableOp::Ltu | - BinaryBasicTableOp::Lt | - BinaryBasicTableOp::Gt | - BinaryBasicTableOp::Eq | - BinaryBasicTableOp::Add | - BinaryBasicTableOp::Sub => true, - - BinaryBasicTableOp::Leu | - BinaryBasicTableOp::Le | - BinaryBasicTableOp::And | - BinaryBasicTableOp::Or | - BinaryBasicTableOp::Xor | - BinaryBasicTableOp::Ext32 => false, + BinaryBasicTableOp::Minu + | BinaryBasicTableOp::Min + | BinaryBasicTableOp::Maxu + | BinaryBasicTableOp::Max + | BinaryBasicTableOp::LtAbsNP + | BinaryBasicTableOp::LtAbsPN + | BinaryBasicTableOp::Ltu + | BinaryBasicTableOp::Lt + | BinaryBasicTableOp::Gt + | BinaryBasicTableOp::Eq + | BinaryBasicTableOp::Add + | BinaryBasicTableOp::Sub => true, + + BinaryBasicTableOp::Leu + | BinaryBasicTableOp::Le + | BinaryBasicTableOp::And + | BinaryBasicTableOp::Or + | BinaryBasicTableOp::Xor + | BinaryBasicTableOp::Ext32 => false, } } /// Determines if the given opcode's result depends on the "a" operand. fn opcode_result_is_a(opcode: BinaryBasicTableOp) -> bool { match opcode { - BinaryBasicTableOp::Minu | - BinaryBasicTableOp::Min | - BinaryBasicTableOp::Maxu | - BinaryBasicTableOp::Max => true, - - BinaryBasicTableOp::LtAbsNP | - BinaryBasicTableOp::LtAbsPN | - BinaryBasicTableOp::Ltu | - BinaryBasicTableOp::Lt | - BinaryBasicTableOp::Gt | - BinaryBasicTableOp::Eq | - BinaryBasicTableOp::Add | - BinaryBasicTableOp::Sub | - BinaryBasicTableOp::Leu | - BinaryBasicTableOp::Le | - BinaryBasicTableOp::And | - BinaryBasicTableOp::Or | - BinaryBasicTableOp::Xor | - BinaryBasicTableOp::Ext32 => false, + BinaryBasicTableOp::Minu + | BinaryBasicTableOp::Min + | BinaryBasicTableOp::Maxu + | BinaryBasicTableOp::Max => true, + + BinaryBasicTableOp::LtAbsNP + | BinaryBasicTableOp::LtAbsPN + | BinaryBasicTableOp::Ltu + | BinaryBasicTableOp::Lt + | BinaryBasicTableOp::Gt + | BinaryBasicTableOp::Eq + | BinaryBasicTableOp::Add + | BinaryBasicTableOp::Sub + | BinaryBasicTableOp::Leu + | BinaryBasicTableOp::Le + | BinaryBasicTableOp::And + | BinaryBasicTableOp::Or + | BinaryBasicTableOp::Xor + | BinaryBasicTableOp::Ext32 => false, } } diff --git a/state-machines/binary/src/binary_extension.rs b/state-machines/binary/src/binary_extension.rs index f67e8d022..100c6bd56 100644 --- a/state-machines/binary/src/binary_extension.rs +++ b/state-machines/binary/src/binary_extension.rs @@ -66,12 +66,12 @@ impl BinaryExtensionSM { /// Determines if the given opcode represents a shift operation. fn opcode_is_shift(opcode: ZiskOp) -> bool { match opcode { - ZiskOp::Sll | - ZiskOp::Srl | - ZiskOp::Sra | - ZiskOp::SllW | - ZiskOp::SrlW | - ZiskOp::SraW => true, + ZiskOp::Sll + | ZiskOp::Srl + | ZiskOp::Sra + | ZiskOp::SllW + | ZiskOp::SrlW + | ZiskOp::SraW => true, ZiskOp::SignExtendB | ZiskOp::SignExtendH | ZiskOp::SignExtendW => false, @@ -84,12 +84,12 @@ impl BinaryExtensionSM { match opcode { ZiskOp::SllW | ZiskOp::SrlW | ZiskOp::SraW => true, - ZiskOp::Sll | - ZiskOp::Srl | - ZiskOp::Sra | - ZiskOp::SignExtendB | - ZiskOp::SignExtendH | - ZiskOp::SignExtendW => false, + ZiskOp::Sll + | ZiskOp::Srl + | ZiskOp::Sra + | ZiskOp::SignExtendB + | ZiskOp::SignExtendH + | ZiskOp::SignExtendW => false, _ => panic!("BinaryExtensionSM::opcode_is_shift() got invalid opcode={:?}", opcode), } diff --git a/state-machines/mem/src/mem_align_rom_sm.rs b/state-machines/mem/src/mem_align_rom_sm.rs index 5445ed58b..4977e15fb 100644 --- a/state-machines/mem/src/mem_align_rom_sm.rs +++ b/state-machines/mem/src/mem_align_rom_sm.rs @@ -48,9 +48,9 @@ impl MemAlignRomSM { ), MemOp::TwoWrites => ( - 1 + ONE_WORD_COMBINATIONS * OP_SIZES[0] + - ONE_WORD_COMBINATIONS * OP_SIZES[1] + - TWO_WORD_COMBINATIONS * OP_SIZES[2], + 1 + ONE_WORD_COMBINATIONS * OP_SIZES[0] + + ONE_WORD_COMBINATIONS * OP_SIZES[1] + + TWO_WORD_COMBINATIONS * OP_SIZES[2], false, ), }; diff --git a/state-machines/mem/src/mem_bus_helpers.rs b/state-machines/mem/src/mem_bus_helpers.rs index 4cd4b396c..41c8d7353 100644 --- a/state-machines/mem/src/mem_bus_helpers.rs +++ b/state-machines/mem/src/mem_bus_helpers.rs @@ -19,9 +19,9 @@ impl MemBusHelpers { [ MEMORY_LOAD_OP as u64, addr as u64, - MEM_STEP_BASE + - MAX_MEM_OPS_BY_MAIN_STEP * step + - MAX_MEM_OPS_BY_STEP_OFFSET * step_offset as u64, + MEM_STEP_BASE + + MAX_MEM_OPS_BY_MAIN_STEP * step + + MAX_MEM_OPS_BY_STEP_OFFSET * step_offset as u64, bytes as u64, mem_values[0], mem_values[1], @@ -39,9 +39,9 @@ impl MemBusHelpers { [ MEMORY_STORE_OP as u64, addr as u64, - MEM_STEP_BASE + - MAX_MEM_OPS_BY_MAIN_STEP * step + - MAX_MEM_OPS_BY_STEP_OFFSET * step_offset as u64, + MEM_STEP_BASE + + MAX_MEM_OPS_BY_MAIN_STEP * step + + MAX_MEM_OPS_BY_STEP_OFFSET * step_offset as u64, bytes as u64, mem_values[0], mem_values[1], diff --git a/state-machines/mem/src/mem_constants.rs b/state-machines/mem/src/mem_constants.rs index bd3f7c815..263b19b2e 100644 --- a/state-machines/mem/src/mem_constants.rs +++ b/state-machines/mem/src/mem_constants.rs @@ -15,9 +15,9 @@ pub const MEM_REGS_MASK: u32 = 0xFFFF_FF00; pub const MEM_REGS_ADDR: u32 = 0xA000_0000; pub const MAX_MAIN_STEP: u64 = 0x1FFF_FFFF_FFFF_FFFF; -pub const MAX_MEM_STEP: u64 = MEM_STEP_BASE + - MAX_MEM_OPS_BY_MAIN_STEP * MAX_MAIN_STEP + - MAX_MEM_OPS_BY_STEP_OFFSET * MAX_MEM_STEP_OFFSET; +pub const MAX_MEM_STEP: u64 = MEM_STEP_BASE + + MAX_MEM_OPS_BY_MAIN_STEP * MAX_MAIN_STEP + + MAX_MEM_OPS_BY_STEP_OFFSET * MAX_MEM_STEP_OFFSET; pub const MAX_MEM_ADDR: u64 = 0xFFFF_FFFF; diff --git a/state-machines/mem/src/mem_debug.rs b/state-machines/mem/src/mem_debug.rs index b26739c5a..f84d0c06a 100644 --- a/state-machines/mem/src/mem_debug.rs +++ b/state-machines/mem/src/mem_debug.rs @@ -33,7 +33,7 @@ impl MemDebug { } pub fn log(&mut self, addr: u32, step: u64, bytes: u8, is_write: bool, is_internal: bool) { if addr < 0xA000_0000 { - return + return; } assert!(!self.prepared); let addr_w = MemHelpers::get_addr_w(addr); @@ -86,11 +86,11 @@ impl MemDebug { _ => panic!("Invalid bytes {}", bytes), }; let order = (order as u16) & 0x01; - let flags: u16 = if is_write { 0x100 } else { 0 } | - if internal { 0x80 } else { 0 } | - (order << 6) | - (offset << 3) | - bytes; + let flags: u16 = if is_write { 0x100 } else { 0 } + | if internal { 0x80 } else { 0 } + | (order << 6) + | (offset << 3) + | bytes; flags } pub fn flags_to_order(flags: u16) -> u8 { @@ -120,11 +120,11 @@ impl MemDebug { } fn prepare(&mut self) -> bool { if self.prepared { - return false + return false; } if self.ops.is_empty() { self.prepared = true; - return false + return false; } println!("[MemDebug] sorting information ....."); self.ops.sort_by_key(|op| (op.addr, op.step)); @@ -152,7 +152,7 @@ impl MemDebug { } pub fn save_to_file(&mut self, file_name: &str) { if !self.prepare() { - return + return; } println!("[MemDebug] writing information {} .....", file_name); let file = File::create(file_name).unwrap(); diff --git a/state-machines/mem/src/mem_helpers.rs b/state-machines/mem/src/mem_helpers.rs index 333232d55..16c117d5c 100644 --- a/state-machines/mem/src/mem_helpers.rs +++ b/state-machines/mem/src/mem_helpers.rs @@ -68,9 +68,9 @@ pub struct MemHelpers {} impl MemHelpers { pub fn main_step_to_address_step(step: u64, step_offset: u8) -> u64 { - MEM_STEP_BASE + - MAX_MEM_OPS_BY_MAIN_STEP * step + - MAX_MEM_OPS_BY_STEP_OFFSET * step_offset as u64 + MEM_STEP_BASE + + MAX_MEM_OPS_BY_MAIN_STEP * step + + MAX_MEM_OPS_BY_STEP_OFFSET * step_offset as u64 } pub fn is_aligned(addr: u32, width: u8) -> bool { (addr & MEM_ADDR_ALIGN_MASK) == 0 && width == 8 @@ -143,7 +143,7 @@ impl MemHelpers { let lo_mask = !(byte_mask << offset); let lo_write = (lo_mask & read_values[0]) | (value << offset); if !is_double { - return [lo_write, read_values[1]] + return [lo_write, read_values[1]]; } let hi_mask = !(byte_mask >> (64 - offset)); diff --git a/state-machines/mem/src/mem_module_instance.rs b/state-machines/mem/src/mem_module_instance.rs index a5e80813c..99e1d1b7a 100644 --- a/state-machines/mem/src/mem_module_instance.rs +++ b/state-machines/mem/src/mem_module_instance.rs @@ -136,9 +136,9 @@ impl MemModuleInstance { let mut input_index = 0; let mut skip_rows = 0; loop { - while self.inputs[input_index].addr == prev_segment.addr && - (self.inputs[input_index].step - prev_segment.step) > MEMORY_MAX_DIFF && - skip_rows < self.mem_check_point.skip_rows as usize + while self.inputs[input_index].addr == prev_segment.addr + && (self.inputs[input_index].step - prev_segment.step) > MEMORY_MAX_DIFF + && skip_rows < self.mem_check_point.skip_rows as usize { prev_segment.step += MEMORY_MAX_DIFF; skip_rows += 1; diff --git a/state-machines/mem/src/mem_module_planner.rs b/state-machines/mem/src/mem_module_planner.rs index ce51be91e..a97dfcda6 100644 --- a/state-machines/mem/src/mem_module_planner.rs +++ b/state-machines/mem/src/mem_module_planner.rs @@ -138,8 +138,8 @@ impl<'a> MemModulePlanner<'a> { { Ok(pos) => self.cursors.push((index, pos + REGISTERS_COUNT)), Err(pos) => { - if pos < counter.1.addr_sorted.len() && - counter.1.addr_sorted[pos].0 <= self.config.to_addr + if pos < counter.1.addr_sorted.len() + && counter.1.addr_sorted[pos].0 <= self.config.to_addr { self.cursors.push((index, pos + REGISTERS_COUNT)); } @@ -182,13 +182,13 @@ impl<'a> MemModulePlanner<'a> { }; let mut cursor_next_addr_pos = cursor_next_pos - REGISTERS_COUNT; - if cursor_on_registers && - cursor_next_addr_pos < self.counters[cursor_index].1.addr_sorted.len() + if cursor_on_registers + && cursor_next_addr_pos < self.counters[cursor_index].1.addr_sorted.len() { // filter addr out of [from_addr, to_addr] - while cursor_next_addr_pos < self.counters[cursor_index].1.addr_sorted.len() && - self.counters[cursor_index].1.addr_sorted[cursor_next_addr_pos].0 < - self.config.from_addr + while cursor_next_addr_pos < self.counters[cursor_index].1.addr_sorted.len() + && self.counters[cursor_index].1.addr_sorted[cursor_next_addr_pos].0 + < self.config.from_addr { cursor_next_addr_pos += 1; cursor_next_pos += 1; @@ -196,9 +196,9 @@ impl<'a> MemModulePlanner<'a> { } // if it's last position, we must remove for list of open_cursors, if not we increment - if cursor_next_addr_pos >= self.counters[cursor_index].1.addr_sorted.len() || - self.counters[cursor_index].1.addr_sorted[cursor_next_addr_pos].0 > - self.config.to_addr + if cursor_next_addr_pos >= self.counters[cursor_index].1.addr_sorted.len() + || self.counters[cursor_index].1.addr_sorted[cursor_next_addr_pos].0 + > self.config.to_addr { self.cursors.remove(min_index); } else { diff --git a/state-machines/mem/src/mem_planner.rs b/state-machines/mem/src/mem_planner.rs index 7d4593e98..167f59743 100644 --- a/state-machines/mem/src/mem_planner.rs +++ b/state-machines/mem/src/mem_planner.rs @@ -48,9 +48,9 @@ impl MemPlanner { use crate::MemModuleSegmentCheckPoint; for (index, plan) in plans.iter().enumerate() { - if plan.air_id == MEM_AIR_IDS[0] || - plan.air_id == INPUT_DATA_AIR_IDS[0] || - plan.air_id == ROM_DATA_AIR_IDS[0] + if plan.air_id == MEM_AIR_IDS[0] + || plan.air_id == INPUT_DATA_AIR_IDS[0] + || plan.air_id == ROM_DATA_AIR_IDS[0] { let meta = plan .meta