removes carry_t, moves functionality to own functions

This commit is contained in:
2025-03-09 15:07:53 +01:00
parent 0fe9e6ebc8
commit 453407568c
3 changed files with 89 additions and 48 deletions

View File

@@ -68,7 +68,6 @@ struct vmask_view {
size_t elem_count;
mask_bit_reference operator[](size_t) const;
};
enum class carry_t { NO_CARRY = 0, ADD_CARRY = 1, SUB_CARRY = 2 };
vmask_view read_vmask(uint8_t* V, uint16_t VLEN, uint16_t elem_count, uint8_t reg_idx = 0);
template <unsigned VLEN> vmask_view read_vmask(uint8_t* V, uint16_t elem_count, uint8_t reg_idx = 0);
@@ -84,10 +83,16 @@ uint64_t vector_load_store_index(void* core, std::function<bool(void*, uint64_t,
uint8_t segment_size);
template <unsigned VLEN, typename dest_elem_t, typename src2_elem_t = dest_elem_t, typename src1_elem_t = src2_elem_t>
void vector_vector_op(uint8_t* V, unsigned funct6, unsigned funct3, uint64_t vl, uint64_t vstart, vtype_t vtype, bool vm, unsigned vd,
unsigned vs2, unsigned vs1, carry_t carry = carry_t::NO_CARRY);
unsigned vs2, unsigned vs1);
template <unsigned VLEN, typename dest_elem_t, typename src2_elem_t = dest_elem_t, typename src1_elem_t = src2_elem_t>
void vector_imm_op(uint8_t* V, unsigned funct6, unsigned funct3, uint64_t vl, uint64_t vstart, vtype_t vtype, bool vm, unsigned vd,
unsigned vs2, typename std::make_signed<src1_elem_t>::type imm, carry_t carry = carry_t::NO_CARRY);
unsigned vs2, typename std::make_signed<src1_elem_t>::type imm);
template <unsigned VLEN, typename elem_t>
void vector_vector_carry(uint8_t* V, unsigned funct6, unsigned funct3, uint64_t vl, uint64_t vstart, vtype_t vtype, unsigned vd,
unsigned vs2, unsigned vs1, signed carry);
template <unsigned VLEN, typename elem_t>
void vector_imm_carry(uint8_t* V, unsigned funct6, unsigned funct3, uint64_t vl, uint64_t vstart, vtype_t vtype, unsigned vd, unsigned vs2,
typename std::make_signed<elem_t>::type imm, signed carry);
template <unsigned VLEN, typename scr_elem_t>
void vector_vector_merge(uint8_t* V, uint64_t vl, uint64_t vstart, vtype_t vtype, bool vm, unsigned vd, unsigned vs2, unsigned vs1);
template <unsigned VLEN, typename scr_elem_t>

View File

