itun
itun

Reputation: 3521

How to work with float variables at asm in VS

I need to write a common task with inline asm: The Code I used is as Follows.

Vector3 Matrix3x3::objectToInertial(const Vector3 &v) 
{
    return Vector3(
        m11 * v.x + m12 * v.y + m13 * v.z,
        m21 * v.x + m22 * v.y + m23 * v.z,
        m31 * v.x + m32 * v.y + m33 * v.z
        );
}

How to make this equation with asm: m11 * v.x + m12 * v.y?

Upvotes: 0

Views: 766

Answers (2)

Andy Finkenstadt
Andy Finkenstadt

Reputation: 3587

#if *MICROSOFT_COMPILER_DETECTION*
#define APP_FORCEINLINE __forceinline
#else
#if *GCC_COMPILER_DETECTION*
#define APP_FORCEINLINE inline
#else
#define APP_FORCEINLINE /* */
#endif
#endif

APP_FORCEINLINE
Vector3 Matrix3x3::objectToInertial(const Vector3 &v) {
return Vector3(
    m11 * v.x + m12 * v.y + m13 * v.z,
    m21 * v.x + m22 * v.y + m23 * v.z,
    m31 * v.x + m32 * v.y + m33 * v.z
    );

Keep in mind that inlining is just a suggestion to the compiler, albeit it, a strong one.

The optimizing compilers of today may benefit from using different data structures than the Matrix3x3 class in use here. XNAMATH.X (from Microsoft XNA) is designed to be cross-platform, and to take advantage of built-in intrinsics for math operations, when available for your requested CPU.

Upvotes: 1

ds27680
ds27680

Reputation: 1993

If you really want to compute m11 * v.x + m12 * v.y by inline assembler try this (I am assuming you want to store the result in a variable result):

__asm
{
   fld m11
   fmul v.x
   fld m12
   fmul v.y
   faddp st(1), st
   fstp result
}

If you want to learn more about floating point arithmetic in assembly you can take a look at Art of Assembly Language - Chapter 14 - you can download the book also as pdf it would seem.

Upvotes: 2

Related Questions