Re: [Qemu-devel] [PATCH v1 1/5] target-ppc: add vector insert instructions

2016-08-08 Thread David Gibson
On Thu, Aug 04, 2016 at 10:08:17PM +0530, Richard Henderson wrote:
> On 08/04/2016 06:33 PM, Rajalakshmi Srinivasaraghavan wrote:
> > +#if defined(HOST_WORDS_BIGENDIAN)
> > +#define VINSERT(suffix, element, index)
> >  \
> > +void helper_vinsert##suffix(ppc_avr_t *r, ppc_avr_t *b, uint32_t 
> > splat) \
> > +{  
> >  \
> > +memcpy(>u8[SPLAT_ELEMENT(u8)], >element[index],  
> >  \

It seems odd to use SPLAT_ELEMENT() here but not in the LE case, given
that SPLAT_ELEMENT() is already a macro whose definition is
conditional on endianness.  It might actually be clearer to open code it.

> > +   sizeof(r->element[0])); 
> >  \
> > +}
> > +#else
> > +#define VINSERT(suffix, element, index)
> >  \
> > +void helper_vinsert##suffix(ppc_avr_t *r, ppc_avr_t *b, uint32_t 
> > splat) \
> > +{  
> >  \
> > +memcpy(>u8[(16 - splat) - sizeof(r->element[0])],   
> >  \
> > +   >element[(ARRAY_SIZE(r->element) - index) - 1],  
> >  \
> > +   sizeof(r->element[0])); 
> >  \
> > +}
> 
> Something somewhere needs to check for out of bounds SPLAT, for evil guests.
> 
> The spec says it's undefined; I don't recall if that gives you the latitude
> to generate an illegal instruction trap during translate.

splat is an immediate argument, so that should be done on the
generator side, rather than the helper side.  It's already partially
done by the way it's extracted from the instruction.

But, AFAICT that just limits splat to 5 bits, and I'm not sure that's
enough for all forms of this instruction.

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH v1 1/5] target-ppc: add vector insert instructions

2016-08-04 Thread Richard Henderson

On 08/04/2016 06:33 PM, Rajalakshmi Srinivasaraghavan wrote:

+#if defined(HOST_WORDS_BIGENDIAN)
+#define VINSERT(suffix, element, index) \
+void helper_vinsert##suffix(ppc_avr_t *r, ppc_avr_t *b, uint32_t splat) \
+{   \
+memcpy(>u8[SPLAT_ELEMENT(u8)], >element[index],   \
+   sizeof(r->element[0]));  \
+}
+#else
+#define VINSERT(suffix, element, index) \
+void helper_vinsert##suffix(ppc_avr_t *r, ppc_avr_t *b, uint32_t splat) \
+{   \
+memcpy(>u8[(16 - splat) - sizeof(r->element[0])],\
+   >element[(ARRAY_SIZE(r->element) - index) - 1],   \
+   sizeof(r->element[0]));  \
+}


Something somewhere needs to check for out of bounds SPLAT, for evil guests.

The spec says it's undefined; I don't recall if that gives you the latitude to 
generate an illegal instruction trap during translate.



r~