From d5f3e7bc675a07bd04c746512c6f1b0b1250b55e Mon Sep 17 00:00:00 2001 From: Greg Brown Date: Sat, 8 Jan 2022 17:38:20 +0000 Subject: Make RawPseudocode contain its own bundles. --- src/Helium/Data/Pseudocode.agda | 283 ++++++++++++++++----------------- src/Helium/Semantics/Denotational.agda | 57 +++---- 2 files changed, 165 insertions(+), 175 deletions(-) diff --git a/src/Helium/Data/Pseudocode.agda b/src/Helium/Data/Pseudocode.agda index f683193..146dbf9 100644 --- a/src/Helium/Data/Pseudocode.agda +++ b/src/Helium/Data/Pseudocode.agda @@ -8,180 +8,179 @@ module Helium.Data.Pseudocode where +open import Algebra.Bundles using (RawRing) open import Algebra.Core -open import Data.Bool using (Bool; if_then_else_) -open import Data.Fin hiding (_+_; cast) -import Data.Fin.Properties as Finₚ -open import Data.Nat using (ℕ; zero; suc; _+_; _^_) -import Data.Vec as Vec +import Algebra.Definitions.RawSemiring as RS +open import Data.Bool.Base using (Bool; if_then_else_) +open import Data.Fin.Base as Fin hiding (cast) +import Data.Fin.Properties as Fₚ +import Data.Fin.Induction as Induction +open import Data.Nat.Base using (ℕ; zero; suc) +open import Data.Vec.Functional +open import Data.Vec.Functional.Relation.Binary.Pointwise using (Pointwise) +import Data.Vec.Functional.Relation.Binary.Pointwise.Properties as Pwₚ +open import Function using (_$_; _∘′_; id) +open import Helium.Algebra.Bundles using (RawField; RawBooleanAlgebra) open import Level using (_⊔_) renaming (suc to ℓsuc) -open import Relation.Binary using (REL; Rel; Symmetric; Transitive; Decidable) -open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym) -open import Relation.Nullary using (Dec; does) -open import Relation.Nullary.Decidable - -private - map-False : ∀ {p q} {P : Set p} {Q : Set q} {P? : Dec P} {Q? : Dec Q} → (P → Q) → False Q? → False P? - map-False ⇒ f = fromWitnessFalse (λ x → toWitnessFalse f (⇒ x)) +open import Relation.Binary.Core using (Rel) +open import Relation.Binary.Definitions using (Decidable) +open import Relation.Binary.PropositionalEquality as P using (_≡_) +open import Relation.Nullary using (does) +open import Relation.Nullary.Decidable.Core using (False; toWitnessFalse) record RawPseudocode b₁ b₂ i₁ i₂ i₃ r₁ r₂ r₃ : Set (ℓsuc (b₁ ⊔ b₂ ⊔ i₁ ⊔ i₂ ⊔ i₃ ⊔ r₁ ⊔ r₂ ⊔ r₃)) where - infix 9 _^ᶻ_ _^ʳ_ - infix 8 _⁻¹ - infixr 7 _*ᶻ_ _*ʳ_ - infix 6 -ᶻ_ -ʳ_ - infixr 5 _+ᶻ_ _+ʳ_ _∶_ - infix 4 _≈ᵇ_ _≟ᵇ_ _≈ᶻ_ _≟ᶻ_ _<ᶻ_ _>_ _>>_ : ℤ → ℕ → ℤ - x >> n = (x div (2ℤ ^ᶻ n)) {2^n≢0 n} - - getᶻ : ℕ → ℤ → Bits 1 - getᶻ i x = if (does ((x mod (2ℤ ^ᶻ suc i)) {2^n≢0 (suc i)} > zero = x + x >> suc n = (x div (1ℤ << suc n)) {1<> 1) + + uint : ∀ {n} → Bits n → ℤ + uint x = sumᶻ λ i → if hasBit i x then 1ℤ << toℕ i else 0ℤ + + sint : ∀ {n} → Bits n → ℤ + sint {zero} x = 0ℤ + sint {suc n} x = uint x -ᶻ (if hasBit (fromℕ n) x then 1ℤ << suc n else 0ℤ) diff --git a/src/Helium/Semantics/Denotational.agda b/src/Helium/Semantics/Denotational.agda index 8e2cf85..2a18957 100644 --- a/src/Helium/Semantics/Denotational.agda +++ b/src/Helium/Semantics/Denotational.agda @@ -17,20 +17,19 @@ open import Algebra.Core using (Op₂) open import Data.Bool as Bool using (Bool; true; false) open import Data.Fin as Fin hiding (cast; lift; _+_) import Data.Fin.Properties as Finₚ -open import Data.List using (List; []; _∷_) +import Data.List as List open import Data.Nat hiding (_⊔_) import Data.Nat.Properties as ℕₚ open import Data.Product using (∃; _×_; _,_; dmap) open import Data.Sum using ([_,_]′) -open import Data.Vec.Functional as V using (Vector) +open import Data.Vec.Functional as V using (Vector; []; _∷_) open import Function using (_$_; _∘₂_) open import Function.Nary.NonDependent.Base import Helium.Instructions as Instr import Helium.Semantics.Denotational.Core as Core -open import Level hiding (lift; zero; suc) -open import Relation.Binary using (Transitive) -open import Relation.Binary.PropositionalEquality -open import Relation.Nullary +open import Level using (Level; _⊔_) +open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; trans; cong) +open import Relation.Nullary using (does) open import Relation.Nullary.Decidable open RawPseudocode pseudocode @@ -45,7 +44,7 @@ record State : Set ℓ where R : Vector (Bits 32) 16 P0 : Bits 16 mask : Bits 8 - QC : Bits 1 + QC : Bit advanceVPT : Bool open Core State @@ -84,7 +83,7 @@ ElmtMask = Bits 4 &Q : ∀ {n ls} {Γ : Sets n ls} → PureExpr n Γ Instr.VecReg → PureExpr n Γ Beat → Reference n Γ (Bits 32) &Q reg beat = &S λ σ ρ → combine (reg σ ρ) (beat σ ρ) -&FPSCR-QC : ∀ {n ls} {Γ : Sets n ls} → Reference n Γ (Bits 1) +&FPSCR-QC : ∀ {n ls} {Γ : Sets n ls} → Reference n Γ Bit &FPSCR-QC = record { get = λ σ ρ → State.QC σ ; set = λ x σ ρ → record σ { QC = x } , ρ @@ -159,30 +158,25 @@ copyMasked : Instr.VecReg → Procedure 3 (Bits 32 , Beat , ElmtMask , _) copyMasked dest = for 4 ( -- 0:e 1:result 2:beat 3:elmtMask - if ⦇ (λ x y → does (getᵇ y x ≟ᵇ 1b)) (↓ !# 3) (↓ !# 0) ⦈ + if ⦇ hasBit (↓ !# 0) (↓ !# 3) ⦈ then elem 8 (&Q (pure′ dest) (!# 2)) (!# 0) ≔ ↓! elem 8 (var (# 1)) (!# 0) else skip) ∙ ⦇ _ ⦈ module fun-sliceᶻ - (≈ᶻ-trans : Transitive _≈ᶻ_) - (round∘float : ∀ x → x ≈ᶻ round (float x)) - (round-cong : ∀ {x y} → x ≈ʳ y → round x ≈ᶻ round y) - (0#-homo-round : round 0ℝ ≈ᶻ 0ℤ) - (2^n≢0 : ∀ n → False (2ℤ ^ᶻ n ≟ᶻ 0ℤ)) - (*ᶻ-identityʳ : ∀ x → x *ᶻ 1ℤ ≈ᶻ x) + (1<>3≡4) m)) (↓ !# 5) (↓ !# 0) ⦈ then - &FPSCR-QC ≔ ⦇ 1b ⦈ + &FPSCR-QC ≔ ⦇ 1𝔹 ⦈ else skip else skip) ∙ invoke (copyMasked dest) ⦇ ↓ !# 2 , ⦇ ↓ !# 3 , ↓ !# 4 ⦈ ⦈ ∙ @@ -314,6 +303,8 @@ module _ ⟦ Instr.vmulh x ⟧₁ = execBeats (vmulh x) ⟦ Instr.vqdmulh x ⟧₁ = execBeats (vqdmulh x) + open List using (List; []; _∷_) + ⟦_⟧ : List (Instr.Instruction) → Procedure 0 _ ⟦ [] ⟧ = ⦇ _ ⦈ ⟦ i ∷ is ⟧ = invoke ⟦ i ⟧₁ ⦇ _ ⦈ ∙ ⟦ is ⟧ -- cgit v1.2.3