cli/testfloat_expr_cli tutorial
This tutorial shows how to execute a Berkeley TestFloat vector file with the
binary runner. The runner is reached as
floating-conformance --backend testfloat; below, testfloat abbreviates that
command.
| I want to | Use |
|---|---|
| run one generated vector file | testfloat --function … FILE |
match testfloat_gen options | --rounding, --tininess, --exact |
| split a large file over processes | --shard-count, --shard-index |
| get machine-readable output | --json |
| call the runner from MoonBit | @testfloat_expr_cli.run |
| run the whole TestFloat matrix | just conformance run binary |
Quick start
The executable is built from a checkout of the repository with
just conformance build binary.
Generate vectors with TestFloat’s testfloat_gen and run them.
just conformance fetch binary downloads the pinned SoftFloat and TestFloat
sources; just conformance run binary builds testfloat_gen from them into
.tmp/binary-conformance/vendor/TestFloat-3e/build/Linux-x86_64-GCC/.
testfloat_gen -level 1 -rnear_even -tininessafter f64_mul > f64_mul.tv
testfloat --function f64_mul --rounding rnear_even --tininess after f64_mul.tv
TestFloat execution summary
function: f64_mul
rounding: rnear_even
tininess: after
cases: …
selected cases: …
passed cases: …
failed cases: 0
From MoonBit code
The runner is also a library. The package belongs to the tools module Luna-Flow/floating-tools (directory tooling/ of the repository, versioned with the library), not to the published library. Write your code as a package of this workspace or, once the tools module is published, run moon add Luna-Flow/floating-tools@0.11.0. Import
"Luna-Flow/floating-tools/cli/testfloat_expr_cli" in moon.pkg and call run
with the same arguments:
///|
test "run the TestFloat runner from MoonBit code" {
let status = @testfloat_expr_cli.run([
"testfloat", "--function", "f16_add", "--rounding", "rnear_even", "--tininess",
"after", "../testdata/binary/smoke/f16_add_rnear_even_after.testfloat",
])
inspect(status, content="0")
}
just docs runs the tests of this page in the module directory tooling/, so the corpus paths start with ../testdata; use your own paths in your code.
Everyday tasks
Match the generator options
Pass the same function, rounding and tininess as the generator, and --exact
when the vectors were generated with -exact:
testfloat_gen -rminMag -exact f32_roundToInt > r.tv
testfloat --function f32_roundToInt --rounding rminMag --exact r.tv
Shard a large file
testfloat --function f128_mulAdd --shard-count 8 --shard-index 3 --json big.tv
Shard i runs the vectors whose index is i modulo the shard count.
JSON for scripts
--json prints function, rounding, tininess, exact, totalCases,
selectedCases, passedCases, failedCases and failedIds
(FUNCTION:LINE).
Going further
just conformance run binary --level 1 --tininess after --tininess beforeplans the full matrix, streamstestfloat_genoutput in chunks into temporary files, runs this runner on each chunk, and remaps the line-based ids to global vector numbers.- testfloat_expr tutorial explains the pass rule.
Common pitfalls
- Exactly one file. A second path is an error.
- Rounding defaults to
rnear_even. Always pass the generator’s mode. - Ids are line numbers of the file you pass. When you split a stream into chunks, keep track of the offset yourself.