call asm sqrtsd under a c++
Asked Answered
E

4

2

Under visual 2012 how can I call the sqrtsd asm function in a c++ project

I can't find it via google

something like :

double mySqrt(double val)
{
__asm
{
  ...
  sqrstd...
}
}

EDIT:

in 32bit mode

Embry answered 28/12, 2012 at 9:20 Comment(3)
Something like push argument \r\n call sqrt, however you'll need 1. the mangled name of std::sqrt(), 2. a good assembly tutorial.Wraparound
...and not 64-bit targetPacien
A related question Is it possible to roll a significantly faster version of sqrt?Richelle
T
2

I think doing this is a somewhat academic excercise, as it's unlikely to have any actual benefit, and quite likely a penalty. However:

double mySqrt(double val)
{
    double retu;

    __asm
    {
        sqrtsd xmm1, val
        movsd retu, xmm1
    }
    return retu;
}
Thracian answered 28/12, 2012 at 9:54 Comment(0)
W
3

Why not using sqrt function http://www.cplusplus.com/reference/cmath/sqrt/ which will be portable ?

By default VS 2012 will replace sqrt() by __libm_sse2_sqrt_precise. But if you compile with /fp:fast it will replace by sqrtsd

Wilbanks answered 28/12, 2012 at 9:31 Comment(2)
I would like to be sure of the asm code, cause I can have a call to __libm_sse2_sqrt_preciseEmbry
Compile with /fp:fast to get the compiler to directly emit sqrtpd without using a library function.Bukovina
M
2

You may or may not be able to use inline assembler, as other answers have indicated.

There are, however so called intrinsics for SSE (and MMX and others):

intrinsic functons for MS VS

The one for sqrtsd is _mm_sqrt_sd

You'll obviously have to read a few of the other pages as well to be able to put together the whole thing. Intrinsics is the recommended way by Microsoft to solve this.

Mackinnon answered 28/12, 2012 at 9:46 Comment(0)
T
2

I think doing this is a somewhat academic excercise, as it's unlikely to have any actual benefit, and quite likely a penalty. However:

double mySqrt(double val)
{
    double retu;

    __asm
    {
        sqrtsd xmm1, val
        movsd retu, xmm1
    }
    return retu;
}
Thracian answered 28/12, 2012 at 9:54 Comment(0)
P
0

what you want, the feature that you are looking for, it's called "inline assembly", meaning assembly inside a C/C++ program basically, Visual Studio doesn't offer a good support for this, for x64 bit platform it doesn't offer this feature at all.

http://www.viva64.com/en/k/0015/

You probably want to switch to a better compiler.

Pringle answered 28/12, 2012 at 9:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.