|
|
Message-ID: <c3a94a37-03c9-49ec-b8f9-334926312d66@gmail.com> Date: Fri, 4 Sep 2026 19:31:30 +0300 From: dzaima <dzaimagit@...il.com> To: Szabolcs Nagy <nsz@...t70.net> Cc: musl@...ts.openwall.com Subject: Re: [PATCH v4 2/2] math: fmaf rewrite Hello from the person that did the SMT verification :) On 9/3/26 15:32, Szabolcs Nagy wrote: > note the code is not correct under some fast-math flags. Wanting an exact FMA implementation under any fast-math flags doesn't exactly make much sense in the first place, of course. My SMT code assumes IEEE-754 to be exactly followed (no FTZ/DAZ), and for there to be no implicit contraction. (replacing xy+z with an explicit FMA still passes, so at least that bit of contraction would be fine, albeit funny). I've modeled NaN bit pattern propagation rules following LLVM's descriptions (https://llvm.org/docs/LangRef.html#behavior-of-floating-point-nan-values), with 3 different models: x86 (which is identical to ARM and RISC-V), SPARC, and wasm. I'd assume GCC's behaviors should be similar, but haven't happened across any docs for it. > i didnt find info on how to use this for verification. The SMT interface is not public yet, sorry... So the code samples are "useless" other than as a reference to how I translated the code. > e.g. the correctness of the FLT_EVAL_METHOD==2 case is not > obvious, nor if the e==0x7ff check is needed given that > branch is never taken on most implementations, would the > tool catch that if you removed this check?. Cannot comment on FLT_EVAL_METHOD==2; that's a massive mess. Bitwuzla theoretically could do IEEE-754 binary128, but other float formats (incl. x87's) are experimental. Never mind the problem of how exactly compilers handle it. (and larger floats would probably take much more time to verify anyway (for reference, the current version takes 14 to 25 minutes (single-threaded) on my old PC to verify)). Removing the e==0x7ff check does still verify as correct for all the aforementioned NaN propagation rules. (all checks in this email are done with the e==0x7ff check removed) There do exist rules where the check is needed to maintain strict correctness; e.g. with the x86 rule, except 64-bit float ops are allowed to optionally change QNaN payload to 0x4000000000000 (i.e. with top payload bit (after quiet bit) set; no such change for 32-bit floats though!), my tool spits out this counterexample for the version without a e==0x7ff check: https://dzaima.github.io/paste/#0hVbNjts2EL77KSYJ0LUSb6EfW/7prtGiyB4DFL2HkL2kLURLbSlqa6@...Oe@...uDxJZ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GWTe@...z/rqF4BXBinOddqrPx4RHy8rCisOXS0Vn/Aq/bW754@...h1O3vFw/R8#singeli > that said, tools that can verify numerical results over a > large input space are useful.. if we know what was verified. This is just generally what SMT does well; Bitwuzla in particular, especially at float stuff, in my experience, is much faster than Z3 & CVC5. My tool is just a dumb mapping of code in the single configurable-enough programming language I know of, to SMT. The SMT task done here is to try to find a configuration of argument bit patterns for which there exists a result bit pattern that the custom impl (tgt_musl) can produce, which SMT-LIB's native FMA op (or custom NaN bit patterns as per NaN propagation rules, if applicable) cannot. i.e. if the code is a refinement of FMA. The originally-used rounding mode was the regular nearest-ties-to-even. I've now ran it through all 5 rounding modes though, which all passed. There's no attempt at any verification of float exception/flag values, in case that's an aspect that matters; SMT-LIB doesn't come with any ops for it, and I don't trust myself on implementing them correctly myself (not that I would even care to for my purposes). anyway, that's enough rambling about my little tool that I only really wanted to sanity-check a new algorithm with :) (I hope this email gets to roughly the correct place, I don't do emails)
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.