Skip to content

Conversation

@PetarMax
Copy link
Collaborator

@PetarMax PetarMax commented Aug 4, 2025

This PR introduces the following specifications and proofs:

  • IsEqualWord, IsZero, IsZeroWord, LtOperationSigned, LtOperationUnsigned, U16Compare, Add, Addw, Sub, Subw, U16MSB, and U16toU8Unsafe operations;
  • ALUType, CpuState, IType, and RType readers; and
  • all opcodes except Div- and Rem-related ones.

It also provides the proof of the axiom previously introduced in LtOperationSigned.

I would suggest that the proofs for other operations, readers, and opcodes that have appeared in the meantime be revisited in the style of the ones I've proven. In particular, the shift-right operation has the most streamlined structure that simplifies chip proofs greatly.

@PetarMax PetarMax requested review from GZGavinZhao and dtumad August 4, 2025 20:26
@PetarMax PetarMax self-assigned this Aug 4, 2025
@PetarMax PetarMax added the enhancement New feature or request label Aug 4, 2025
(cstrs : (constraints Main).allHold)
(h_is_real : Main[32] = 1)

def spec_add (rs2 rs1 rd : regidx) : SailM Unit := do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec_sub

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


open Sail

theorem correct_add
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct_sub

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

let op_a := sp1_op_a Main cstrs (srl_real Main srl)
-- TODO(gzgz): we can obtain this from the constraint compiler
-- This comes from the Interaction.state in CPUState
Sail.writeReg Register.nextPC (Word.toBitVec64 #v[Main[3], Main[4], Main[5], 0] + 4)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value that's actually being written is Word.toBitVec64 #v[Main[3] + 4, Main[4], Main[5], 0]. Could you please update all of your chip proof to use this instead? The equivalence holds using something like this:

      have : (↑(Main[3]$ + 4) + ↑Main[4]$ <<< 16 + ↑Main[5]$ <<< 32 : ℕ) = ↑Main[3]$ + ↑Main[4]$ <<< 16 + ↑Main[5]$ <<< 32 + 4 := by
        simp [Fin.add_def]
        rw [Nat.mod_eq_of_lt (by clear * - h_pc0; linarith)]
        ring_nf

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean here. Actually being written by whom? The Rust code of the reader?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case, done.

@dtumad dtumad merged commit 219a90c into main Aug 19, 2025
1 check failed
@dtumad dtumad deleted the petar/64-bit-ALU-verification branch October 2, 2025 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants