Skip to content

missing representation-preserving scalar bitcast #44

Description

@resetius

missing representation-preserving scalar bitcast

Status

  • Fix agreed upon.
  • Regression case added to externals/qumir/test/regtest/cases/corelang.
  • AST/core syntax has an explicit scalar bitcast or an equivalent intrinsic.
  • Full Qumir regtest passes.

Scenario

Hashing f64 requires obtaining the IEEE-754 representation as u64 without
a numeric conversion of the value.

An ordinary cast:

(cast value u64)

lowers to f2i/LLVM fptoui. This is a numeric conversion, not a bitcast. It
loses the representation and is incorrect for negative values, NaN, and large
exponent values.

Expected behavior

The core language should have an explicit operation with a same-byte-size
check:

(bitcast value u64)

or a standard intrinsic bitcast_f64_u64(f64) -> u64. Lowering should
generate a representation-preserving IR/LLVM bitcast.

Actual limitation

TCastExpr supports numeric casts and pointer casts. There is no public AST
node for a scalar bitcast. Core syntax also does not allow explicitly taking
the address of a local scalar and reading it through a pointer of another
type.

Workaround

register a narrow external primitive f64_bits(f64) -> u64, implemented via std::bit_cast

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions