cli/testfloat_expr_cli チュートリアル

このチュートリアルでは、2 進ランナーで Berkeley TestFloat のベクトルファイルを実行する方法を説明します。ランナーは floating-conformance --backend testfloat として呼び出します。以下では testfloat でこのコマンドを略記します。

やりたいこと使うもの
生成された 1 つのベクトルファイルを実行するtestfloat --function … FILE
testfloat_gen のオプションに合わせる--rounding, --tininess, --exact
大きなファイルを複数のプロセスに分割する--shard-count, --shard-index
機械可読な出力を得る--json
MoonBit からランナーを呼び出す@testfloat_expr_cli.run
TestFloat のマトリクス全体を実行するjust conformance run binary

クイックスタート

実行ファイルはリポジトリのチェックアウトから just conformance build binary でビルドします。

TestFloat の testfloat_gen でベクトルを生成して実行します。just conformance fetch binary は固定された SoftFloat と TestFloat のソースをダウンロードし、just conformance run binary はそれらから testfloat_gen を .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

MoonBit コードから

ランナーはライブラリでもあります。このパッケージは、公開ライブラリではなくツールモジュール Luna-Flow/floating-tools(リポジトリの tooling/ ディレクトリ、ライブラリと同じバージョン)に属します。このワークスペースのパッケージとしてコードを書くか、ツールモジュールの公開後に moon add Luna-Flow/floating-tools@0.11.0 を実行してください。moon.pkg で "Luna-Flow/floating-tools/cli/testfloat_expr_cli" をインポートし、同じ引数で run を呼び出します:

///|
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 はこのページのテストをモジュールディレクトリ tooling/ で実行するため、コーパスのパスは ../testdata で始まります。自分のコードでは自分のパスを使ってください。

日常的なタスク

生成器のオプションに合わせる

生成器と同じ関数、丸め、極小性を渡し、ベクトルが -exact で生成された場合は --exact も渡します。

testfloat_gen -rminMag -exact f32_roundToInt > r.tv
testfloat --function f32_roundToInt --rounding rminMag --exact r.tv

大きなファイルをシャードに分割する

testfloat --function f128_mulAdd --shard-count 8 --shard-index 3 --json big.tv

シャード i は、インデックスをシャード数で割った余りが i であるベクトルを実行します。

スクリプト向けの JSON

--json は function、rounding、tininess、exact、totalCases、selectedCases、passedCases、failedCases、failedIds(FUNCTION:LINE)を出力します。

さらに進んで

  • just conformance run binary --level 1 --tininess after --tininess before は完全なマトリクスを計画し、testfloat_gen の出力をチャンク単位で一時ファイルにストリームし、各チャンクに対してこのランナーを実行して、行ベースの ID をベクトル全体の通し番号に対応付け直します。
  • 合格規則については testfloat_expr チュートリアル で説明しています。

よくある落とし穴

  • ファイルはちょうど 1 つ。 2 つ目のパスはエラーになります。
  • 丸めの既定は rnear_even です。 必ず生成器のモードを渡してください。
  • ID は渡したファイルの行番号です。 ストリームをチャンクに分割する場合は、オフセットを自分で管理してください。

次のステップ