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

Guillaume Paris
  • 10,303
  • 14
  • 70
  • 145
  • Something like `push argument \r\n call sqrt`, however you'll need 1. the mangled name of `std::sqrt()`, 2. a good assembly tutorial. –  Dec 28 '12 at 09:21
  • ...and not 64-bit target – SomeWittyUsername Dec 28 '12 at 09:22
  • 1
    A related question [Is it possible to roll a significantly faster version of sqrt?](http://stackoverflow.com/questions/2637700/is-it-possible-to-roll-a-significantly-faster-version-of-sqrt) – Bo Persson Dec 28 '12 at 09:43

4 Answers4

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

benjarobin
  • 4,410
  • 27
  • 21
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.

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227
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;
}
Guillaume Paris
  • 10,303
  • 14
  • 70
  • 145
JasonD
  • 16,464
  • 2
  • 29
  • 44
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.

user1849534
  • 2,329
  • 4
  • 18
  • 20