You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[MooreToCore][Sim] Added support for moore.fmt.real (#9397)
Since LLVM doesn't have a very clean separation between printing out
floats in FP vs Scientific Notation (see `toStringImpl` [here]
(https://llvm.org/doxygen/APFloat_8cpp_source.html)), I decided to do
what Verilator does here: call [`snprintf`](https://github.com/sifive/verilator/blob/master/include/verilated.cpp#L837).
So for now, we're doing C-style prints - I plan to make a patch to LLVM
to disambiguate `toStringImpl` for FP notation, but that's for later.
Overview: 1. By default, the precision for floating point numbers is 6
for `%f` and `%e` 2. `$fieldWidth` is used to determine padding, and
`$fracDigits` is used to denote the number of digits after the decimal
point/the alphabet 'e' - the actual formatting is handled by `snprintf`
under the hood 3. `%g` has a unique formatting logic:
For `exp ≥ 0`: Uses decimal notation if `exp + 1 ≤ max(1, fracDigits)`,
otherwise switches to scientific notation with `max(0, fracDigits - 1)`
fractional digits.
For `exp < 0`: If `exp ≥ -4`: Uses decimal notation with `max(b - 1,
0) + |exp|` fractional digits If `exp < -4`: Uses scientific notation
with `max(b - 1, 0)` fractional digits Everything is stripped of
trailing zeroes after the decimal point/the alphabet 'e', which, as
expected, is in conjunction with [this](https://en.cppreference.com/w/cpp/io/c/printf.html#Notes)
I've introduced this patch to fix the current `fmt.real` legalization
errors and improve test coverage. I think it is beneficial to merge
this even if we remove the formatting folders later, since this might
serve as reference code for the arcilator runtime (#7692).
0 commit comments