feat(runtime,backend): Float64 and Float32 bits() and ofBits(_) #358
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/348-float-bits"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #348
What and why
Adds
Float64.bits(): UInt64,Float64.ofBits(_): Float64,Float32.bits(): UInt32andFloat32.ofBits(_): Float32tostd/number. Each one is amemcpyruntime function (torb_bits_f64,torb_of_bits_f64,torb_bits_f32,torb_of_bits_f32). The C back end and the VM thunks call the same functions, so both give the same bits.Float32as thedoubleit equals. A C cast betweenfloatanddoublequiets a signalling nan such as0x7fa00000, so everyfloatin a thunk now crosses a register through two new helpers inruntime/machine.c:torb_machine_float_ofandtorb_machine_word_of_float. These carry a nan by its sign and payload bits and convert every other value exactly as before. This touches the parameters oftorb_compare_f32andtorb_show_f32and the out-parameters oftorb_parse_f32andtorb_convert_f64_f32_checked, without changing their results for any value that is not a nan.const x = Float64.ofBits(...)at the top level is the usual "has to be known at compile time" error. A new test inconstants.test.trbpins this.std/or the compiler uses them yet (the seed rule of #35). Movingstd/binary/src/number.trbonto them is the second commit, after a seed that knows them is published.docs/design/BINARY.mdsection 10 says so.runtime/include/torb_natives.handruntime/machine_natives.care regenerated. The four new symbols renumber the later thunks; after the rebase onto theDecimalnatives the table is the union of both, in the manifest's sorted order.Tests
runtime/tests/number_test.c: round trips of every special pattern, plus1.0→0x3ff0000000000000and0x3f800000.compiler/tests: the manifest entries are ready, the float thunks cross through the new helpers, and a bit cast is never constant-folded (the harness prelude has nostd/number, so that test declares the twoFloat64natives itself).tests/conformance/float64-bits.trbandfloat32-bits.trb:-0.0, subnormals, the infinities, quiet, signalling and negative nans with payloads, carried through a parameter, a list and a reassigned variable, in both back ends. Their allocation budgets (.allocations: 550 and 358 blocks) are the counts of the first CI run.std/number,docs/standard-library/number.mdwith its skill copy, andBINARY.mdsection 10.Bootstrap, gates and conformance run in CI only.
f6acdc5377f4536c7a28Approved at
f4536c7. Checklist:number_test.cround trips, manifest and thunk-text tests, the constant-folding test, and conformance programs for both widths. CI is green on this head (bootstrap, tier A/B, gates, pdisc).memcpy. Thetorb_machine_float_of/torb_machine_word_of_floatmapping puts the 23-bit float payload at the top of the 52 bits of the double, and the sign and non-nan values convert as before.std/or the compiler uses the natives yet, so the seed rule holds.number.mdwith its skill copy,BINARY.mdsection 10 and the conformance README.Non-blocking:
torb_machine_float_oftreats any double nan whose top 23 payload bits are zero (for example0x7ff0000000000001) as0x7f800000, which is an infinity. A float register only gets nans throughtorb_machine_word_of_float, whose low 29 bits are always zero, so this cannot happen today. Forcing the quiet bit or a nonzero payload in that branch would make it robust against other writers.