[Beignet] [PATCH] libocl: refine implementation of sign().
Song, Ruiling
ruiling.song at intel.com
Wed Feb 11 22:23:37 PST 2015
> > I don't know if the structure of Beignet allows it (I see that the
> > implementation is in OpenCL C rather than hardware instructions), but
> > Mesa implements sign() for GLSL in three instructions:
> >
> > cmp.nz.f0 null x:f 0.0:f
> > and ret:ud x:ud 0x80000000:ud
> > (+f0) or ret:ud ret:ud 0x3f800000:ud
> >
> > The AND instruction extracts the sign bit, and the predicated OR
> > instruction ORs in the hex value of 1.0 if x is not zero.
> >
> > This gives +1.0 if x > 0.0
> > +0.0 if x == +0.0
> > -0.0 if x == -0.0
> > -1.0 if x < 0.0
> >
> > And since the CMP.NZ's src1 is zero, you can move the conditional mod
> > back into the instruction that generated x.
> >
> > The CL spec says you also have to handle NaN, which this
> > implementation doesn't do, but that should just be an additional two
> instructions, I think:
> >
> > <CMP for NaN> (I don't remember precisely... CMPN.U maybe?)
> > (+f0) mov ret:f 0.0f
> >
> > I think this should be a few instructions shorter than what your code
> > will compile to.
I tried to implement this logic in Beignet, I find that we don't support predicated Gen IR now.
So I would keep my version, and put an TODO comment.
My version will generate 7 instructions, while mesa version would take 5 instructions.
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet
More information about the Beignet
mailing list