#include "Cmm.h"
#include "MachDeps.h"

#if WORD_SIZE_IN_BITS == 64
#define DOUBLE_SIZE_WDS   1
#else
#define DOUBLE_SIZE_WDS   2
#endif

stg_word64ToDoublezh(I64 w)
{
    D_ d;
    P_ ptr;

    STK_CHK_GEN_N (DOUBLE_SIZE_WDS);

    reserve DOUBLE_SIZE_WDS = ptr {
        I64[ptr] = w;
        d = D_[ptr];
    }

    return (d);
}

stg_doubleToWord64zh(D_ d)
{
    I64 w;
    P_ ptr;

    STK_CHK_GEN_N (DOUBLE_SIZE_WDS);

    reserve DOUBLE_SIZE_WDS = ptr {
        D_[ptr] = d;
        w = I64[ptr];
    }

    return (w);
}

stg_word32ToFloatzh(W_ w)
{
    F_ f;
    P_ ptr;

    STK_CHK_GEN_N (1);

    reserve 1 = ptr {
        I32[ptr] = %lobits32(w);
        f = F_[ptr];
    }

    return (f);
}

stg_floatToWord32zh(F_ f)
{
    W_ w;
    P_ ptr;

    STK_CHK_GEN_N (1);

    reserve 1 = ptr {
        F_[ptr] = f;
        // Fix #16617: use zero-extending (TO_ZXW_) here
        w = TO_ZXW_(I32[ptr]);
    }

    return (w);
}