@@ -336,54 +336,69 @@ std::function<dest_elem_t(dest_elem_t, src2_elem_t, src1_elem_t)> get_funct(unsi
}
template <unsigned VLEN, typename dest_elem_t, typename src2_elem_t, typename src1_elem_t>
void vector_vector_op(uint8_t* V, unsigned funct6, unsigned funct3, uint64_t vl, uint64_t vstart, vtype_t vtype, bool vm, unsigned vd,
unsigned vs2, unsigned vs1, carry_t carry) {
unsigned vs2, unsigned vs1) {
uint64_t vlmax = VLEN * vtype.lmul() / vtype.sew();
vmask_view mask_reg = read_vmask<VLEN>(V, vlmax);
auto vs1_view = get_vreg<VLEN, src1_elem_t>(V, vs1, vlmax);
auto vs2_view = get_vreg<VLEN, src2_elem_t>(V, vs2, vlmax);
auto vd_view = get_vreg<VLEN, dest_elem_t>(V, vd, vlmax);
auto fn = get_funct<dest_elem_t, src2_elem_t, src1_elem_t>(funct6, funct3);
if(carry == carry_t::NO_CARRY)
for(size_t idx = vstart; idx < vl; idx++) {
bool mask_active = vm ? 1 : mask_reg[idx];
if(mask_active)
vd_view[idx] = fn(vd_view[idx], vs2_view[idx], vs1_view[idx]);
else if(vtype.vma())
vd_view[idx] = agnostic_behavior(vd_view[idx]);
}
else if(carry == carry_t::SUB_CARRY)
for(size_t idx = vstart; idx < vl; idx++)
vd_view[idx] = fn(vd_view[idx], vs2_view[idx], vs1_view[idx]) - mask_reg[idx];
else
for(size_t idx = vstart; idx < vl; idx++)
vd_view[idx] = fn(vd_view[idx], vs2_view[idx], vs1_view[idx]) + mask_reg[idx];
for(size_t idx = vstart; idx < vl; idx++) {
bool mask_active = vm ? 1 : mask_reg[idx];
if(mask_active)
vd_view[idx] = fn(vd_view[idx], vs2_view[idx], vs1_view[idx]);
else if(vtype.vma())
vd_view[idx] = agnostic_behavior(vd_view[idx]);
}
if(vtype.vta())
for(size_t idx = vl; idx < vlmax; idx++)
vd_view[idx] = agnostic_behavior(vd_view[idx]);
}
template <unsigned VLEN, typename dest_elem_t, typename src2_elem_t, typename src1_elem_t>
void vector_imm_op(uint8_t* V, unsigned funct6, unsigned funct3, uint64_t vl, uint64_t vstart, vtype_t vtype, bool vm, unsigned vd,
unsigned vs2, typename std::make_signed<src1_elem_t>::type imm, carry_t carry) {
unsigned vs2, typename std::make_signed<src1_elem_t>::type imm) {
uint64_t vlmax = VLEN * vtype.lmul() / vtype.sew();
vmask_view mask_reg = read_vmask<VLEN>(V, vlmax);
auto vs2_view = get_vreg<VLEN, src2_elem_t>(V, vs2, vlmax);
auto vd_view = get_vreg<VLEN, dest_elem_t>(V, vd, vlmax);
auto fn = get_funct<dest_elem_t, src2_elem_t, src1_elem_t>(funct6, funct3);
if(carry == carry_t::NO_CARRY)
for(size_t idx = vstart; idx < vl; idx++) {
bool mask_active = vm ? 1 : mask_reg[idx];
if(mask_active) {
vd_view[idx] = fn(vd_view[idx], vs2_view[idx], imm);
} else {
vd_view[idx] = vtype.vma() ? vd_view[idx] : vd_view[idx];
}
for(size_t idx = vstart; idx < vl; idx++) {
bool mask_active = vm ? 1 : mask_reg[idx];
if(mask_active) {
vd_view[idx] = fn(vd_view[idx], vs2_view[idx], imm);
} else {
vd_view[idx] = vtype.vma() ? vd_view[idx] : vd_view[idx];
}
else if(carry == carry_t::SUB_CARRY)
for(size_t idx = vstart; idx < vl; idx++)
vd_view[idx] = fn(vd_view[idx], vs2_view[idx], imm) - mask_reg[idx];
else
for(size_t idx = vstart; idx < vl; idx++)
vd_view[idx] = fn(vd_view[idx], vs2_view[idx], imm) + mask_reg[idx];
}
if(vtype.vta())
for(size_t idx = vl; idx < vlmax; idx++)
vd_view[idx] = agnostic_behavior(vd_view[idx]);
}
template <unsigned VLEN, typename elem_t>
void vector_vector_carry(uint8_t* V, unsigned funct6, unsigned funct3, uint64_t vl, uint64_t vstart, vtype_t vtype, unsigned vd,
unsigned vs2, unsigned vs1, signed carry) {
uint64_t vlmax = VLEN * vtype.lmul() / vtype.sew();
vmask_view mask_reg = read_vmask<VLEN>(V, vlmax);
auto vs1_view = get_vreg<VLEN, elem_t>(V, vs1, vlmax);
auto vs2_view = get_vreg<VLEN, elem_t>(V, vs2, vlmax);
auto vd_view = get_vreg<VLEN, elem_t>(V, vd, vlmax);
auto fn = get_funct<elem_t, elem_t, elem_t>(funct6, funct3);
for(size_t idx = vstart; idx < vl; idx++)
vd_view[idx] = fn(vd_view[idx], vs2_view[idx], vs1_view[idx]) + carry * mask_reg[idx];
if(vtype.vta())
for(size_t idx = vl; idx < vlmax; idx++)
vd_view[idx] = agnostic_behavior(vd_view[idx]);
}
template <unsigned VLEN, typename elem_t>
void vector_imm_carry(uint8_t* V, unsigned funct6, unsigned funct3, uint64_t vl, uint64_t vstart, vtype_t vtype, unsigned vd, unsigned vs2,
typename std::make_signed<elem_t>::type imm, signed carry) {
uint64_t vlmax = VLEN * vtype.lmul() / vtype.sew();
vmask_view mask_reg = read_vmask<VLEN>(V, vlmax);
auto vs2_view = get_vreg<VLEN, elem_t>(V, vs2, vlmax);
auto vd_view = get_vreg<VLEN, elem_t>(V, vd, vlmax);
auto fn = get_funct<elem_t, elem_t, elem_t>(funct6, funct3);
for(size_t idx = vstart; idx < vl; idx++)
vd_view[idx] = fn(vd_view[idx], vs2_view[idx], imm) + carry * mask_reg[idx];
if(vtype.vta())
for(size_t idx = vl; idx < vlmax; idx++)
vd_view[idx] = agnostic_behavior(vd_view[idx]);