[Libre-soc-dev] clamping/saturation semantics

Jacob Lifshay programmerjake at gmail.com
Fri Dec 11 22:22:04 GMT 2020


On Fri, Dec 11, 2020, 13:54 Luke Kenneth Casson Leighton <lkcl at lkcl.net>
wrote:

> On 12/11/20, Jacob Lifshay <programmerjake at gmail.com> wrote:
>
> > I've never heard of an ISA that saturates to a different size than the
> dest
> > size,
>
> 3 back in this thread, unless i am mistaken, Lauri did exactly that.
>

assuming you're referring to:

On Thu, Dec 10, 2020, 23:23 Lauri Kasanen <cand at gmx.com> wrote:

On Thu, 10 Dec 2020 18:07:23 +0000
Luke Kenneth Casson Leighton <lkcl at lkcl.net> wrote:

> does this look like a reasonable general-purpose algorithm, applicable
> to all operations, whether exts*, mr, or 2/3 arithmetic ops?
>
> * saturation is done on the result at the **source** elwidth

This would be a problem. For many cases, dst width != src width.

Say you have gathered stuff to u16 and then want to scale that into
u8, clamped. That's a u16 * u16 = u8 op - different src and dst
elwidths.


I interpreted that as:
u16 in1, in2;
u64 a = in1;
u64 b = in2;
u64 prod = a * b;
u8 out = min(0xFF, prod);

note that the clamp size == the dest size.

Jacob


More information about the Libre-soc-dev mailing list