| """ vec_test_helpers |
| |
| This module is for reusable helper functions used by the templates. |
| """ |
| import numpy as np |
| |
| 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 |
| |
| def get_imms(op_code): |
| """Return a list of valid immediate values for a op code.""" |
| if op_code in ['vsll', 'vsrl']: |
| # Left and right shift immediates must be [0,31] |
| return np.linspace(0, 31, 8, dtype=np.int32) |
| else: |
| # Immediate values must be [-16, 15] |
| return np.linspace(-16, 15, 7, dtype=np.int32) |
| |