-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for TBL/TBX from Advanced SIMD table lookup class (#23)
### Description: This PR adds support for [TBL/TBX (single, two, three, four register table)](https://developer.arm.com/documentation/ddi0602/2023-12/SIMD-FP-Instructions/TBL--Table-vector-Lookup-?lang=en#TBL_asimdtbl_L1_1) from the Advanced SIMD table lookup class. ### Testing: The `make all` succeeds and conformance testing runs successfully on Graviton2 and Graviton3. ### License: By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
- Loading branch information
Showing
6 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/- | ||
Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Author(s): Yan Peng | ||
-/ | ||
-- TBL and TBX (Single, Two, Three, Four register table) | ||
|
||
import Arm.Decode | ||
import Arm.Insts.Common | ||
|
||
---------------------------------------------------------------------- | ||
|
||
namespace DPSFP | ||
|
||
open Std.BitVec | ||
|
||
@[simp] | ||
def create_table (i : Nat) (regs : Nat) (Rn : BitVec 5) (table : BitVec (128 * regs)) | ||
(s : ArmState) : BitVec (128 * regs) := | ||
if h₀ : regs <= i then | ||
table | ||
else | ||
let val := read_sfp 128 Rn s | ||
have h₁ : 128 = 128 * i + 127 - 128 * i + 1 := by omega | ||
let table := BitVec.partInstall (128 * i + 127) (128 * i) (h₁ ▸ val) table | ||
let Rn := (Rn + 1) % 32 | ||
have h₂ : regs - (i + 1) < regs - i := by omega | ||
create_table (i + 1) regs Rn table s | ||
termination_by create_table i regs Rn table s => (regs - i) | ||
|
||
@[simp] | ||
def tblx_aux (i : Nat) (elements : Nat) (indices : BitVec datasize) | ||
(regs : Nat) (table : BitVec (128 * regs)) (result: BitVec datasize) | ||
: BitVec datasize := | ||
if h₀ : elements <= i then | ||
result | ||
else | ||
have h₁ : 8 > 0 := by decide | ||
let index := (elem_get indices i 8 h₁).toNat | ||
let result := | ||
if index < 16 * regs then | ||
let val := elem_get table index 8 h₁ | ||
elem_set result i 8 val h₁ | ||
else | ||
result | ||
have h₂ : elements - (i + 1) < elements - i := by omega | ||
tblx_aux (i + 1) elements indices regs table result | ||
termination_by tblx_aux i elements indices regs table result => (elements - i) | ||
|
||
@[simp] | ||
def exec_tblx (inst : Advanced_simd_table_lookup_cls) (s : ArmState) : ArmState := | ||
let datasize := 64 <<< inst.Q.toNat | ||
let elements := datasize / 8 | ||
let regs := inst.len.toNat + 1 | ||
let is_tbl := (inst.op == 0b0#1) | ||
let indices := read_sfp datasize inst.Rm s | ||
let table := Std.BitVec.zero (128 * regs) | ||
let table := create_table 0 regs inst.Rn table s | ||
let result := if is_tbl | ||
then Std.BitVec.zero datasize | ||
else read_sfp datasize inst.Rd s | ||
let result := tblx_aux 0 elements indices regs table result | ||
-- State Updates | ||
let s := write_sfp datasize inst.Rd result s | ||
let s := write_pc ((read_pc s) + 4#64) s | ||
s | ||
|
||
@[simp] | ||
def exec_advanced_simd_table_lookup | ||
(inst : Advanced_simd_table_lookup_cls) (s : ArmState) : ArmState := | ||
if inst.op2 == 0b00#2 then | ||
exec_tblx inst s | ||
else write_err (StateError.Unimplemented s!"Unsupported {inst} encountered!") s | ||
|
||
---------------------------------------------------------------------- | ||
|
||
def Advanced_simd_table_lookup_cls.tbl.rand : IO (Option (BitVec 32)) := do | ||
let (inst : Advanced_simd_table_lookup_cls) := | ||
{ Q := ← BitVec.rand 1, | ||
op2 := 0b00#2, | ||
Rm := ← BitVec.rand 5, | ||
len := ← BitVec.rand 2, | ||
op := ← BitVec.rand 1, | ||
Rn := ← BitVec.rand 5, | ||
Rd := ← BitVec.rand 5 | ||
} | ||
pure (some (inst.toBitVec32)) | ||
|
||
/-- Generate random instructions of Advanced_simd_table_lookup class. -/ | ||
def Advanced_simd_table_lookup_cls.rand : List (IO (Option (BitVec 32))) := | ||
[ Advanced_simd_table_lookup_cls.tbl.rand ] | ||
|
||
end DPSFP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters