[libre-riscv-dev] spike-sv non-default element widths

lkcl lkcl at libre-riscv.org
Wed Oct 10 22:02:28 BST 2018


On Wed, Oct 10, 2018 at 9:34 PM Jacob Lifshay <programmerjake at gmail.com> wrote:
>
> On Wed, Oct 10, 2018 at 7:45 AM Luke Kenneth Casson Leighton <lkcl at lkcl.net>
> wrote:
>
> > .... actually.. ah.... for signed and unsigned integers, is it
> > _actually_ the case that the size of the type will affect the answer,
> > if typecast down to e.g. int16_t/uint16_t or int8_t/uint8_t?
> >
> >  by that i mean:
> >
> >  uint64_t x = 0..255;
> >  uint64_t y = 0..255;
> >  uint8_t x1 = (uint8_t)x;
> >  uint8_t y1 = (uint8_t)y;
> >
> >  assert (x / y) == (x1 / y1)
> >
> > or any other operator.  will that hold for all possible values of x
> > and y?  i mean, i _could_ write a for-loop to check... :)
> >
> Assuming the compare only operates on the lower 8 bits, it holds for
> mul/add/sub/bitwise-logic/left-shift. It doesn't hold for div/mod or
> right-shift. That's why there are only 1 of add/sub/and/or/xor/mul in RV
> instead of a signed/unsigned version of each of them.
>
> It works similarly for any wider bitwidth simulating a narrower bitwidth as
> long as the upper bits of the results are ignored.

 ok that might work.  i was just thinking of setting some rules, to
simplify that table, as it's 4x4x4 type-casting entries (rd, rs1, rs2)
actually 2x4x4x4 because the rules are different for RV32 as from RV64
(and 3x for RV128), oh and some operations have rs3 as well!

 so a straightforward algorithm is definitely needed, and if a wider
bitwidth can simulate a narrower one by dropping the upper bits (in
*all* cases) then that would do it.

> Note that it doesn't hold for the high-bits of a double-wide mul.
>
> Also note that it doesn't work for signed integers in C/C++ as that depends
> on wrapping around being allowed, which it isn't unless you use the -fwrapv
> compiler flag. You can get around that by casting to unsigned before
> running the alu op then casting to signed again (only for
> mul/add/sub/and/or/xor/left-shift).

 dang it's complicated.  i'm going to need your help, here.

l.



More information about the libre-riscv-dev mailing list