diff --git a/.claude/scripts/worktree-create.sh b/.claude/scripts/worktree-create.sh deleted file mode 100755 index 4c9c83fda2b..00000000000 --- a/.claude/scripts/worktree-create.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# WorktreeCreate hook for Claude Code -# Creates a git worktree and mounts overlayfs over target/ and node_modules/ -# so that heavy build caches and dependencies are shared copy-on-write. -# -# Input (JSON on stdin): { "name": "...", "cwd": "...", ... } -# Output (stdout): absolute path to the created worktree - -INPUT=$(cat) -NAME=$(echo "$INPUT" | jq -r '.name') -MAIN_DIR=$(echo "$INPUT" | jq -r '.cwd') - -WORKTREE_DIR="$MAIN_DIR/.claude/worktrees/$NAME" -OVERLAY_BASE="$WORKTREE_DIR/.overlays" - -# 1. Create the git worktree -git -C "$MAIN_DIR" worktree add -b "claude/$NAME" "$WORKTREE_DIR" HEAD --quiet - -# 2. Mount overlayfs layers if fuse-overlayfs is available -if command -v fuse-overlayfs >/dev/null 2>&1; then - # Mount an overlayfs for a directory (relative path from repo root) - mount_overlay() { - local rel_path="$1" - local src="$MAIN_DIR/$rel_path" - local dst="$WORKTREE_DIR/$rel_path" - - [ -d "$src" ] || return 0 - - local key - key=$(echo "$rel_path" | sed 's|/|__|g') - local upper="$OVERLAY_BASE/$key/upper" - local work="$OVERLAY_BASE/$key/work" - - mkdir -p "$dst" "$upper" "$work" - fuse-overlayfs \ - -o "lowerdir=$src,upperdir=$upper,workdir=$work" \ - "$dst" - } - - # Rust build cache - mount_overlay "target" - - # node_modules directories (pnpm workspace) - while IFS= read -r nm_dir; do - mount_overlay "${nm_dir#"$MAIN_DIR"/}" - done < <(find "$MAIN_DIR" \ - -path "$MAIN_DIR/.claude" -prune -o \ - -name node_modules -type d -print -prune) -fi - -# 3. Print the worktree path (required by Claude Code) -echo "$WORKTREE_DIR" diff --git a/.claude/scripts/worktree-remove.sh b/.claude/scripts/worktree-remove.sh deleted file mode 100755 index ce437f85662..00000000000 --- a/.claude/scripts/worktree-remove.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# WorktreeRemove hook for Claude Code -# Unmounts all overlayfs layers and removes the git worktree. -# -# Input (JSON on stdin): { "worktree_path": "...", "cwd": "...", ... } - -INPUT=$(cat) -WORKTREE_DIR=$(echo "$INPUT" | jq -r '.worktree_path') -MAIN_DIR=$(echo "$INPUT" | jq -r '.cwd') - -# 1. Unmount all overlayfs mounts within the worktree (reverse order for safety) -mount | grep -F " on $WORKTREE_DIR/" | awk '{print $3}' | sort -r | while read -r mnt; do - fusermount3 -u "$mnt" 2>/dev/null || fusermount -u "$mnt" 2>/dev/null || true -done - -# 2. Extract branch name before removing worktree -BRANCH=$(git -C "$WORKTREE_DIR" rev-parse --abbrev-ref HEAD 2>/dev/null || true) - -# 3. Remove the git worktree -git -C "$MAIN_DIR" worktree remove --force "$WORKTREE_DIR" 2>/dev/null || rm -rf "$WORKTREE_DIR" - -# 4. Clean up the temporary branch -if [ -n "$BRANCH" ] && [[ "$BRANCH" == claude/* ]]; then - git -C "$MAIN_DIR" branch -D "$BRANCH" 2>/dev/null || true -fi diff --git a/.claude/settings.json b/.claude/settings.json deleted file mode 100644 index c25e55284a2..00000000000 --- a/.claude/settings.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "hooks": { - "WorktreeCreate": [ - { - "hooks": [ - { - "type": "command", - "command": "bash .claude/scripts/worktree-create.sh" - } - ] - } - ], - "WorktreeRemove": [ - { - "hooks": [ - { - "type": "command", - "command": "bash .claude/scripts/worktree-remove.sh" - } - ] - } - ] - } -} diff --git a/.github/workflows/lydite.yml b/.github/workflows/lydite.yml index c529a5b5f7c..e3d0494f59d 100644 --- a/.github/workflows/lydite.yml +++ b/.github/workflows/lydite.yml @@ -5,8 +5,8 @@ name: lydite # linted, and unit-tested by ci.yml; this workflow runs lydite's own gates. on: - # Queue drafts run these gates on combined changes. Ordinary PRs skip all - # jobs; the weekly run catches drift between merges. + # Queue drafts run editor/replay checks on combined changes. Ordinary PRs + # skip all jobs; the expensive Veryl proof gates run only weekly or manually. push: branches: [develop] paths: @@ -121,7 +121,7 @@ jobs: retention-days: 14 veryl-fv: - if: github.event_name != 'pull_request' || startsWith(github.head_ref, 'mergify/merge-queue/') + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' runs-on: ubuntu-26.04 timeout-minutes: 30 steps: @@ -147,7 +147,7 @@ jobs: retention-days: 14 veryl-proof-corpus: - if: github.event_name != 'pull_request' || startsWith(github.head_ref, 'mergify/merge-queue/') + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' runs-on: ubuntu-26.04 # Cold builds plus the sequential proof/mutation gates can exceed one hour. timeout-minutes: 120 diff --git a/.gitignore b/.gitignore index 21578f46881..407dc7e5424 100644 --- a/.gitignore +++ b/.gitignore @@ -48,11 +48,6 @@ docs/.vitepress/.temp # TypeDoc generated API docs docs/api/ -# Overlay filesystem -.overlays/ -.overlay-upper/ -.overlay-work/ - # Benchmark output ts-output.json benches/verilator/obj_dir/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1074234f042..2cee2e5ed9d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -151,9 +151,12 @@ This does not prioritize jobs inside GitHub Actions or preempt occupied runners. See [Mergify priorities](https://docs.mergify.com/merge-queue/priority/) and [Mergify queue modes](https://docs.mergify.com/merge-queue/queue-modes/). -The separate lydite proof/editor gates run on queue drafts rather than ordinary -PRs; develop pushes, weekly runs, and manual dispatch remain enabled. -The `Queue validation` merge condition requires those pre-merge checks to pass; +The separate lydite documentation, editor, and Celox replay checks run on queue +drafts rather than ordinary PRs; develop pushes, weekly runs, and manual dispatch +remain enabled. The expensive `veryl-fv` and `veryl-proof-corpus` jobs run only +weekly (Monday at 03:41 UTC / 12:41 JST) or on manual dispatch, never on queue +drafts or develop pushes. These separate lydite checks are not merge requirements. +The `Queue validation` merge condition requires the selected checks in `ci.yml` to pass; ordinary PR checks cannot satisfy it. The `ci:full` label opts a PR into the same coverage on its next push. Unrelated paths may still skip jobs. @@ -208,7 +211,7 @@ uses the finer behavior-based matrix above. | Daily at 02:17 UTC (11:17 JST) | `codspeed.yml` measures compile time on the default branch using CPU simulation. Execution failures and CodSpeed performance-check failures open or update a branch issue; the next healthy run closes it. Manual dispatch supports branch measurements. PRs, merge groups, and pushes do not run CodSpeed. | | Daily at 02:37 UTC (11:37 JST) | `heliodor-bench.yml` runs the complete master Linux suite on x86-64 and AArch64. Explicit manual selections retain focused suite runs and ARM64 profiling. PRs run only the benchmark tooling tests when those files change. | | Every full CI run | Run every shared Veryl and SystemVerilog case against both Verilator and Icarus, with locked Nix tools. Run the live adapter tests normally marked ignored because they need external tools. Preserve reports and per-case diagnostics as artifacts for 14 days, including on failure; matrix failures do not cancel the other comparisons. | -| Weekly, and on pull requests with relevant changes | Existing `lydite.yml` proof, conformance, editor, and mutation gates. | +| Weekly Monday at 03:41 UTC (12:41 JST), or manual dispatch | All `lydite.yml` checks, including Veryl formal verification and proof/mutation corpus gates. The two Veryl jobs run only at this cadence; documentation, editor, and Celox replay checks also run on queue drafts and develop pushes with relevant changes. | | On demand | Dispatch `ci.yml` on the desired branch to run full CI and external comparisons, regardless of its diff. | | Pull requests that cut a release | A `master` pull request or legacy merge group whose diff changes `.release-please-manifest.json` (only the release pull request does there; syncing it into `develop` is not a release) runs full CI and the external comparisons. `Rust Test & NAPI Build` then requires the comparisons to pass, so a release cannot merge after only change-based checks. Daily and manual full runs do not gate on the comparisons; their failures reach the full CI issue below. A `master` pull request or legacy merge group whose diff cannot be determined is treated the same way. | diff --git a/crates/celox-backend-cranelift/src/translator/arith.rs b/crates/celox-backend-cranelift/src/translator/arith.rs index 77dd0473af2..a935dbc5005 100644 --- a/crates/celox-backend-cranelift/src/translator/arith.rs +++ b/crates/celox-backend-cranelift/src/translator/arith.rs @@ -369,6 +369,24 @@ impl SIRTranslator { } else { r }; + // Logical shifts by at least the physical width produce zero. + // `r` is zero-extended from a logical width no wider than + // `common_ty`, so this compares the real count without truncation. + let logical_shift_in_range = if matches!(op, BinaryOp::Shl | BinaryOp::Shr) { + Some(state.builder.ins().icmp_imm_u( + IntCC::UnsignedLessThan, + r, + i64::from(common_ty.bits()), + )) + } else { + None + }; + let saturate_logical_shift = |builder: &mut FunctionBuilder, shifted: Value| { + let in_range = + logical_shift_in_range.expect("logical shift count range is computed"); + let zero = builder.ins().iconst(common_ty, 0); + builder.ins().select(in_range, shifted, zero) + }; let build_icmp = |builder: &mut FunctionBuilder, cc: IntCC| { let b1_res = builder.ins().icmp(cc, l, r); @@ -424,11 +442,13 @@ impl SIRTranslator { BinaryOp::Or => state.builder.ins().bor(l, r), BinaryOp::Xor => state.builder.ins().bxor(l, r), BinaryOp::Shr => { - let shifted = state.builder.ins().ushr(l, r); + let raw = state.builder.ins().ushr(l, r); + let shifted = saturate_logical_shift(state.builder, raw); apply_d_width_mask(state, shifted, common_ty, d_width) } BinaryOp::Shl => { - let shifted = state.builder.ins().ishl(l, r); + let raw = state.builder.ins().ishl(l, r); + let shifted = saturate_logical_shift(state.builder, raw); apply_d_width_mask(state, shifted, common_ty, d_width) } BinaryOp::Sar => { @@ -510,7 +530,8 @@ impl SIRTranslator { BinaryOp::Shr => { let zero = state.builder.ins().iconst(common_ty, 0); let shift_amt_has_x = state.builder.ins().icmp(IntCC::NotEqual, r_m, zero); - let shifted_m = state.builder.ins().ushr(l_m, r); + let raw_m = state.builder.ins().ushr(l_m, r); + let shifted_m = saturate_logical_shift(state.builder, raw_m); let all_ones = state.builder.ins().iconst(common_ty, -1); let m = state .builder @@ -521,7 +542,8 @@ impl SIRTranslator { BinaryOp::Shl => { let zero = state.builder.ins().iconst(common_ty, 0); let shift_amt_has_x = state.builder.ins().icmp(IntCC::NotEqual, r_m, zero); - let shifted_m = state.builder.ins().ishl(l_m, r); + let raw_m = state.builder.ins().ishl(l_m, r); + let shifted_m = saturate_logical_shift(state.builder, raw_m); let all_ones = state.builder.ins().iconst(common_ty, -1); let m = state .builder diff --git a/crates/celox-backend-wasm/src/lib.rs b/crates/celox-backend-wasm/src/lib.rs index fed22a9006e..7a454a365ac 100644 --- a/crates/celox-backend-wasm/src/lib.rs +++ b/crates/celox-backend-wasm/src/lib.rs @@ -1648,9 +1648,11 @@ fn compile_binary_narrow( BinaryOp::Xor => instrs.push(Instruction::I64Xor), BinaryOp::Shl => { instrs.push(Instruction::I64Shl); + emit_logical_shift_saturation(instrs, r.value_idx); } BinaryOp::Shr => { instrs.push(Instruction::I64ShrU); + emit_logical_shift_saturation(instrs, r.value_idx); } BinaryOp::Sar => { // Arithmetic shift right — need sign extension first. @@ -2629,8 +2631,14 @@ fn compile_binary_mask_narrow( instrs.push(Instruction::LocalGet(rhs.value_idx)); } match op { - BinaryOp::Shl => instrs.push(Instruction::I64Shl), - BinaryOp::Shr => instrs.push(Instruction::I64ShrU), + BinaryOp::Shl => { + instrs.push(Instruction::I64Shl); + emit_logical_shift_saturation(instrs, rhs.value_idx); + } + BinaryOp::Shr => { + instrs.push(Instruction::I64ShrU); + emit_logical_shift_saturation(instrs, rhs.value_idx); + } BinaryOp::Sar => instrs.push(Instruction::I64ShrS), _ => unreachable!(), } @@ -5947,6 +5955,16 @@ fn emit_sar_count(instrs: &mut Vec>, count: u32) { instrs.push(Instruction::Select); } +/// Replaces the shifted value on the stack with zero when the logical shift +/// count is at least 64. Wasm shifts use the count modulo 64. +fn emit_logical_shift_saturation(instrs: &mut Vec>, count: u32) { + instrs.push(Instruction::I64Const(0)); + instrs.push(Instruction::LocalGet(count)); + instrs.push(Instruction::I64Const(64)); + instrs.push(Instruction::I64LtU); + instrs.push(Instruction::Select); +} + fn emit_sign_extend(instrs: &mut Vec>, local_idx: u32, width: usize) { instrs.push(Instruction::LocalGet(local_idx)); if width < 64 { diff --git a/crates/celox-test-suite/src/veryl/cases/logical_shift_count.vtest b/crates/celox-test-suite/src/veryl/cases/logical_shift_count.vtest new file mode 100644 index 00000000000..2b2bca776fb --- /dev/null +++ b/crates/celox-test-suite/src/veryl/cases/logical_shift_count.vtest @@ -0,0 +1,450 @@ +(group logical_shift_count (category operators)) + +; IEEE 1800-2023 11.4.10: logical shifts fill vacated bits with zero, so a +; known dynamic count of at least the operand width yields zero. + +(case two_state_dynamic_counts + (source "test.veryl" #" +module Top ( + sh: input logic<8>, + a5: input logic<5>, + shl5: output logic<5>, + shr5: output logic<5>, + a8: input logic<8>, + shl8: output logic<8>, + shr8: output logic<8>, + a32: input logic<32>, + shl32: output logic<32>, + shr32: output logic<32>, + a64: input logic<64>, + shl64: output logic<64>, + shr64: output logic<64> +) { + assign shl5 = a5 << sh; + assign shr5 = a5 >> sh; + assign shl8 = a8 << sh; + assign shr8 = a8 >> sh; + assign shl32 = a32 << sh; + assign shr32 = a32 >> sh; + assign shl64 = a64 << sh; + assign shr64 = a64 >> sh; +} +"#) + (top Top) + (modify + (set a5 0x1f) + (set a8 0xff) + (set a32 0xffffffff) + (set a64 0xffffffffffffffff)) + (modify (set sh 1)) + (assert_eq shl5 0x1e "5-bit << 1") + (assert_eq shr5 0xf "5-bit >> 1") + (assert_eq shl8 0xfe "8-bit << 1") + (assert_eq shr8 0x7f "8-bit >> 1") + (assert_eq shl32 0xfffffffe "32-bit << 1") + (assert_eq shr32 0x7fffffff "32-bit >> 1") + (assert_eq shl64 0xfffffffffffffffe "64-bit << 1") + (assert_eq shr64 0x7fffffffffffffff "64-bit >> 1") + (modify (set sh 4)) + (assert_eq shl5 0x10 "5-bit << 4") + (assert_eq shr5 0x1 "5-bit >> 4") + (assert_eq shl8 0xf0 "8-bit << 4") + (assert_eq shr8 0xf "8-bit >> 4") + (assert_eq shl32 0xfffffff0 "32-bit << 4") + (assert_eq shr32 0xfffffff "32-bit >> 4") + (assert_eq shl64 0xfffffffffffffff0 "64-bit << 4") + (assert_eq shr64 0xfffffffffffffff "64-bit >> 4") + (modify (set sh 5)) + (assert_eq shl5 0x0 "5-bit << 5") + (assert_eq shr5 0x0 "5-bit >> 5") + (assert_eq shl8 0xe0 "8-bit << 5") + (assert_eq shr8 0x7 "8-bit >> 5") + (assert_eq shl32 0xffffffe0 "32-bit << 5") + (assert_eq shr32 0x7ffffff "32-bit >> 5") + (assert_eq shl64 0xffffffffffffffe0 "64-bit << 5") + (assert_eq shr64 0x7ffffffffffffff "64-bit >> 5") + (modify (set sh 7)) + (assert_eq shl5 0x0 "5-bit << 7") + (assert_eq shr5 0x0 "5-bit >> 7") + (assert_eq shl8 0x80 "8-bit << 7") + (assert_eq shr8 0x1 "8-bit >> 7") + (assert_eq shl32 0xffffff80 "32-bit << 7") + (assert_eq shr32 0x1ffffff "32-bit >> 7") + (assert_eq shl64 0xffffffffffffff80 "64-bit << 7") + (assert_eq shr64 0x1ffffffffffffff "64-bit >> 7") + (modify (set sh 8)) + (assert_eq shl5 0x0 "5-bit << 8") + (assert_eq shr5 0x0 "5-bit >> 8") + (assert_eq shl8 0x0 "8-bit << 8") + (assert_eq shr8 0x0 "8-bit >> 8") + (assert_eq shl32 0xffffff00 "32-bit << 8") + (assert_eq shr32 0xffffff "32-bit >> 8") + (assert_eq shl64 0xffffffffffffff00 "64-bit << 8") + (assert_eq shr64 0xffffffffffffff "64-bit >> 8") + (modify (set sh 9)) + (assert_eq shl5 0x0 "5-bit << 9") + (assert_eq shr5 0x0 "5-bit >> 9") + (assert_eq shl8 0x0 "8-bit << 9") + (assert_eq shr8 0x0 "8-bit >> 9") + (assert_eq shl32 0xfffffe00 "32-bit << 9") + (assert_eq shr32 0x7fffff "32-bit >> 9") + (assert_eq shl64 0xfffffffffffffe00 "64-bit << 9") + (assert_eq shr64 0x7fffffffffffff "64-bit >> 9") + (modify (set sh 31)) + (assert_eq shl5 0x0 "5-bit << 31") + (assert_eq shr5 0x0 "5-bit >> 31") + (assert_eq shl8 0x0 "8-bit << 31") + (assert_eq shr8 0x0 "8-bit >> 31") + (assert_eq shl32 0x80000000 "32-bit << 31") + (assert_eq shr32 0x1 "32-bit >> 31") + (assert_eq shl64 0xffffffff80000000 "64-bit << 31") + (assert_eq shr64 0x1ffffffff "64-bit >> 31") + (modify (set sh 32)) + (assert_eq shl5 0x0 "5-bit << 32") + (assert_eq shr5 0x0 "5-bit >> 32") + (assert_eq shl8 0x0 "8-bit << 32") + (assert_eq shr8 0x0 "8-bit >> 32") + (assert_eq shl32 0x0 "32-bit << 32") + (assert_eq shr32 0x0 "32-bit >> 32") + (assert_eq shl64 0xffffffff00000000 "64-bit << 32") + (assert_eq shr64 0xffffffff "64-bit >> 32") + (modify (set sh 33)) + (assert_eq shl5 0x0 "5-bit << 33") + (assert_eq shr5 0x0 "5-bit >> 33") + (assert_eq shl8 0x0 "8-bit << 33") + (assert_eq shr8 0x0 "8-bit >> 33") + (assert_eq shl32 0x0 "32-bit << 33") + (assert_eq shr32 0x0 "32-bit >> 33") + (assert_eq shl64 0xfffffffe00000000 "64-bit << 33") + (assert_eq shr64 0x7fffffff "64-bit >> 33") + (modify (set sh 63)) + (assert_eq shl5 0x0 "5-bit << 63") + (assert_eq shr5 0x0 "5-bit >> 63") + (assert_eq shl8 0x0 "8-bit << 63") + (assert_eq shr8 0x0 "8-bit >> 63") + (assert_eq shl32 0x0 "32-bit << 63") + (assert_eq shr32 0x0 "32-bit >> 63") + (assert_eq shl64 0x8000000000000000 "64-bit << 63") + (assert_eq shr64 0x1 "64-bit >> 63") + (modify (set sh 64)) + (assert_eq shl5 0x0 "5-bit << 64") + (assert_eq shr5 0x0 "5-bit >> 64") + (assert_eq shl8 0x0 "8-bit << 64") + (assert_eq shr8 0x0 "8-bit >> 64") + (assert_eq shl32 0x0 "32-bit << 64") + (assert_eq shr32 0x0 "32-bit >> 64") + (assert_eq shl64 0x0 "64-bit << 64") + (assert_eq shr64 0x0 "64-bit >> 64") + (modify (set sh 65)) + (assert_eq shl5 0x0 "5-bit << 65") + (assert_eq shr5 0x0 "5-bit >> 65") + (assert_eq shl8 0x0 "8-bit << 65") + (assert_eq shr8 0x0 "8-bit >> 65") + (assert_eq shl32 0x0 "32-bit << 65") + (assert_eq shr32 0x0 "32-bit >> 65") + (assert_eq shl64 0x0 "64-bit << 65") + (assert_eq shr64 0x0 "64-bit >> 65") + (modify (set sh 128)) + (assert_eq shl5 0x0 "5-bit << 128") + (assert_eq shr5 0x0 "5-bit >> 128") + (assert_eq shl8 0x0 "8-bit << 128") + (assert_eq shr8 0x0 "8-bit >> 128") + (assert_eq shl32 0x0 "32-bit << 128") + (assert_eq shr32 0x0 "32-bit >> 128") + (assert_eq shl64 0x0 "64-bit << 128") + (assert_eq shr64 0x0 "64-bit >> 128") + (modify (set sh 255)) + (assert_eq shl5 0x0 "5-bit << 255") + (assert_eq shr5 0x0 "5-bit >> 255") + (assert_eq shl8 0x0 "8-bit << 255") + (assert_eq shr8 0x0 "8-bit >> 255") + (assert_eq shl32 0x0 "32-bit << 255") + (assert_eq shr32 0x0 "32-bit >> 255") + (assert_eq shl64 0x0 "64-bit << 255") + (assert_eq shr64 0x0 "64-bit >> 255")) + +(case two_state_single_bit_wrap + (source "test.veryl" #" +module Top ( + sh: input logic<8>, + lo5: input logic<5>, + hi5: input logic<5>, + shl5: output logic<5>, + shr5: output logic<5>, + lo8: input logic<8>, + hi8: input logic<8>, + shl8: output logic<8>, + shr8: output logic<8>, + lo32: input logic<32>, + hi32: input logic<32>, + shl32: output logic<32>, + shr32: output logic<32>, + lo64: input logic<64>, + hi64: input logic<64>, + shl64: output logic<64>, + shr64: output logic<64> +) { + assign shl5 = lo5 << sh; + assign shr5 = hi5 >> sh; + assign shl8 = lo8 << sh; + assign shr8 = hi8 >> sh; + assign shl32 = lo32 << sh; + assign shr32 = hi32 >> sh; + assign shl64 = lo64 << sh; + assign shr64 = hi64 >> sh; +} +"#) + (top Top) + (modify + (set lo5 0x1) + (set hi5 0x10) + (set lo8 0x1) + (set hi8 0x80) + (set lo32 0x1) + (set hi32 0x80000000) + (set lo64 0x1) + (set hi64 0x8000000000000000)) + (modify (set sh 8)) + (assert_eq shl5 0x0 "5-bit 1 << 8") + (assert_eq shr5 0x0 "5-bit msb >> 8") + (assert_eq shl8 0x0 "8-bit 1 << 8") + (assert_eq shr8 0x0 "8-bit msb >> 8") + (assert_eq shl32 0x100 "32-bit 1 << 8") + (assert_eq shr32 0x800000 "32-bit msb >> 8") + (assert_eq shl64 0x100 "64-bit 1 << 8") + (assert_eq shr64 0x80000000000000 "64-bit msb >> 8") + (modify (set sh 32)) + (assert_eq shl5 0x0 "5-bit 1 << 32") + (assert_eq shr5 0x0 "5-bit msb >> 32") + (assert_eq shl8 0x0 "8-bit 1 << 32") + (assert_eq shr8 0x0 "8-bit msb >> 32") + (assert_eq shl32 0x0 "32-bit 1 << 32") + (assert_eq shr32 0x0 "32-bit msb >> 32") + (assert_eq shl64 0x100000000 "64-bit 1 << 32") + (assert_eq shr64 0x80000000 "64-bit msb >> 32") + (modify (set sh 64)) + (assert_eq shl5 0x0 "5-bit 1 << 64") + (assert_eq shr5 0x0 "5-bit msb >> 64") + (assert_eq shl8 0x0 "8-bit 1 << 64") + (assert_eq shr8 0x0 "8-bit msb >> 64") + (assert_eq shl32 0x0 "32-bit 1 << 64") + (assert_eq shr32 0x0 "32-bit msb >> 64") + (assert_eq shl64 0x0 "64-bit 1 << 64") + (assert_eq shr64 0x0 "64-bit msb >> 64") + (modify (set sh 65)) + (assert_eq shl5 0x0 "5-bit 1 << 65") + (assert_eq shr5 0x0 "5-bit msb >> 65") + (assert_eq shl8 0x0 "8-bit 1 << 65") + (assert_eq shr8 0x0 "8-bit msb >> 65") + (assert_eq shl32 0x0 "32-bit 1 << 65") + (assert_eq shr32 0x0 "32-bit msb >> 65") + (assert_eq shl64 0x0 "64-bit 1 << 65") + (assert_eq shr64 0x0 "64-bit msb >> 65") + (modify (set sh 128)) + (assert_eq shl5 0x0 "5-bit 1 << 128") + (assert_eq shr5 0x0 "5-bit msb >> 128") + (assert_eq shl8 0x0 "8-bit 1 << 128") + (assert_eq shr8 0x0 "8-bit msb >> 128") + (assert_eq shl32 0x0 "32-bit 1 << 128") + (assert_eq shr32 0x0 "32-bit msb >> 128") + (assert_eq shl64 0x0 "64-bit 1 << 128") + (assert_eq shr64 0x0 "64-bit msb >> 128")) + +(case two_state_wide_count + (source "test.veryl" #" +module Top ( + n: input logic<72>, + a8: input logic<8>, + shl8: output logic<8>, + shr8: output logic<8>, + a64: input logic<64>, + shl64: output logic<64>, + shr64: output logic<64> +) { + assign shl8 = a8 << n; + assign shr8 = a8 >> n; + assign shl64 = a64 << n; + assign shr64 = a64 >> n; +} +"#) + (top Top) + (modify + (set a8 0xff) + (set a64 0xffffffffffffffff)) + (modify (set n 0x3)) + (assert_eq shl8 0xf8 "8-bit << 0x3") + (assert_eq shr8 0x1f "8-bit >> 0x3") + (assert_eq shl64 0xfffffffffffffff8 "64-bit << 0x3") + (assert_eq shr64 0x1fffffffffffffff "64-bit >> 0x3") + (modify (set n 0x40)) + (assert_eq shl8 0x0 "8-bit << 0x40") + (assert_eq shr8 0x0 "8-bit >> 0x40") + (assert_eq shl64 0x0 "64-bit << 0x40") + (assert_eq shr64 0x0 "64-bit >> 0x40") + (modify (set n 0x10000000000000000)) + (assert_eq shl8 0x0 "8-bit << 0x10000000000000000") + (assert_eq shr8 0x0 "8-bit >> 0x10000000000000000") + (assert_eq shl64 0x0 "64-bit << 0x10000000000000000") + (assert_eq shr64 0x0 "64-bit >> 0x10000000000000000") + (modify (set n 0x10000000000000001)) + (assert_eq shl8 0x0 "8-bit << 0x10000000000000001") + (assert_eq shr8 0x0 "8-bit >> 0x10000000000000001") + (assert_eq shl64 0x0 "64-bit << 0x10000000000000001") + (assert_eq shr64 0x0 "64-bit >> 0x10000000000000001") + (modify (set n 0xffffffffffffffffff)) + (assert_eq shl8 0x0 "8-bit << 0xffffffffffffffffff") + (assert_eq shr8 0x0 "8-bit >> 0xffffffffffffffffff") + (assert_eq shl64 0x0 "64-bit << 0xffffffffffffffffff") + (assert_eq shr64 0x0 "64-bit >> 0xffffffffffffffffff")) + +(case four_state_dynamic_counts + (four_state) + (source "test.veryl" #" +module Top ( + sh: input logic<8>, + a5: input logic<5>, + shl5: output logic<5>, + shr5: output logic<5>, + a8: input logic<8>, + shl8: output logic<8>, + shr8: output logic<8>, + a32: input logic<32>, + shl32: output logic<32>, + shr32: output logic<32>, + a64: input logic<64>, + shl64: output logic<64>, + shr64: output logic<64> +) { + assign shl5 = a5 << sh; + assign shr5 = a5 >> sh; + assign shl8 = a8 << sh; + assign shr8 = a8 >> sh; + assign shl32 = a32 << sh; + assign shr32 = a32 >> sh; + assign shl64 = a64 << sh; + assign shr64 = a64 >> sh; +} +"#) + (top Top) + (modify + (set a5 (fourstate 0x13 0x15)) + (set a8 (fourstate 0x83 0x91)) + (set a32 (fourstate 0x80000003 0x80010001)) + (set a64 (fourstate 0x8000000000000003 0x8000000100000001))) + (modify (set sh 1)) + (assert_eq shl5 (fourstate 0x6 0xa) "5-bit << 1") + (assert_eq shr5 (fourstate 0x9 0xa) "5-bit >> 1") + (assert_eq shl8 (fourstate 0x6 0x22) "8-bit << 1") + (assert_eq shr8 (fourstate 0x41 0x48) "8-bit >> 1") + (assert_eq shl32 (fourstate 0x6 0x20002) "32-bit << 1") + (assert_eq shr32 (fourstate 0x40000001 0x40008000) "32-bit >> 1") + (assert_eq shl64 (fourstate 0x6 0x200000002) "64-bit << 1") + (assert_eq shr64 (fourstate 0x4000000000000001 0x4000000080000000) "64-bit >> 1") + (modify (set sh 4)) + (assert_eq shl5 (fourstate 0x10 0x10) "5-bit << 4") + (assert_eq shr5 (fourstate 0x1 0x1) "5-bit >> 4") + (assert_eq shl8 (fourstate 0x30 0x10) "8-bit << 4") + (assert_eq shr8 (fourstate 0x8 0x9) "8-bit >> 4") + (assert_eq shl32 (fourstate 0x30 0x100010) "32-bit << 4") + (assert_eq shr32 (fourstate 0x8000000 0x8001000) "32-bit >> 4") + (assert_eq shl64 (fourstate 0x30 0x1000000010) "64-bit << 4") + (assert_eq shr64 (fourstate 0x800000000000000 0x800000010000000) "64-bit >> 4") + (modify (set sh 5)) + (assert_eq shl5 (fourstate 0x0 0x0) "5-bit << 5") + (assert_eq shr5 (fourstate 0x0 0x0) "5-bit >> 5") + (assert_eq shl8 (fourstate 0x60 0x20) "8-bit << 5") + (assert_eq shr8 (fourstate 0x4 0x4) "8-bit >> 5") + (assert_eq shl32 (fourstate 0x60 0x200020) "32-bit << 5") + (assert_eq shr32 (fourstate 0x4000000 0x4000800) "32-bit >> 5") + (assert_eq shl64 (fourstate 0x60 0x2000000020) "64-bit << 5") + (assert_eq shr64 (fourstate 0x400000000000000 0x400000008000000) "64-bit >> 5") + (modify (set sh 7)) + (assert_eq shl5 (fourstate 0x0 0x0) "5-bit << 7") + (assert_eq shr5 (fourstate 0x0 0x0) "5-bit >> 7") + (assert_eq shl8 (fourstate 0x80 0x80) "8-bit << 7") + (assert_eq shr8 (fourstate 0x1 0x1) "8-bit >> 7") + (assert_eq shl32 (fourstate 0x180 0x800080) "32-bit << 7") + (assert_eq shr32 (fourstate 0x1000000 0x1000200) "32-bit >> 7") + (assert_eq shl64 (fourstate 0x180 0x8000000080) "64-bit << 7") + (assert_eq shr64 (fourstate 0x100000000000000 0x100000002000000) "64-bit >> 7") + (modify (set sh 8)) + (assert_eq shl5 (fourstate 0x0 0x0) "5-bit << 8") + (assert_eq shr5 (fourstate 0x0 0x0) "5-bit >> 8") + (assert_eq shl8 (fourstate 0x0 0x0) "8-bit << 8") + (assert_eq shr8 (fourstate 0x0 0x0) "8-bit >> 8") + (assert_eq shl32 (fourstate 0x300 0x1000100) "32-bit << 8") + (assert_eq shr32 (fourstate 0x800000 0x800100) "32-bit >> 8") + (assert_eq shl64 (fourstate 0x300 0x10000000100) "64-bit << 8") + (assert_eq shr64 (fourstate 0x80000000000000 0x80000001000000) "64-bit >> 8") + (modify (set sh 9)) + (assert_eq shl5 (fourstate 0x0 0x0) "5-bit << 9") + (assert_eq shr5 (fourstate 0x0 0x0) "5-bit >> 9") + (assert_eq shl8 (fourstate 0x0 0x0) "8-bit << 9") + (assert_eq shr8 (fourstate 0x0 0x0) "8-bit >> 9") + (assert_eq shl32 (fourstate 0x600 0x2000200) "32-bit << 9") + (assert_eq shr32 (fourstate 0x400000 0x400080) "32-bit >> 9") + (assert_eq shl64 (fourstate 0x600 0x20000000200) "64-bit << 9") + (assert_eq shr64 (fourstate 0x40000000000000 0x40000000800000) "64-bit >> 9") + (modify (set sh 31)) + (assert_eq shl5 (fourstate 0x0 0x0) "5-bit << 31") + (assert_eq shr5 (fourstate 0x0 0x0) "5-bit >> 31") + (assert_eq shl8 (fourstate 0x0 0x0) "8-bit << 31") + (assert_eq shr8 (fourstate 0x0 0x0) "8-bit >> 31") + (assert_eq shl32 (fourstate 0x80000000 0x80000000) "32-bit << 31") + (assert_eq shr32 (fourstate 0x1 0x1) "32-bit >> 31") + (assert_eq shl64 (fourstate 0x180000000 0x8000000080000000) "64-bit << 31") + (assert_eq shr64 (fourstate 0x100000000 0x100000002) "64-bit >> 31") + (modify (set sh 32)) + (assert_eq shl5 (fourstate 0x0 0x0) "5-bit << 32") + (assert_eq shr5 (fourstate 0x0 0x0) "5-bit >> 32") + (assert_eq shl8 (fourstate 0x0 0x0) "8-bit << 32") + (assert_eq shr8 (fourstate 0x0 0x0) "8-bit >> 32") + (assert_eq shl32 (fourstate 0x0 0x0) "32-bit << 32") + (assert_eq shr32 (fourstate 0x0 0x0) "32-bit >> 32") + (assert_eq shl64 (fourstate 0x300000000 0x100000000) "64-bit << 32") + (assert_eq shr64 (fourstate 0x80000000 0x80000001) "64-bit >> 32") + (modify (set sh 33)) + (assert_eq shl5 (fourstate 0x0 0x0) "5-bit << 33") + (assert_eq shr5 (fourstate 0x0 0x0) "5-bit >> 33") + (assert_eq shl8 (fourstate 0x0 0x0) "8-bit << 33") + (assert_eq shr8 (fourstate 0x0 0x0) "8-bit >> 33") + (assert_eq shl32 (fourstate 0x0 0x0) "32-bit << 33") + (assert_eq shr32 (fourstate 0x0 0x0) "32-bit >> 33") + (assert_eq shl64 (fourstate 0x600000000 0x200000000) "64-bit << 33") + (assert_eq shr64 (fourstate 0x40000000 0x40000000) "64-bit >> 33") + (modify (set sh 63)) + (assert_eq shl5 (fourstate 0x0 0x0) "5-bit << 63") + (assert_eq shr5 (fourstate 0x0 0x0) "5-bit >> 63") + (assert_eq shl8 (fourstate 0x0 0x0) "8-bit << 63") + (assert_eq shr8 (fourstate 0x0 0x0) "8-bit >> 63") + (assert_eq shl32 (fourstate 0x0 0x0) "32-bit << 63") + (assert_eq shr32 (fourstate 0x0 0x0) "32-bit >> 63") + (assert_eq shl64 (fourstate 0x8000000000000000 0x8000000000000000) "64-bit << 63") + (assert_eq shr64 (fourstate 0x1 0x1) "64-bit >> 63") + (modify (set sh 64)) + (assert_eq shl5 (fourstate 0x0 0x0) "5-bit << 64") + (assert_eq shr5 (fourstate 0x0 0x0) "5-bit >> 64") + (assert_eq shl8 (fourstate 0x0 0x0) "8-bit << 64") + (assert_eq shr8 (fourstate 0x0 0x0) "8-bit >> 64") + (assert_eq shl32 (fourstate 0x0 0x0) "32-bit << 64") + (assert_eq shr32 (fourstate 0x0 0x0) "32-bit >> 64") + (assert_eq shl64 (fourstate 0x0 0x0) "64-bit << 64") + (assert_eq shr64 (fourstate 0x0 0x0) "64-bit >> 64") + (modify (set sh 65)) + (assert_eq shl5 (fourstate 0x0 0x0) "5-bit << 65") + (assert_eq shr5 (fourstate 0x0 0x0) "5-bit >> 65") + (assert_eq shl8 (fourstate 0x0 0x0) "8-bit << 65") + (assert_eq shr8 (fourstate 0x0 0x0) "8-bit >> 65") + (assert_eq shl32 (fourstate 0x0 0x0) "32-bit << 65") + (assert_eq shr32 (fourstate 0x0 0x0) "32-bit >> 65") + (assert_eq shl64 (fourstate 0x0 0x0) "64-bit << 65") + (assert_eq shr64 (fourstate 0x0 0x0) "64-bit >> 65") + (modify (set sh 255)) + (assert_eq shl5 (fourstate 0x0 0x0) "5-bit << 255") + (assert_eq shr5 (fourstate 0x0 0x0) "5-bit >> 255") + (assert_eq shl8 (fourstate 0x0 0x0) "8-bit << 255") + (assert_eq shr8 (fourstate 0x0 0x0) "8-bit >> 255") + (assert_eq shl32 (fourstate 0x0 0x0) "32-bit << 255") + (assert_eq shr32 (fourstate 0x0 0x0) "32-bit >> 255") + (assert_eq shl64 (fourstate 0x0 0x0) "64-bit << 255") + (assert_eq shr64 (fourstate 0x0 0x0) "64-bit >> 255")) diff --git a/crates/celox-test-suite/src/veryl/cases/mod.rs b/crates/celox-test-suite/src/veryl/cases/mod.rs index 3ad35cc33d2..4d6b0a4a49e 100644 --- a/crates/celox-test-suite/src/veryl/cases/mod.rs +++ b/crates/celox-test-suite/src/veryl/cases/mod.rs @@ -135,6 +135,10 @@ pub(super) const GROUPS: &[Group] = &[ file: "src/veryl/cases/linear_sorter_pull.vtest", text: include_str!("linear_sorter_pull.vtest"), }, + Group { + file: "src/veryl/cases/logical_shift_count.vtest", + text: include_str!("logical_shift_count.vtest"), + }, Group { file: "src/veryl/cases/loop_idiom.vtest", text: include_str!("loop_idiom.vtest"), diff --git a/crates/celox-test-suite/tests/external_adapter.rs b/crates/celox-test-suite/tests/external_adapter.rs index 0cd539d0ae3..cda2b717ee0 100644 --- a/crates/celox-test-suite/tests/external_adapter.rs +++ b/crates/celox-test-suite/tests/external_adapter.rs @@ -93,7 +93,7 @@ fn catalogue_has_unique_stable_names_and_categories() { assert!(names.insert(case.name), "duplicate {}", case.name); assert!(case.name.contains("::")); } - assert_eq!(names.len(), 745); + assert_eq!(names.len(), 749); assert_eq!( case("operators::test_bitwise_operations").unwrap().category, Category::Operators diff --git a/crates/celox/tests/logical_shift_count.rs b/crates/celox/tests/logical_shift_count.rs new file mode 100644 index 00000000000..71331aaac4e --- /dev/null +++ b/crates/celox/tests/logical_shift_count.rs @@ -0,0 +1,12 @@ +#[path = "test_utils/mod.rs"] +#[macro_use] +mod test_utils; + +// Dynamic logical shift counts of at least the operand width must yield zero +// rather than wrapping modulo the machine word on any backend. +all_backends! { + fn two_state_dynamic_counts(sim) { @case "logical_shift_count::two_state_dynamic_counts"; } + fn two_state_single_bit_wrap(sim) { @case "logical_shift_count::two_state_single_bit_wrap"; } + fn two_state_wide_count(sim) { @case "logical_shift_count::two_state_wide_count"; } + fn four_state_dynamic_counts(sim) { @case "logical_shift_count::four_state_dynamic_counts"; } +} diff --git a/flake.nix b/flake.nix index afa1f160971..615bff13f57 100644 --- a/flake.nix +++ b/flake.nix @@ -71,7 +71,6 @@ pkgs.cmake pkgs.pkg-config pkgs.openssl - pkgs.fuse-overlayfs pkgs.cargo-insta pkgs.cargo-nextest pkgs.git