diff options
author | Marcus Comstedt <marcus@mc.pp.se> | 2019-08-18 16:03:43 +0200 |
---|---|---|
committer | Chih-Min Chao <chihmin.chao@sifive.com> | 2019-10-29 03:33:45 -0700 |
commit | 65648669c15343cb1aa6b102cf2eae0ed91024cd (patch) | |
tree | 4530bee628e72cf17adeca999e9826ea4a0f88a9 /riscv/decode.h | |
parent | 7c85cc44d13547ab7260438d97671d7f423e5d6c (diff) | |
download | spike-65648669c15343cb1aa6b102cf2eae0ed91024cd.zip spike-65648669c15343cb1aa6b102cf2eae0ed91024cd.tar.gz spike-65648669c15343cb1aa6b102cf2eae0ed91024cd.tar.bz2 |
Implement support for big-endian hosts
Signed-off-by: Chih-Min Chao <chihmin.chao@sifive.com>
Diffstat (limited to 'riscv/decode.h')
-rw-r--r-- | riscv/decode.h | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/riscv/decode.h b/riscv/decode.h index 2fb8192..3e759a3 100644 --- a/riscv/decode.h +++ b/riscv/decode.h @@ -7,10 +7,6 @@ # error spike requires a two''s-complement c++ implementation #endif -#ifdef WORDS_BIGENDIAN -# error spike requires a little-endian host -#endif - #include <algorithm> #include <cstdint> #include <string.h> @@ -69,6 +65,23 @@ const int NCSR = 4096; #define MAX_INSN_LENGTH 8 #define PC_ALIGN 2 +#ifdef WORDS_BIGENDIAN + // Elements are stored in opposite order, see comment in processor.h + #define TAIL_ZERO(x) \ + uint8_t *tail = &P.VU.elt<uint8_t>(rd_num, vl * (x) - 1); \ + memset(tail - (P.VU.vlmax - vl) * (x), 0, (P.VU.vlmax - vl) * (x)); + #define TAIL_ZERO_REDUCTION(x) \ + uint8_t *tail = (uint8_t *)&P.VU.elt<type_sew_t<x>::type>(rd_num, 0); \ + memset(tail - ((P.VU.get_vlen() - x) >> 3), 0, (P.VU.get_vlen() - x) >> 3); +#else + #define TAIL_ZERO(x) \ + uint8_t *tail = &P.VU.elt<uint8_t>(rd_num, vl * (x)); \ + memset(tail, 0, (P.VU.vlmax - vl) * (x)); + #define TAIL_ZERO_REDUCTION(x) \ + uint8_t *tail = (uint8_t *)&P.VU.elt<type_sew_t<x>::type>(rd_num, 1); \ + memset(tail, 0, (P.VU.get_vlen() - x) >> 3); +#endif + typedef uint64_t insn_bits_t; class insn_t { @@ -486,8 +499,7 @@ static inline bool is_overlaped(const int astart, const int asize, #define VI_TAIL_ZERO(elm) \ if (vl != 0 && vl < P.VU.vlmax && P.VU.TZ) { \ - uint8_t *tail = &P.VU.elt<uint8_t>(rd_num, vl * ((sew >> 3) * elm)); \ - memset(tail, 0, (P.VU.vlmax - vl) * ((sew >> 3) * elm)); \ + TAIL_ZERO((sew >> 3) * elm); \ } #define VI_TAIL_ZERO_MASK(dst) \ @@ -518,8 +530,7 @@ static inline bool is_overlaped(const int astart, const int asize, #define VI_LOOP_WIDEN_END \ } \ if (vl != 0 && vl < P.VU.vlmax && P.VU.TZ){ \ - uint8_t *tail = &P.VU.elt<uint8_t>(rd_num, vl * ((sew >> 3) * 2)); \ - memset(tail, 0, (P.VU.vlmax - vl) * ((sew >> 3) * 2)); \ + TAIL_ZERO((sew >> 3) * 2); \ }\ P.VU.vstart = 0; @@ -528,8 +539,7 @@ static inline bool is_overlaped(const int astart, const int asize, if (vl > 0) { \ vd_0_des = vd_0_res; \ if (P.VU.TZ) { \ - uint8_t *tail = (uint8_t *)&P.VU.elt<type_sew_t<x>::type>(rd_num, 1); \ - memset(tail, 0, (P.VU.get_vlen() - x) >> 3); \ + TAIL_ZERO_REDUCTION(x); \ } \ } \ P.VU.vstart = 0; @@ -1638,16 +1648,14 @@ for (reg_t i = 0; i < vlmax && P.VU.vl != 0; ++i) { \ #define VI_VFP_LOOP_END \ } \ if (vl != 0 && vl < P.VU.vlmax && P.VU.TZ){ \ - uint8_t *tail = &P.VU.elt<uint8_t>(rd_num, vl * ((P.VU.vsew >> 3) * 1)); \ - memset(tail, 0, (P.VU.vlmax - vl) * ((P.VU.vsew >> 3) * 1)); \ + TAIL_ZERO((P.VU.vsew >> 3) * 1); \ }\ P.VU.vstart = 0; \ #define VI_VFP_LOOP_WIDE_END \ } \ if (vl != 0 && vl < P.VU.vlmax && P.VU.TZ){ \ - uint8_t *tail = &P.VU.elt<uint8_t>(rd_num, vl * ((P.VU.vsew >> 3) * 2)); \ - memset(tail, 0, (P.VU.vlmax - vl) * ((P.VU.vsew >> 3) * 2)); \ + TAIL_ZERO((P.VU.vsew >> 3) * 2); \ }\ P.VU.vstart = 0; \ set_fp_exceptions; |