using in-line asm to write a for loop with 2 comparisons
Posted
by aCuria
on Stack Overflow
See other posts from Stack Overflow
or by aCuria
Published on 2010-05-12T10:27:12Z
Indexed on
2010/05/12
10:34 UTC
Read the original article
Hit count: 303
I want to convert the for loop in the following code into assembly but i am not sure how to start. An explanation of how to do it and why it works would be appreciated.
I am using VS2010, C++, writing for the x86. The code is as follows:
for (n = 0; norm2 < 4.0 && n < N; ++n)
{
__asm{
///a*a - b*b + x
fld a // a
fmul st(0), st(0) // aa
fld b // b aa
fmul st(0), st(0) // bb aa
fsub // (aa-bb) // st(0) - st(1)
fld x // x (aa-bb)
fadd // (aa-bb+x)
/// 2.0*a*b + y;
fld d // d (aa-bb+x)
fld a // d a (aa-bb+x)
fmul // ad (aa-bb+x)
fld b // b ad (aa-bb+x)
fmul // abd (aa-bb+x)
fld y // y adb (aa-bb+x)
fadd // b:(adb+y) a:(aa-bb+x)
fld st(0) //b b:(adb+y) a:(aa-bb+x)
fmul st(0), st(0) // bb b:(adb+y) a:(aa-bb+x)
fld st(2) // a bb b:(adb+y) a:(aa-bb+x)
fmul st(0), st(0) // aa bb b:(adb+y) a:(aa-bb+x)
fadd // aa+bb b:(adb+y) a:(aa-bb+x)
fstp norm2 // store aa+bb to norm2, st(0) is popped.
fstp b
fstp a
}
}
© Stack Overflow or respective owner