3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-08-03 18:00:24 +00:00
yosys/backends
Robert O'Callahan 6ee3cd8ffd Replace stringf() with a templated function which does compile-time format string checking.
Checking only happens at compile time if -std=c++20 (or greater) is enabled. Otherwise
the checking happens at run time.

This requires the format string to be a compile-time constant (when compiling with
C++20), so fix a few places where that isn't true.

The format string behavior is a bit more lenient than C printf. For %d/%u
you can pass any integer type and it will be converted and output without
truncating bits, i.e. any length specifier is ignored and the conversion is
always treated as 'll'. Any truncation needs to be done by casting the argument itself.
For %f/%g you can pass anything that converts to double, including integers.

Performance results with clang 19 -O3 on Linux:
```
hyperfine './yosys -dp "read_rtlil /usr/local/google/home/rocallahan/Downloads/jpeg.synth.il; dump"'
```
C++17 before: Time (mean ± σ):     101.3 ms ±   0.8 ms    [User: 85.6 ms, System: 15.6 ms]
C++17 after:  Time (mean ± σ):      98.4 ms ±   1.2 ms    [User: 82.1 ms, System: 16.1 ms]
C++20 before: Time (mean ± σ):     100.9 ms ±   1.1 ms    [User: 87.0 ms, System: 13.8 ms]
C++20 after:  Time (mean ± σ):      97.8 ms ±   1.4 ms    [User: 83.1 ms, System: 14.7 ms]

The generated code is reasonably efficient. E.g. with clang 19, `stringf()` with a format
with no %% escapes and no other parameters (a weirdly common case) often compiles to a fully
inlined `std::string` construction. In general the format string parsing is often (not always)
compiled away.
2025-07-29 05:29:33 +00:00
..
aiger Merge pull request #5109 from YosysHQ/emil/aiger-map-fix-outputs 2025-06-02 15:07:19 +02:00
aiger2 abc_new: Fix PI confusion in whitebox model export 2024-12-10 14:27:29 +01:00
blif driver: allow --no-version still write things like Generated by Yosys 2025-05-07 11:34:23 +02:00
btor driver: allow --no-version still write things like Generated by Yosys 2025-05-07 11:34:23 +02:00
cxxrtl cxxrtl: Add debug items for state with private names 2025-05-26 16:58:13 +02:00
edif driver: allow --no-version still write things like Generated by Yosys 2025-05-07 11:34:23 +02:00
firrtl write_firrtl: clear used names cache each pass 2025-07-15 14:14:07 +01:00
functional Revert "Add groups to command reference" 2025-07-23 14:41:49 +00:00
intersynth rtlil: represent Const strings as std::string 2024-10-14 06:28:12 +02:00
jny driver: allow --no-version still write things like Generated by Yosys 2025-05-07 11:34:23 +02:00
json driver: allow --no-version still write things like Generated by Yosys 2025-05-07 11:34:23 +02:00
rtlil driver: allow --no-version still write things like Generated by Yosys 2025-05-07 11:34:23 +02:00
simplec rtlil: represent Const strings as std::string 2024-10-14 06:28:12 +02:00
smt2 driver: allow --no-version still write things like Generated by Yosys 2025-05-07 11:34:23 +02:00
smv driver: allow --no-version still write things like Generated by Yosys 2025-05-07 11:34:23 +02:00
spice driver: allow --no-version still write things like Generated by Yosys 2025-05-07 11:34:23 +02:00
table Fixing old e-mail addresses and deadnames 2021-06-08 00:39:36 +02:00
verilog Replace stringf() with a templated function which does compile-time format string checking. 2025-07-29 05:29:33 +00:00