On 24 August 2015 at 17:17, Richard Henderson <r...@twiddle.net> wrote: > From: Chen Gang <xili_gchen_5...@hotmail.com> > > The related instructions are exception, cntlz, cnttz, shufflebytes. > > Signed-off-by: Chen Gang <gang.chen.5...@gmail.com> > Message-Id: <blu436-smtp83f96fd8422be49afdc9dfb9...@phx.gbl> > [rth: Remove incorrect implementation of add_saturate.] > Signed-off-by: Richard Henderson <r...@twiddle.net> > ---
> +/* > + * Functional Description > + * uint64_t a = rf[SrcA]; > + * uint64_t b = rf[SrcB]; > + * uint64_t d = rf[Dest]; > + * uint64_t output = 0; > + * unsigned int counter; > + * for (counter = 0; counter < (WORD_SIZE / BYTE_SIZE); counter++) > + * { > + * int sel = getByte (b, counter) & 0xf; > + * uint8_t byte = (sel < 8) ? getByte (d, sel) : getByte (a, (sel - > 8)); > + * output = setByte (output, counter, byte); > + * } > + * rf[Dest] = output; > + */ > +uint64_t helper_shufflebytes(uint64_t dest, uint64_t srca, uint64_t srcb) > +{ > + uint64_t vdst = 0; > + int count; > + > + for (count = 0; count < 64; count += 8) { > + uint64_t sel = srcb >> count; > + uint64_t src = (sel & 8) ? srca : dest; > + vdst |= ((src >> ((sel & 7) * 8)) & 0xff) << count; I would have used extract64(src, (sel & 7) * 8, 8) as being slightly easier to read in comparison with the quoted pseudocode, but it's not a big deal, so Reviewed-by: Peter Maydell <peter.mayd...@linaro.org> thanks -- PMM