summaryrefslogtreecommitdiff
path: root/libraries/base/cbits/CastFloatWord.cmm
blob: 2edb006472394cbdc16574f5fd8fa81ed1694b70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#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);
}