Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lean: Adding features to support bitfields #817

Open
wants to merge 13 commits into
base: sail2
Choose a base branch
from

Conversation

lfrenot
Copy link
Collaborator

@lfrenot lfrenot commented Dec 6, 2024

#833 should probably take priority

This translates

default Order dec

$include <prelude.sail>

bitfield cr_type : bits(8) = {
  CR0 : 7 .. 4,
  LT  : 7,
  GT  : 6,
  CR1 : 3 .. 2,
  CR3 : 1 .. 0
}

into

import Sail.Sail

structure cr_type  where
  bits : BitVec 8


def undefined_cr_type (lit : Unit) : cr_type :=
  sorry

def Mk_cr_type (v : BitVec 8) : cr_type :=
  {bits := v}

def _get_cr_type_bits (v : cr_type) : BitVec 8 :=
  (Sail.BitVec.extractLsb v.bits (HSub.hSub 8 1) 0)

def _update_cr_type_bits (v : cr_type) (x : BitVec 8) : cr_type :=
  {v with bits := (Sail.BitVec.update_subrange v.bits (HSub.hSub 8 1) 0 x)}

def _set_cr_type_bits (r_ref : register_ref Unit Unit cr_type) (v : BitVec 8) : Unit :=
  sorry

def _get_cr_type_CR0 (v : cr_type) : BitVec 4 :=
  (Sail.BitVec.extractLsb v.bits 7 4)

def _update_cr_type_CR0 (v : cr_type) (x : BitVec 4) : cr_type :=
  {v with bits := (Sail.BitVec.update_subrange v.bits 7 4 x)}

def _set_cr_type_CR0 (r_ref : register_ref Unit Unit cr_type) (v : BitVec 4) : Unit :=
  sorry

def _get_cr_type_CR1 (v : cr_type) : BitVec 2 :=
  (Sail.BitVec.extractLsb v.bits 3 2)

def _update_cr_type_CR1 (v : cr_type) (x : BitVec 2) : cr_type :=
  {v with bits := (Sail.BitVec.update_subrange v.bits 3 2 x)}

def _set_cr_type_CR1 (r_ref : register_ref Unit Unit cr_type) (v : BitVec 2) : Unit :=
  sorry

def _get_cr_type_CR3 (v : cr_type) : BitVec 2 :=
  (Sail.BitVec.extractLsb v.bits 1 0)

def _update_cr_type_CR3 (v : cr_type) (x : BitVec 2) : cr_type :=
  {v with bits := (Sail.BitVec.update_subrange v.bits 1 0 x)}

def _set_cr_type_CR3 (r_ref : register_ref Unit Unit cr_type) (v : BitVec 2) : Unit :=
  sorry

def _get_cr_type_GT (v : cr_type) : BitVec 1 :=
  (Sail.BitVec.extractLsb v.bits 6 6)

def _update_cr_type_GT (v : cr_type) (x : BitVec 1) : cr_type :=
  {v with bits := (Sail.BitVec.update_subrange v.bits 6 6 x)}

def _set_cr_type_GT (r_ref : register_ref Unit Unit cr_type) (v : BitVec 1) : Unit :=
  sorry

def _get_cr_type_LT (v : cr_type) : BitVec 1 :=
  (Sail.BitVec.extractLsb v.bits 7 7)

def _update_cr_type_LT (v : cr_type) (x : BitVec 1) : cr_type :=
  {v with bits := (Sail.BitVec.update_subrange v.bits 7 7 x)}

def _set_cr_type_LT (r_ref : register_ref Unit Unit cr_type) (v : BitVec 1) : Unit :=
  sorry

def initialize_registers : Unit :=
  ()

Copy link

github-actions bot commented Dec 6, 2024

Test Results

   12 files  ±0     24 suites  ±0   0s ⏱️ ±0s
  738 tests +1    738 ✅ +1  0 💤 ±0  0 ❌ ±0 
2 466 runs  +1  2 465 ✅ +1  1 💤 ±0  0 ❌ ±0 

Results for commit 492d310. ± Comparison against base commit 52d292a.

♻️ This comment has been updated with latest results.

@javra
Copy link
Collaborator

javra commented Dec 16, 2024

Looks good! The convention for Lean files is to start with an upper case, I think we'd better stick to that

@lfrenot lfrenot force-pushed the lean-record-features branch from f15991b to 84df9be Compare December 17, 2024 13:26
@lfrenot lfrenot marked this pull request as ready for review December 17, 2024 13:35
@lfrenot lfrenot force-pushed the lean-record-features branch from b0de2a6 to 4583c5a Compare December 17, 2024 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants