[Mesa-dev] [PATCH 4/6] Bitwise conversion operator support in ir_constant_expression.
Jose Fonseca
jfonseca at vmware.com
Sun May 20 05:04:43 PDT 2012
----- Original Message -----
> On Sat, May 19, 2012 at 11:59:24AM -0700, Jose Fonseca wrote:
> >
> >
> > ----- Original Message -----
> > > +/* This method is the only one supported by gcc. Unions in
> > > particular
> > > + * are iffy, and read-through-converted-pointer is killed by
> > > strict
> > > + * aliasing. OTOH, the compiler sees through the memcpy, so the
> > > + * resulting asm is reasonable.
> > > + */
> > > +static float
> > > +bitcast_u2f(unsigned int u)
> > > +{
> > > + assert(sizeof(float) == sizeof(unsigned int));
> > > + float f;
> > > + memcpy(&f, &u, sizeof(f));
> > > + return f;
> > > +}
> > > +
> > > +static unsigned int
> > > +bitcast_f2u(float f)
> > > +{
> > > + assert(sizeof(float) == sizeof(unsigned int));
> > > + unsigned int u;
> > > + memcpy(&u, &f, sizeof(f));
> > > + return u;
> > > +}
> > > +
> [...]
>
> > > ir_constant *
> > > ir_rvalue::constant_expression_value(struct hash_table
> > > *variable_context)
> > > {
> > > @@ -207,6 +230,30 @@
> > > ir_expression::constant_expression_value(struct
> > > hash_table *variable_context)
> > > data.u[c] = op[0]->value.i[c];
> > > }
> > > break;
> > > + case ir_unop_bitcast_i2f:
> > > + assert(op[0]->type->base_type == GLSL_TYPE_INT);
> > > + for (unsigned c = 0; c < op[0]->type->components(); c++) {
> > > + data.f[c] = bitcast_u2f(op[0]->value.i[c]);
> >
> > Shouldn't it be bitcast_i2f ?
>
> No, these are the immediate execution paths, which call the C
> functions up there. Doing a signed version would be redundant and
> would result in strictly identical asm, the implicit (bit-identical)
> conversion there is perfectly appropriate.
I see. All looks good then.
Jose
More information about the mesa-dev
mailing list