On Jan 19, 1:08 pm, Bill Woessner <woess...@nospicedham.gmail.com> wrote: > 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
This works for me: #include <math.h> double DiffAngle(double theta1, double theta2) { static const double TWO_PI __attribute__ ((aligned (16))) = 2 * M_PI; double delta = theta1 - theta2; asm("cmpnlesd %0, %1\n" "cmpltsd %0, %2\n" "andpd %3, %1\n" "andpd %3, %2\n" "addsd %1, %0\n" "subsd %2, %0\n" : "+x" (delta) : "x" (M_PI), "x" (-M_PI), "m" (TWO_PI) : ); return delta; } (Using another trick, where the variable containing -2pi can be replaced by a subtraction of +2pi.) Steven _______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org https://lists.gnu.org/mailman/listinfo/help-gplusplus