Repository: dotnet/runtime
File: src/coreclr/jit/emitwasm.cpp (C++)

Code before:
            dst += emitOutputByte(dst, 0x40 /* block type of void */);
            break;
        case IF_ULEB128:
        {
            dst += emitOutputByte(dst, opcode);
            cnsval_ssize_t constant = emitGetInsSC(id);
            dst += emitOutputULEB128(dst, constant);
            break;
        }
        case IF_SLEB128:
        {
            dst += emitOutputByte(dst, opcode);
            cnsval_ssize_t constant = emitGetInsSC(id);
            dst += emitOutputSLEB128(dst, constant);
            break;
        }
        case IF_F32:
        {
            dst += emitOutputByte(dst, opcode);
            // Reinterpret the bits as a double constant and then truncate it to f32,
            //  then finally copy the raw truncated f32 bits to the output.
            cnsval_ssize_t bits = emitGetInsSC(id);
            double         value;
            float          truncated;
            memcpy(&value, &bits, sizeof(double));
            truncated = (float)value;
            memcpy(dst + writeableOffset, &truncated, sizeof(float));
            dst += sizeof(float);
            break;
        }
        case IF_F64:
        {
            dst += emitOutputByte(dst, opcode);
            // The int64 bits are actually a double constant we can copy directly
            //  to the output stream.
            cnsval_ssize_t bits = emitGetInsSC(id);
            memcpy(dst + writeableOffset, &bits, sizeof(double));
            dst += sizeof(double);
            break;
        }
        case IF_LABEL:
            NYI_WASM("emitOutputInstr IF_LABEL");
            break;
        case IF_MEMARG:
        {
            dst += emitOutputByte(dst, opcode);
            uint64_t align  = 0; // FIXME
            uint64_t offset = emitGetInsSC(id);
            assert(align <= UINT32_MAX); // spec says memarg alignment is u32
            assert(align < 64);          // spec says align > 2^6 produces a memidx for multiple memories.
            dst += emitOutputULEB128(dst, align);

Review comment (suggestion):
Elsewhere we just use `static_cast` so there's no bit manipulation going on
```suggestion
            float truncated = static_cast<float>(bits);
```

Code after:

    switch (insFmt)
    {
        case IF_OPCODE:
            dst += emitOutputByte(dst, opcode);
            break;
        case IF_BLOCK:
            dst += emitOutputByte(dst, opcode);
            dst += emitOutputByte(dst, 0x40 /* block type of void */);
            break;
        case IF_ULEB128:
        {
            dst += emitOutputByte(dst, opcode);
            cnsval_ssize_t constant = emitGetInsSC(id);
            dst += emitOutputULEB128(dst, (uint64_t)constant);
            break;
        }
        case IF_SLEB128:
        {
            dst += emitOutputByte(dst, opcode);
            cnsval_ssize_t constant = emitGetInsSC(id);
            dst += emitOutputSLEB128(dst, (int64_t)constant);
            break;
        }
        case IF_F32:
        {
            dst += emitOutputByte(dst, opcode);
            // Reinterpret the bits as a double constant and then truncate it to f32,
            //  then finally copy the raw truncated f32 bits to the output.
            cnsval_ssize_t bits = emitGetInsSC(id);
            double         value;
            float          truncated;
            memcpy(&value, &bits, sizeof(double));
            truncated = FloatingPointUtils::convertToSingle(value);
            dst += emitRawBytes(dst, &truncated, sizeof(float));
            break;
        }
        case IF_F64:
        {
            dst += emitOutputByte(dst, opcode);
            // The int64 bits are actually a double constant we can copy directly
            //  to the output stream.
            cnsval_ssize_t bits = emitGetInsSC(id);
            dst += emitRawBytes(dst, &bits, sizeof(cnsval_ssize_t));
            break;
        }
        case IF_LABEL:
            NYI_WASM("emitOutputInstr IF_LABEL");
            break;
        case IF_MEMARG:
        {