help-gplusplus
[Top][All Lists]
Advanced

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

C/C++ Extended Assembly Constraint Confusion


From: woessner
Subject: C/C++ Extended Assembly Constraint Confusion
Date: Mon, 19 Mar 2012 10:50:32 -0700 (PDT)
User-agent: G2/1.0

I have written a function using some extended inline assembly.  I'm using the 
"m" constraint to reference a memory location.  If I compile it with gcc, 
everything works fine.  But if I try to compile it with g++ (version 4.6.1), it 
produces the following error:

foo.cc: In function ‘double DiffAngle(double, double)’:
foo.cc:19:8: error: memory input 3 is not directly addressable

Here is the function in question.  The line referenced in the error message is 
the closing bracket and semicolon of the asm statement.

inline 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;
}

Can anyone explain why this works with gcc but not g++?

Thanks in advance,
Bill


reply via email to

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