help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with Hand-Optimized Assembly


From: Bill Woessner
Subject: Re: Help with Hand-Optimized Assembly
Date: Wed, 28 Mar 2012 18:30:00 -0000
User-agent: G2/1.0

Success!  Thanks to everyone who helped me out.  This was a great
little project to learn about inline assembly in GCC.  For those of
you who are interested, here's the final product:

inline double DiffAngle(double theta1, double theta2)
{
  double TWO_PI __attribute__ ((aligned (16)))(2 * M_PI),
    NEG_TWO_PI __attribute__ ((aligned (16)))(-TWO_PI);
  double delta(theta1 - theta2);

  asm("cmpnlesd %0, %1\n\t"
      "cmpltsd %0, %2\n\t"
      "andpd %3, %1\n\t"
      "andpd %4, %2\n\t"
      "addsd %1, %0\n\t"
      "addsd %2, %0\n\t"
      : "+x" (delta)
      : "x" (M_PI),
        "x" (-M_PI),
        "m" (TWO_PI),
        "m" (NEG_TWO_PI)
      :
      );

  return delta;
}

One final question - is it possible to declare TWO_PI and NEG_TWO_PI
as const?  And, if so, what constraint would I use?  Right now, if I
declare them const, I get the error "memory input 3 is not directly
addressable".

Thanks,
Bill


reply via email to

[Prev in Thread] Current Thread [Next in Thread]