97 lines
		
	
	
		
			5.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			97 lines
		
	
	
		
			5.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
////////////////////////////////////////////////////////////////////////////////
 | 
						|
// Copyright (C) 2025, MINRES Technologies GmbH
 | 
						|
// All rights reserved.
 | 
						|
//
 | 
						|
// Redistribution and use in source and binary forms, with or without
 | 
						|
// modification, are permitted provided that the following conditions are met:
 | 
						|
//
 | 
						|
// 1. Redistributions of source code must retain the above copyright notice,
 | 
						|
//    this list of conditions and the following disclaimer.
 | 
						|
//
 | 
						|
// 2. Redistributions in binary form must reproduce the above copyright notice,
 | 
						|
//    this list of conditions and the following disclaimer in the documentation
 | 
						|
//    and/or other materials provided with the distribution.
 | 
						|
//
 | 
						|
// 3. Neither the name of the copyright holder nor the names of its contributors
 | 
						|
//    may be used to endorse or promote products derived from this software
 | 
						|
//    without specific prior written permission.
 | 
						|
//
 | 
						|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 | 
						|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 | 
						|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 | 
						|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 | 
						|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 | 
						|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 | 
						|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 | 
						|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 | 
						|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 | 
						|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 | 
						|
// POSSIBILITY OF SUCH DAMAGE.
 | 
						|
//
 | 
						|
// Contributors:
 | 
						|
//       alex@minres.com - initial API and implementation
 | 
						|
////////////////////////////////////////////////////////////////////////////////
 | 
						|
 | 
						|
#ifndef _VM_VECTOR_FUNCTIONS_H_
 | 
						|
#define _VM_VECTOR_FUNCTIONS_H_
 | 
						|
 | 
						|
#include "iss/arch_if.h"
 | 
						|
#include "iss/vm_types.h"
 | 
						|
#include <cstdint>
 | 
						|
#include <functional>
 | 
						|
#include <stdint.h>
 | 
						|
namespace softvector {
 | 
						|
const unsigned RFS = 32;
 | 
						|
 | 
						|
struct vtype_t {
 | 
						|
    uint64_t underlying;
 | 
						|
    vtype_t(uint32_t vtype_val);
 | 
						|
    vtype_t(uint64_t vtype_val);
 | 
						|
    unsigned sew();
 | 
						|
    double lmul();
 | 
						|
    bool vill();
 | 
						|
    bool vma();
 | 
						|
    bool vta();
 | 
						|
};
 | 
						|
struct vmask_view {
 | 
						|
    uint8_t* start;
 | 
						|
    size_t elem_count;
 | 
						|
    bool 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);
 | 
						|
 | 
						|
bool softvec_read(void* core, uint64_t addr, uint64_t length, uint8_t* data);
 | 
						|
bool softvec_write(void* core, uint64_t addr, uint64_t length, uint8_t* data);
 | 
						|
uint64_t vector_load_store(void* core, std::function<bool(void*, uint64_t, uint64_t, uint8_t*)> load_store_fn, uint8_t* V, uint16_t VLEN,
 | 
						|
                           uint8_t addressed_register, uint64_t base_addr, uint64_t vl, uint64_t vstart, vtype_t vtype, bool vm,
 | 
						|
                           uint8_t elem_size_byte, uint64_t elem_count, int8_t EMUL_pow, uint8_t segment_size = 1, int64_t stride = 0,
 | 
						|
                           bool use_stride = false);
 | 
						|
uint64_t vector_load_store_index(void* core, std::function<bool(void*, uint64_t, uint64_t, uint8_t*)> load_store_fn, uint8_t* V,
 | 
						|
                                 uint16_t VLEN, uint8_t XLEN, uint8_t addressed_register, uint8_t index_register, uint64_t base_addr,
 | 
						|
                                 uint64_t vl, uint64_t vstart, vtype_t vtype, bool vm, uint8_t elem_size_byte, uint64_t elem_count,
 | 
						|
                                 uint8_t segment_size, bool ordered);
 | 
						|
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);
 | 
						|
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);
 | 
						|
template <unsigned VLEN, typename dest_elem_t, typename src2_elem_t = dest_elem_t>
 | 
						|
void vector_unary_op(uint8_t* V, unsigned unary_op, uint64_t vl, uint64_t vstart, vtype_t vtype, bool vm, unsigned vd, unsigned vs2);
 | 
						|
template <unsigned VLEN, typename elem_t>
 | 
						|
void mask_vector_vector_op(uint8_t* V, unsigned funct, unsigned funct3, uint64_t vl, uint64_t vstart, vtype_t vtype, bool vm, unsigned vd,
 | 
						|
                           unsigned vs2, unsigned vs1);
 | 
						|
template <unsigned VLEN, typename elem_t>
 | 
						|
void mask_vector_imm_op(uint8_t* V, unsigned funct, unsigned funct3, uint64_t vl, uint64_t vstart, vtype_t vtype, bool vm, unsigned vd,
 | 
						|
                        unsigned vs2, typename std::make_signed<elem_t>::type imm);
 | 
						|
void carry_vector_vector_op(uint8_t* V, unsigned funct, uint64_t vl, uint64_t vstart, vtype_t vtype, bool vm, unsigned vd, unsigned vs2,
 | 
						|
                            unsigned vs1);
 | 
						|
template <unsigned VLEN, typename elem_t>
 | 
						|
void carry_vector_imm_op(uint8_t* V, unsigned funct, uint64_t vl, uint64_t vstart, vtype_t vtype, bool vm, unsigned vd, unsigned vs2,
 | 
						|
                         typename std::make_signed<elem_t>::type imm);
 | 
						|
} // namespace softvector
 | 
						|
#include "vm/vector_functions.hpp"
 | 
						|
#endif /* _VM_VECTOR_FUNCTIONS_H_ */
 |