Skip to content

Commit

Permalink
[gen]: Generate basic SVE loads and stores
Browse files Browse the repository at this point in the history
SVE pseudo-relaxation are grouped under `Sv` suffix:

 - `SvV` command a SVE gather load and scatter store
 - `Sv{1,2,3,4}` command a SVE interleave loads and stores'

Generated tests set predicates in such way that single access won't
exceed 128 bit (which is minimal allowed vector length) which allow
them tolerate difference in implemented vector length when run on the
target. Also it aligns with herd's implementation choice of 128 bit
vector length.

Please note that predicate register require another allocator which
implemented via newly introduced `special2` allocator

Signed-off-by: Vladimir Murzin <[email protected]>
  • Loading branch information
Vladimir Murzin committed May 1, 2024
1 parent b1dbf49 commit 4128e86
Show file tree
Hide file tree
Showing 9 changed files with 288 additions and 16 deletions.
46 changes: 33 additions & 13 deletions gen/AArch64Arch_gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ let do_morello = C.variant Variant_gen.Morello
let do_fullkvm = C.variant Variant_gen.FullKVM
let do_kvm = do_fullkvm || C.variant Variant_gen.KVM
let do_neon = C.variant Variant_gen.Neon
let do_sve = C.variant Variant_gen.SVE
let do_mixed = Variant_gen.is_mixed C.variant
let do_cu = C.variant Variant_gen.ConstrainedUnpredictable

Expand All @@ -60,7 +61,7 @@ module Mixed =
let bellatom = false
module SIMD = struct

type atom = NeP|NeAcqPc|NeRel|Ne1|Ne2|Ne3|Ne4|Ne2i|Ne3i|Ne4i|NePa|NePaN
type atom = SvV|Sv1|Sv2i|Sv3i|Sv4i|NeP|NeAcqPc|NeRel|Ne1|Ne2|Ne3|Ne4|Ne2i|Ne3i|Ne4i|NePa|NePaN

let fold_neon f r = r |>
f NeAcqPc |> f NeRel |>
Expand All @@ -69,26 +70,35 @@ module SIMD = struct
f Ne1 |> f Ne2 |> f Ne3 |> f Ne4 |>
f Ne2i |> f Ne3i |> f Ne4i

let fold_sve f r = r |>
f SvV |> f Sv1 |>
f Sv2i |> f Sv3i |> f Sv4i

let nregs = function
| Ne1 -> 1
| Ne2 | Ne2i -> 2
| Ne3 | Ne3i -> 3
| Ne4 | Ne4i -> 4
| SvV | Sv1 | Ne1 -> 1
| Sv2i | Ne2 | Ne2i -> 2
| Sv3i | Ne3 | Ne3i -> 3
| Sv4i | Ne4 | Ne4i -> 4
| _ -> 1

let nelements = function
| SvV|Sv1|Sv2i|Sv3i|Sv4i
| Ne1|Ne2|Ne2i|Ne3|Ne3i|Ne4|Ne4i -> 4
| NePa|NePaN -> 2
| NeP | NeAcqPc | NeRel -> 1

let pp_opt = function
| Sv2i | Sv3i | Sv4i
| Ne2i | Ne3i | Ne4i -> "i"
| _ -> ""

let pp n =
match n with
| Ne1 | Ne2 | Ne3 | Ne4 | Ne2i | Ne3i | Ne4i ->
Printf.sprintf "Ne%i%s" (nregs n) (pp_opt n)
| Sv1 | Sv2i | Sv3i | Sv4i ->
Printf.sprintf "Sv%i%s" (nregs n) (pp_opt n)
| SvV -> "SvV"
| NePa -> "NePa"
| NePaN -> "NePaN"
| NeP -> "NeP"
Expand All @@ -107,9 +117,10 @@ module SIMD = struct
for k = 0 to sz-1 do
for i=0 to el-1 do
let j = match n with
| Ne2i | Ne3i | Ne4i -> k+i*sz
| Sv2i | Sv3i | Sv4i | Ne2i | Ne3i | Ne4i -> k+i*sz
| NeP | NeAcqPc | NeRel | NePa | NePaN
| Ne1 | Ne2 | Ne3 | Ne4 -> i+k*el
| Ne1 | Ne2 | Ne3 | Ne4
| SvV | Sv1 -> i+k*el
in
v.(j) <- start+k
done
Expand All @@ -120,9 +131,10 @@ module SIMD = struct
let el = nelements n in
let sz = nregs n in
let access r k = match n with
| Ne2i | Ne3i | Ne4i -> sz*k + r
| Sv2i | Sv3i | Sv4i | Ne2i | Ne3i | Ne4i -> sz*k + r
| NeP | NeAcqPc | NeRel | NePa | NePaN
| Ne1 | Ne2 | Ne3 | Ne4 -> el*r + k
| Ne1 | Ne2 | Ne3 | Ne4
| SvV | Sv1 -> el*r + k
in
let rec reg r k =
if k >= el then []
Expand Down Expand Up @@ -335,6 +347,12 @@ let is_ifetch a = match a with
else
fun _ r -> r

let fold_sve =
if do_sve then
fun f -> SIMD.fold_sve (fun n -> f (Neon n))
else
fun _ r -> r

let fold_pair f r =
if do_mixed then r
else
Expand All @@ -357,6 +375,7 @@ let is_ifetch a = match a with
let r = fold_morello f r in
let r = fold_tag f r in
let r = fold_neon f r in
let r = fold_sve f r in
let r = fold_pair f r in
let r = fold_acc_opt None f r in
let r =
Expand Down Expand Up @@ -456,10 +475,10 @@ let is_ifetch a = match a with
function
| NeP | NeAcqPc | NeRel -> 1
| NePa | NePaN -> 2
| Ne1 -> 4
| Ne2 | Ne2i -> 8
| Ne3 | Ne3i -> 12
| Ne4 | Ne4i -> 16
| SvV | Sv1 | Ne1 -> 4
| Sv2i | Ne2 | Ne2i -> 8
| Sv3i | Ne3 | Ne3i -> 12
| Sv4i | Ne4 | Ne4i -> 16

let atom_to_bank = function
| Tag,None -> Code.Tag
Expand Down Expand Up @@ -866,6 +885,7 @@ include

type special = reg
let specials = vregs
let specials2 = pregs
end)

end
Loading

0 comments on commit 4128e86

Please sign in to comment.