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

Remove vector of bools in vext #622

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions model/prelude.sail
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ function bits_to_bool(x : bits(1)) -> bool = bool_bits(x)
val to_bits : forall 'l, 'l >= 0.(int('l), int) -> bits('l)
function to_bits (l, n) = get_slice_int(l, n, 0)

val flip_bits : forall 'n, 'n >= 0. (int('n), bits('n)) -> bits('n)
function flip_bits (num : int('n), x : bits('n)) -> bits('n) = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems like you are always flipping all bits? Can't you just xor with ones()?

If this function is needed with a partial flip, you can simplify that to an xor with ones(n) @ zeros()

var result : bits('n) = zeros();
foreach (i from 0 to (num - 1))
if x[i] == bitone then
result[i] = bitzero
else
result[i] = bitone;
result
}

infix 4 <_s
infix 4 >_s
infix 4 <=_s
Expand Down
232 changes: 149 additions & 83 deletions model/riscv_insts_vext_arith.sail

Large diffs are not rendered by default.

118 changes: 76 additions & 42 deletions model/riscv_insts_vext_fp.sail
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ function clause execute(FVVTYPE(funct6, vm, vs2, vs1, vd)) = {
let 'n = num_elem;
let 'm = SEW;

let vm_val : vector('n, bool) = read_vmask(num_elem, vm, 0b00000);
assert('n > 0);

let vm_val : bits('n) = read_vmask(num_elem, vm, 0b00000);
let vs1_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vs1);
let vs2_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vs2);
let vd_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vd);
Expand All @@ -51,7 +53,7 @@ function clause execute(FVVTYPE(funct6, vm, vs2, vs1, vd)) = {
var result = initial_result;

foreach (i from 0 to (num_elem - 1)) {
if mask[i] then {
if mask[i] == bitone then {
result[i] = match funct6 {
FVV_VADD => fp_add(rm_3b, vs2_val[i], vs1_val[i]),
FVV_VSUB => fp_sub(rm_3b, vs2_val[i], vs1_val[i]),
Expand Down Expand Up @@ -116,7 +118,9 @@ function clause execute(FVVMATYPE(funct6, vm, vs2, vs1, vd)) = {
let 'n = num_elem;
let 'm = SEW;

let vm_val : vector('n, bool) = read_vmask(num_elem, vm, 0b00000);
assert('n > 0);

let vm_val : bits('n) = read_vmask(num_elem, vm, 0b00000);
let vs1_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vs1);
let vs2_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vs2);
let vd_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vd);
Expand All @@ -125,7 +129,7 @@ function clause execute(FVVMATYPE(funct6, vm, vs2, vs1, vd)) = {
var result = initial_result;

foreach (i from 0 to (num_elem - 1)) {
if mask[i] then {
if mask[i] == bitone then {
result[i] = match funct6 {
FVV_VMACC => fp_muladd(rm_3b, vs1_val[i], vs2_val[i], vd_val[i]),
FVV_VNMACC => fp_nmulsub(rm_3b, vs1_val[i], vs2_val[i], vd_val[i]),
Expand Down Expand Up @@ -188,7 +192,9 @@ function clause execute(FWVVTYPE(funct6, vm, vs2, vs1, vd)) = {
let 'm = SEW;
let 'o = SEW_widen;

let vm_val : vector('n, bool) = read_vmask(num_elem, vm, 0b00000);
assert('n > 0);

let vm_val : bits('n) = read_vmask(num_elem, vm, 0b00000);
let vd_val : vector('n, bits('o)) = read_vreg(num_elem, SEW_widen, LMUL_pow_widen, vd);
let vs1_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vs1);
let vs2_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vs2);
Expand All @@ -197,7 +203,7 @@ function clause execute(FWVVTYPE(funct6, vm, vs2, vs1, vd)) = {
var result = initial_result;

foreach (i from 0 to (num_elem - 1)) {
if mask[i] then {
if mask[i] == bitone then {
result[i] = match funct6 {
FWVV_VADD => fp_add(rm_3b, fp_widen(vs2_val[i]), fp_widen(vs1_val[i])),
FWVV_VSUB => fp_sub(rm_3b, fp_widen(vs2_val[i]), fp_widen(vs1_val[i])),
Expand Down Expand Up @@ -252,7 +258,9 @@ function clause execute(FWVVMATYPE(funct6, vm, vs1, vs2, vd)) = {
let 'm = SEW;
let 'o = SEW_widen;

let vm_val : vector('n, bool) = read_vmask(num_elem, vm, 0b00000);
assert('n > 0);

let vm_val : bits('n) = read_vmask(num_elem, vm, 0b00000);
let vd_val : vector('n, bits('o)) = read_vreg(num_elem, SEW_widen, LMUL_pow_widen, vd);
let vs1_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vs1);
let vs2_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vs2);
Expand All @@ -261,7 +269,7 @@ function clause execute(FWVVMATYPE(funct6, vm, vs1, vs2, vd)) = {
var result = initial_result;

foreach (i from 0 to (num_elem - 1)) {
if mask[i] then {
if mask[i] == bitone then {
result[i] = match funct6 {
FWVV_VMACC => fp_muladd(rm_3b, fp_widen(vs1_val[i]), fp_widen(vs2_val[i]), vd_val[i]),
FWVV_VNMACC => fp_nmulsub(rm_3b, fp_widen(vs1_val[i]), fp_widen(vs2_val[i]), vd_val[i]),
Expand Down Expand Up @@ -314,7 +322,9 @@ function clause execute(FWVTYPE(funct6, vm, vs2, vs1, vd)) = {
let 'm = SEW;
let 'o = SEW_widen;

let vm_val : vector('n, bool) = read_vmask(num_elem, vm, 0b00000);
assert('n > 0);

let vm_val : bits('n) = read_vmask(num_elem, vm, 0b00000);
let vd_val : vector('n, bits('o)) = read_vreg(num_elem, SEW_widen, LMUL_pow_widen, vd);
let vs1_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vs1);
let vs2_val : vector('n, bits('o)) = read_vreg(num_elem, SEW_widen, LMUL_pow_widen, vs2);
Expand All @@ -323,7 +333,7 @@ function clause execute(FWVTYPE(funct6, vm, vs2, vs1, vd)) = {
var result = initial_result;

foreach (i from 0 to (num_elem - 1)) {
if mask[i] then {
if mask[i] == bitone then {
result[i] = match funct6 {
FWV_VADD => fp_add(rm_3b, vs2_val[i], fp_widen(vs1_val[i])),
FWV_VSUB => fp_sub(rm_3b, vs2_val[i], fp_widen(vs1_val[i]))
Expand Down Expand Up @@ -371,15 +381,17 @@ function clause execute(VFUNARY0(vm, vs2, vfunary0, vd)) = {
let 'n = num_elem;
let 'm = SEW;

let vm_val : vector('n, bool) = read_vmask(num_elem, vm, 0b00000);
assert('n > 0);

let vm_val : bits('n) = read_vmask(num_elem, vm, 0b00000);
let vs2_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vs2);
let vd_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vd);

let (initial_result, mask) = init_masked_result(num_elem, SEW, LMUL_pow, vd_val, vm_val);
var result = initial_result;

foreach (i from 0 to (num_elem - 1)) {
if mask[i] then {
if mask[i] == bitone then {
result[i] = match vfunary0 {
FV_CVT_XU_F => {
let (fflags, elem) : (bits_fflags, bits('m)) = match 'm {
Expand Down Expand Up @@ -489,15 +501,17 @@ function clause execute(VFWUNARY0(vm, vs2, vfwunary0, vd)) = {
let 'm = SEW;
let 'o = SEW_widen;

let vm_val : vector('n, bool) = read_vmask(num_elem, vm, 0b00000);
assert('n > 0);

let vm_val : bits('n) = read_vmask(num_elem, vm, 0b00000);
let vs2_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vs2);
let vd_val : vector('n, bits('o)) = read_vreg(num_elem, SEW_widen, LMUL_pow_widen, vd);

let (initial_result, mask) = init_masked_result(num_elem, SEW_widen, LMUL_pow_widen, vd_val, vm_val);
var result = initial_result;

foreach (i from 0 to (num_elem - 1)) {
if mask[i] then {
if mask[i] == bitone then {
result[i] = match vfwunary0 {
FWV_CVT_XU_F => {
let (fflags, elem) : (bits_fflags, bits('o)) = match 'm {
Expand Down Expand Up @@ -618,15 +632,17 @@ function clause execute(VFNUNARY0(vm, vs2, vfnunary0, vd)) = {
let 'm = SEW;
let 'o = SEW_widen;

let vm_val : vector('n, bool) = read_vmask(num_elem, vm, 0b00000);
assert('n > 0);

let vm_val : bits('n) = read_vmask(num_elem, vm, 0b00000);
let vs2_val : vector('n, bits('o)) = read_vreg(num_elem, SEW_widen, LMUL_pow_widen, vs2);
let vd_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vd);

let (initial_result, mask) = init_masked_result(num_elem, SEW, LMUL_pow, vd_val, vm_val);
var result = initial_result;

foreach (i from 0 to (num_elem - 1)) {
if mask[i] then {
if mask[i] == bitone then {
result[i] = match vfnunary0 {
FNV_CVT_XU_F => {
let (fflags, elem) : (bits_fflags, bits('m)) = match 'm {
Expand Down Expand Up @@ -748,15 +764,17 @@ function clause execute(VFUNARY1(vm, vs2, vfunary1, vd)) = {
let 'n = num_elem;
let 'm = SEW;

let vm_val : vector('n, bool) = read_vmask(num_elem, vm, 0b00000);
assert('n > 0);

let vm_val : bits('n) = read_vmask(num_elem, vm, 0b00000);
let vs2_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vs2);
let vd_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vd);

let (initial_result, mask) = init_masked_result(num_elem, SEW, LMUL_pow, vd_val, vm_val);
var result = initial_result;

foreach (i from 0 to (num_elem - 1)) {
if mask[i] then {
if mask[i] == bitone then {
result[i] = match vfunary1 {
FVV_VSQRT => {
let (fflags, elem) : (bits_fflags, bits('m)) = match 'm {
Expand Down Expand Up @@ -871,16 +889,18 @@ function clause execute(FVFTYPE(funct6, vm, vs2, rs1, vd)) = {
let 'n = num_elem;
let 'm = SEW;

let vm_val : vector('n, bool) = read_vmask(num_elem, vm, 0b00000);
let rs1_val : bits('m) = get_scalar_fp(rs1, 'm);
assert('n > 0);

let vm_val : bits('n) = read_vmask(num_elem, vm, 0b00000);
let rs1_val : bits('m) = get_scalar_fp(rs1, 'm);
let vs2_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vs2);
let vd_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vd);

let (initial_result, mask) = init_masked_result(num_elem, SEW, LMUL_pow, vd_val, vm_val);
var result = initial_result;

foreach (i from 0 to (num_elem - 1)) {
if mask[i] then {
if mask[i] == bitone then {
result[i] = match funct6 {
VF_VADD => fp_add(rm_3b, vs2_val[i], rs1_val),
VF_VSUB => fp_sub(rm_3b, vs2_val[i], rs1_val),
Expand Down Expand Up @@ -960,16 +980,18 @@ function clause execute(FVFMATYPE(funct6, vm, vs2, rs1, vd)) = {
let 'n = num_elem;
let 'm = SEW;

let vm_val : vector('n, bool) = read_vmask(num_elem, vm, 0b00000);
let rs1_val : bits('m) = get_scalar_fp(rs1, 'm);
assert('n > 0);

let vm_val : bits('n) = read_vmask(num_elem, vm, 0b00000);
let rs1_val : bits('m) = get_scalar_fp(rs1, 'm);
let vs2_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vs2);
let vd_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vd);

let (initial_result, mask) = init_masked_result(num_elem, SEW, LMUL_pow, vd_val, vm_val);
var result = initial_result;

foreach (i from 0 to (num_elem - 1)) {
if mask[i] then {
if mask[i] == bitone then {
result[i] = match funct6 {
VF_VMACC => fp_muladd(rm_3b, rs1_val, vs2_val[i], vd_val[i]),
VF_VNMACC => fp_nmulsub(rm_3b, rs1_val, vs2_val[i], vd_val[i]),
Expand Down Expand Up @@ -1031,16 +1053,18 @@ function clause execute(FWVFTYPE(funct6, vm, vs2, rs1, vd)) = {
let 'm = SEW;
let 'o = SEW_widen;

let vm_val : vector('n, bool) = read_vmask(num_elem, vm, 0b00000);
assert('n > 0);

let vm_val : bits('n) = read_vmask(num_elem, vm, 0b00000);
let vd_val : vector('n, bits('o)) = read_vreg(num_elem, SEW_widen, LMUL_pow_widen, vd);
let rs1_val : bits('m) = get_scalar_fp(rs1, 'm);
let rs1_val : bits('m) = get_scalar_fp(rs1, 'm);
let vs2_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vs2);

let (initial_result, mask) = init_masked_result(num_elem, SEW_widen, LMUL_pow_widen, vd_val, vm_val);
var result = initial_result;

foreach (i from 0 to (num_elem - 1)) {
if mask[i] then {
if mask[i] == bitone then {
result[i] = match funct6 {
FWVF_VADD => fp_add(rm_3b, fp_widen(vs2_val[i]), fp_widen(rs1_val)),
FWVF_VSUB => fp_sub(rm_3b, fp_widen(vs2_val[i]), fp_widen(rs1_val)),
Expand Down Expand Up @@ -1094,16 +1118,18 @@ function clause execute(FWVFMATYPE(funct6, vm, rs1, vs2, vd)) = {
let 'm = SEW;
let 'o = SEW_widen;

let vm_val : vector('n, bool) = read_vmask(num_elem, vm, 0b00000);
assert('n > 0);

let vm_val : bits('n) = read_vmask(num_elem, vm, 0b00000);
let vd_val : vector('n, bits('o)) = read_vreg(num_elem, SEW_widen, LMUL_pow_widen, vd);
let rs1_val : bits('m) = get_scalar_fp(rs1, 'm);
let rs1_val : bits('m) = get_scalar_fp(rs1, 'm);
let vs2_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vs2);

let (initial_result, mask) = init_masked_result(num_elem, SEW_widen, LMUL_pow_widen, vd_val, vm_val);
var result = initial_result;

foreach (i from 0 to (num_elem - 1)) {
if mask[i] then {
if mask[i] == bitone then {
result[i] = match funct6 {
FWVF_VMACC => fp_muladd(rm_3b, fp_widen(rs1_val), fp_widen(vs2_val[i]), vd_val[i]),
FWVF_VNMACC => fp_nmulsub(rm_3b, fp_widen(rs1_val), fp_widen(vs2_val[i]), vd_val[i]),
Expand Down Expand Up @@ -1155,16 +1181,18 @@ function clause execute(FWFTYPE(funct6, vm, vs2, rs1, vd)) = {
let 'm = SEW;
let 'o = SEW_widen;

let vm_val : vector('n, bool) = read_vmask(num_elem, vm, 0b00000);
assert('n > 0);

let vm_val : bits('n) = read_vmask(num_elem, vm, 0b00000);
let vd_val : vector('n, bits('o)) = read_vreg(num_elem, SEW_widen, LMUL_pow_widen, vd);
let rs1_val : bits('m) = get_scalar_fp(rs1, 'm);
let rs1_val : bits('m) = get_scalar_fp(rs1, 'm);
let vs2_val : vector('n, bits('o)) = read_vreg(num_elem, SEW_widen, LMUL_pow_widen, vs2);

let (initial_result, mask) = init_masked_result(num_elem, SEW_widen, LMUL_pow_widen, vd_val, vm_val);
var result = initial_result;

foreach (i from 0 to (num_elem - 1)) {
if mask[i] then {
if mask[i] == bitone then {
result[i] = match funct6 {
FWF_VADD => fp_add(rm_3b, vs2_val[i], fp_widen(rs1_val)),
FWF_VSUB => fp_sub(rm_3b, vs2_val[i], fp_widen(rs1_val))
Expand Down Expand Up @@ -1207,8 +1235,10 @@ function clause execute(VFMERGE(vs2, rs1, vd)) = {
let 'n = num_elem;
let 'm = SEW;

let vm_val : vector('n, bool) = read_vmask(num_elem, 0b0, 0b00000);
let rs1_val : bits('m) = get_scalar_fp(rs1, 'm);
assert('n > 0);

let vm_val : bits('n) = read_vmask(num_elem, 0b0, 0b00000);
let rs1_val : bits('m) = get_scalar_fp(rs1, 'm);
let vs2_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vs2);
let vd_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vd);
var result : vector('n, bits('m)) = vector_init(zeros());
Expand All @@ -1224,7 +1254,7 @@ function clause execute(VFMERGE(vs2, rs1, vd)) = {
}
} else {
/* the merge operates on all body elements */
result[i] = if vm_val[i] then rs1_val else vs2_val[i]
result[i] = if vm_val[i] == bitone then rs1_val else vs2_val[i]
}
};

Expand Down Expand Up @@ -1255,15 +1285,17 @@ function clause execute(VFMV(rs1, vd)) = {
let 'n = num_elem;
let 'm = SEW;

let rs1_val : bits('m) = get_scalar_fp(rs1, 'm);
let vm_val : vector('n, bool) = read_vmask(num_elem, 0b1, 0b00000);
assert('n > 0);

let rs1_val : bits('m) = get_scalar_fp(rs1, 'm);
let vm_val : bits('n) = read_vmask(num_elem, 0b1, 0b00000);
let vd_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, LMUL_pow, vd);

let (initial_result, mask) = init_masked_result(num_elem, SEW, LMUL_pow, vd_val, vm_val);
var result = initial_result;

foreach (i from 0 to (num_elem - 1)) {
if mask[i] then result[i] = rs1_val
if mask[i] == bitone then result[i] = rs1_val
};

write_vreg(num_elem, SEW, LMUL_pow, vd, result);
Expand Down Expand Up @@ -1291,15 +1323,17 @@ function clause execute(VFMVSF(rs1, vd)) = {
let 'n = num_elem;
let 'm = SEW;

let vm_val : vector('n, bool) = read_vmask(num_elem, 0b1, 0b00000);
let rs1_val : bits('m) = get_scalar_fp(rs1, 'm);
assert('n > 0);

let vm_val : bits('n) = read_vmask(num_elem, 0b1, 0b00000);
let rs1_val : bits('m) = get_scalar_fp(rs1, 'm);
let vd_val : vector('n, bits('m)) = read_vreg(num_elem, SEW, 0, vd);

let (initial_result, mask) = init_masked_result(num_elem, SEW, 0, vd_val, vm_val);
var result = initial_result;

/* one body element */
if mask[0] then result[0] = rs1_val;
if mask[0] == bitone then result[0] = rs1_val;

/* others treated as tail elements */
let tail_ag : agtype = get_vtype_vta();
Expand Down
Loading
Loading