blob: 77cb7ff738de83fe2a81ce5026fbe9c5ca800e41 [file] [log] [blame]
""" vec_test_helpers
This module is for reusable helper functions used by the templates.
"""
def is_widening(op_code):
"""Check if a particular op_code is a widening type."""
return op_code[1] == 'w'
def is_unsigned(op_code):
"""Check if a particular op_code is a unsigned type."""
return op_code[-1] == 'u'
def get_sews(op_code):
"""Given an op_code return a list of valid element widths."""
return [8, 16] if is_widening(op_code) else [8, 16, 32]
def get_lmuls(op_code):
"""Given an op_code return an iterable if valid lmuls."""
return [1, 2, 4] if is_widening(op_code) else [1, 2, 4, 8]
def get_dest_type(op_code, sew):
"""Return a destination type for a op_code and element width."""
type_fmt = "%sint%d_t"
sign_type = "u" if is_unsigned(op_code) else ""
dest_sew = sew * 2 if is_widening(op_code) else sew
return type_fmt % (sign_type, dest_sew)
def get_src_type(op_code, sew):
"""Return a source type for an op_code and element width."""
type_fmt = "%sint%d_t"
sign_type = "u" if is_unsigned(op_code) else ""
return type_fmt % (sign_type, sew)
def get_ref_opcode(op_code):
"""Return the name of the reference code in the softrvv library."""
return op_code[:-1] if is_unsigned(op_code) else op_code