0

I was trying to convert 32bit game client to 64bit. But I can't compile, because the client has an inline ASM code, 64bit doesn't support __asm inline. So I can't find a solution for this. I hope I can get into this community.

define inline code:

#define PR_FLOAT_TO_INTASM __asm    \
{                                   \
    __asm fld PR_FCNV               \
    __asm fistp PR_ICNV             \
}
#define PR_FLOAT_TO_INT(inreal, outint)                         \
{                                                               \
    PR_FCNV = (inreal);                                         \
    PR_FLOAT_TO_INTASM;                                         \
    (outint) = PR_ICNV > PR_FCNV ? PR_ICNV - 1 : PR_ICNV;       \
}

Example code using:

float CMapOutdoor::GetTerrainHeight(float fx, float fy)
{
    if (fy < 0)
        fy = -fy;
    long lx, ly;
    PR_FLOAT_TO_INT(fx, lx);
    PR_FLOAT_TO_INT(fy, ly);

    WORD usCoordX, usCoordY;

    usCoordX = (WORD)(lx / CTerrainImpl::TERRAIN_XSIZE);
    usCoordY = (WORD)(ly / CTerrainImpl::TERRAIN_YSIZE);

    BYTE byTerrainNum;
    if (!GetTerrainNumFromCoord(usCoordX, usCoordY, &byTerrainNum))
        return 0.0f;

    CTerrain* pTerrain;

    if (!GetTerrainPointer(byTerrainNum, &pTerrain))
        return 0.0f;

    return pTerrain->GetHeight(lx, ly);
}

Error code:

error C2146: syntax error : missing ';' before identifier 'PR_ICNV'
error C2146: syntax error : missing ';' before identifier 'fistp'
error C2146: syntax error : missing ';' before identifier '}'
Sweta Jain
  • 3,248
  • 6
  • 30
  • 50
dracaryS
  • 1
  • 2
  • 1
    Use any mainstream compiler other than MSVC. But really you don't need or even want inline asm for this, or legacy x87 instructions at all. Looks like you're just converting `float` to `int32_t` with round-to-nearest (`fistp`), which you should do with `lrint(float)` or `(int)nearbyint(float)`. Except then you're manually rounding down to implement round toward -inf? There's no SSE/AVX instruction that can override the rounding mode for that, but with SSE4.1 `roundss` you can efficiently `(int)floor(float)` – Peter Cordes Nov 14 '21 at 02:52
  • So really a better question to ask would be how to efficiently (when compiled by MSVC for x86-64, and probably also 32-bit x86) implement conversion to integer with rounding towards -inf. Very likely this is not actually optimal asm for 32-bit, especially if it involves copying your float to some random global variable and reloading. I assume `PR_FCNV` is defined somewhere?/ – Peter Cordes Nov 14 '21 at 02:59
  • @PeterCordes , Yes have define. ` float PR_FCNV; long PR_ICNV;` – dracaryS Nov 14 '21 at 04:30

0 Answers0