(this is Linux, the same happens on Darwin).
This is not really a good idea, as movsd of a double-precision 1.0 is faster.

I wonder whether fixing compress_float_constant is better. It seems similar to the old hack in expr.c: expanding a/b to a*(1/b), and hope that it is transformed back to a/b or CSE-ed.

Also, here is some code that tries to load 1.0 into an SSE register without using the constant pool. I don't know if it is fast or not.

float f = 1, g;
double h = 1, i;

void main ()
{
  /* Generates movl + movd */
  asm volatile
      ("movd %1, %0" : "=x" (g) : "r" (0x3f800000));
  printf ("%x %f %f\n", *(unsigned int *) &f, f, g);

  /* Generates movl + xorps + pinsrwl */
  asm volatile
      ("xorps %0, %0;\
        pinsrwl $3, %1, %0" : "=x" (i) : "r" (0x3ff0));
  printf ("%llx %llx %f %f\n", *(unsigned long long *) &h,
          *(unsigned long long *) &i, h, i);
}

Paolo

Reply via email to