call asm sqrtsd under a c++

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 20:08:05

问题


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


回答1:


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



回答2:


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




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/14067236/call-asm-sqrtsd-under-a-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!