[Beignet] [PATCH] LibOcl: Fix float convert to long/ulong bug.

Song, Ruiling ruiling.song at intel.com
Tue Oct 20 23:17:25 PDT 2015


> > > +OVERLOADABLE DSTTYPE convert_ ## DSTTYPE ## _sat(SRCTYPE x) { \
> > > +  return x >= SRC_MAX ? DST_MAX : x <= SRC_MIN ? (DSTTYPE)DST_MIN :
> > > (DSTTYPE)x; \
> >
> > Why don't you use two sentences here?suppose this kind of writing would
> > generate if-else blocks?
> > Other parts LGTM.
> It is hard to use two sentences. Think about two methods:
> 
> x = x >= SRC_MAX ? DST_MAX : x;
> return x <= SRC_ MIN? (DSTTYPE) DST_MIN: (DSTTYPE)x;
> The second sentences may convert SRC_MAX to DSTTYPE  and return, because
> SRC_MAX is overflow, so the value may be undefined.
> 
> Another methods:
> DSTTYPE y = x >= SRC_MAX ? DST_MAX: (DSTTYPE)x;
> return x <= SRC_MIN ? (DSTTYPE) DST_MIN : (DSTTYPE)y;
> But in the first sentences, when convert x to y, the x may underflow, so the y
> also may be undefined.
Underflow would only occur if x<= SRC_MIN, right?
Then the final result would be DST_MIN. so the final result is also defined.
What I mean is this kind of form. This form would avoid unnecessary if-else extra basic block generation I think. 
> 
> Don't you have other suggestion?


More information about the Beignet mailing list