From 960a369869e02e230f5cb9243c5a1518b4dc9af0 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sat, 3 Nov 2018 14:00:57 +0000 Subject: [PATCH] add reshaping algorithm for elements --- riscv/processor.cc | 30 ++++++++++++++++++++++++++++++ riscv/sv.h | 9 +++++++++ riscv/sv_insn_redirect.cc | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/riscv/processor.cc b/riscv/processor.cc index eeb7c5e..f24784b 100644 --- a/riscv/processor.cc +++ b/riscv/processor.cc @@ -140,6 +140,35 @@ void state_t::reset(reg_t max_isa) mcontrol[i].type = 2; } +void sv_shape_t::setup_map() +{ + int order[3] = {}; + int lims[3] = {xsz, ysz, zsz}; + int idxs[3] = {0,0,0}; + + switch (permute) { + case SV_SHAPE_PERM_XYZ: order[0] = 0; order[1] = 1; order[2] = 2; break; + case SV_SHAPE_PERM_XZY: order[0] = 0; order[1] = 2; order[2] = 1; break; + case SV_SHAPE_PERM_YXZ: order[0] = 1; order[1] = 0; order[2] = 2; break; + case SV_SHAPE_PERM_YZX: order[0] = 1; order[1] = 2; order[2] = 0; break; + case SV_SHAPE_PERM_ZXY: order[0] = 2; order[1] = 0; order[2] = 1; break; + case SV_SHAPE_PERM_ZYX: order[0] = 2; order[1] = 1; order[2] = 0; break; + } + for (int i = 0; i < 128; i++) + { + uint8_t new_idx = idxs[0] + idxs[1] * xsz + idxs[2] * xsz * ysz; + map[i] = new_idx; + for (int j = 0; j < 3; j++) + { + idxs[order[j]] = idxs[order[j]] + 1; + if (idxs[order[j]] != lims[order[j]]) { + break; + } + idxs[order[i]] = 0; + } + } +} + int state_t::sv_csr_sz() { if (prv == PRV_M) @@ -536,6 +565,7 @@ void processor_t::set_csr(int which, reg_t val) (get_field(val, (1<<15)) ? 0x2 : 0) | (get_field(val, (1<<23)) ? 0x4 : 0); state.shape[shapeidx].permute = get_field(val, SV_SHAPE_PERM); + state.shape[shapeidx].setup_map(); break; } #endif diff --git a/riscv/sv.h b/riscv/sv.h index 60e9b8d..fc06de1 100644 --- a/riscv/sv.h +++ b/riscv/sv.h @@ -82,6 +82,8 @@ typedef struct { int zsz; int offs; int permute; + uint8_t map[128]; + void setup_map(); } sv_shape_t; #define SV_REMAP_REGIDX0 (0x7f) @@ -95,4 +97,11 @@ typedef struct { #define SV_SHAPE_ZDIM (0x7f<<16) #define SV_SHAPE_PERM (0x7<<24) +#define SV_SHAPE_PERM_XYZ 0 +#define SV_SHAPE_PERM_XZY 1 +#define SV_SHAPE_PERM_YXZ 2 +#define SV_SHAPE_PERM_YZX 3 +#define SV_SHAPE_PERM_ZXY 4 +#define SV_SHAPE_PERM_ZYX 5 + #endif diff --git a/riscv/sv_insn_redirect.cc b/riscv/sv_insn_redirect.cc index a4ca88a..bb3dd26 100644 --- a/riscv/sv_insn_redirect.cc +++ b/riscv/sv_insn_redirect.cc @@ -125,7 +125,7 @@ unsigned int sv_proc_t::remap(reg_spec_t const& spec) if (shape == NULL) { return offs; } - return offs; // XXX TODO + return (unsigned int)shape->map[offs] + shape->offs; } void (sv_proc_t::DO_WRITE_FREG)(reg_spec_t const& spec, sv_freg_t const& value) -- 2.30.2