3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-08-04 02:10:24 +00:00
yosys/kernel
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
..
binding.cc Generate an RTLIL representation of bind constructs 2021-08-13 17:11:35 -06:00
binding.h Generate an RTLIL representation of bind constructs 2021-08-13 17:11:35 -06:00
bitpattern.h mark all hash_into methods nodiscard 2025-01-14 12:39:15 +01:00
calc.cc Reduce comparisons of size_t and int 2024-11-29 12:53:29 +13:00
cellaigs.cc hashlib: hash_eat -> hash_into 2024-12-18 15:09:25 +01:00
cellaigs.h mark all hash_into methods nodiscard 2025-01-14 12:39:15 +01:00
celledges.cc celledges: use capped shift width 2025-04-26 18:34:21 +02:00
celledges.h Fixing old e-mail addresses and deadnames 2021-06-08 00:39:36 +02:00
celltypes.h Update codebase for macc_v2 2025-01-24 12:38:03 +01:00
compute_graph.h convert class FunctionalIR to a namespace Functional, rename functionalir.h to functional.h, rename functional.h to compute_graph.h 2024-08-21 11:04:08 +01:00
consteval.h macc: Rename 'ports' to 'terms' throughout codebase 2025-03-18 13:25:10 +01:00
constids.inc Merge pull request #5141 from garytwong/unique-if 2025-05-27 09:45:50 +12:00
cost.cc cost: Add $mem_v2, $macc_v2 estimates 2025-03-18 13:51:09 +01:00
cost.h cost: add model for techmapped cell count, keep_hierarchy pass with -min_cost parameter 2024-07-29 10:26:02 +02:00
driver.cc driver.cc: Don't split options on commas 2025-06-13 10:31:53 +12:00
drivertools.cc rtlil: represent Const strings as std::string 2024-10-14 06:28:12 +02:00
drivertools.h mark all hash_into methods nodiscard 2025-01-14 12:39:15 +01:00
ff.cc rtlil: represent Const strings as std::string 2024-10-14 06:28:12 +02:00
ff.h ff: improve comments 2024-09-05 11:17:12 +02:00
ffinit.h rtlil: represent Const strings as std::string 2024-10-14 06:28:12 +02:00
ffmerge.cc rtlil: represent Const strings as std::string 2024-10-14 06:28:12 +02:00
ffmerge.h Add new helper class for merging FFs into cells, use for memory_dff. 2021-05-23 14:46:59 +02:00
fmt.cc Merge pull request #4567 from kivikakk/cxxrtl-escape-trailing 2025-03-14 16:52:07 +13:00
fmt.h fmt,cxxrtl: add option to group digits in numbers. 2024-04-02 12:13:22 +02:00
fstdata.cc fstdata.cc: Fix last step 2025-05-12 13:18:19 +12:00
fstdata.h sim.cc: Move cycle check 2025-05-12 12:48:01 +12:00
functional.cc functional, glift: use fold overload of IdString::in instead of pool literals 2024-11-06 12:48:32 +01:00
functional.h mark all hash_into methods nodiscard 2025-01-14 12:39:15 +01:00
gzip.cc Allow reading of gzipped files when not in NDEBUG 2025-05-21 15:18:29 -07:00
gzip.h gzip: back to pointers 2025-03-19 13:43:44 +01:00
hashlib.h Add <optional> to haslib.h which uses std::optional 2025-05-06 09:57:03 -07:00
io.cc Replace stringf() with a templated function which does compile-time format string checking. 2025-07-29 05:29:33 +00:00
io.h Replace stringf() with a templated function which does compile-time format string checking. 2025-07-29 05:29:33 +00:00
json.cc Support for BTOR witness to Yosys witness conversion 2023-01-11 18:07:16 +01:00
json.h Revert "Add groups to command reference" 2025-07-23 14:41:49 +00:00
log.cc log: deduplicate unescape_id from log_id 2025-07-09 16:20:27 +02:00
log.h Revert "Change the implementation of log_debug in kernel/log.h from a macro function to a normal function." 2025-06-06 15:14:40 +02:00
macc.h macc: Rename 'ports' to 'terms' throughout codebase 2025-03-18 13:25:10 +01:00
mem.cc kernel/mem: Fix Cygwin compat 2024-12-03 13:15:33 +13:00
mem.h rtlil: represent Const strings as std::string 2024-10-14 06:28:12 +02:00
modtools.h mark all hash_into methods nodiscard 2025-01-14 12:39:15 +01:00
qcsat.cc Add coarse-grain $buf buffer cell type 2024-09-17 10:46:20 +02:00
qcsat.h Refactor common parts of SAT-using optimizations into a helper. 2021-08-09 16:54:35 +02:00
register.cc Revert "Add groups to command reference" 2025-07-23 14:41:49 +00:00
register.h Revert "Add groups to command reference" 2025-07-23 14:41:49 +00:00
rtlil.cc kernel: treat zero width constant as zero 2025-07-08 19:37:59 +01:00
rtlil.h Merge pull request #5101 from georgerennie/george/opt_expr_shift_ovfl 2025-05-22 15:16:19 +01:00
satgen.cc Merge pull request #5025 from povik/fix-macc_v2-satgen 2025-04-22 08:55:28 +12:00
satgen.h Fix space leak in SatGen::importSigSpecWorker() by avoiding log_id(). 2025-07-08 23:53:38 +00:00
scopeinfo.cc Add scopeinfo index/lookup utils 2024-02-06 18:01:26 +01:00
scopeinfo.h fix bugs in handling last id in hdlname to scopename conversion 2025-01-16 12:57:08 +01:00
sexpr.cc factor out SExpr/SExprWriter classes out of smtlib backend, and also tidy them up/document them 2024-08-21 11:03:27 +01:00
sexpr.h factor out SExpr/SExprWriter classes out of smtlib backend, and also tidy them up/document them 2024-08-21 11:03:27 +01:00
sigtools.h mark all hash_into methods nodiscard 2025-01-14 12:39:15 +01:00
tclapi.cc Reinstate #4768 2025-04-08 11:58:05 +12:00
timinginfo.h mark all hash_into methods nodiscard 2025-01-14 12:39:15 +01:00
topo_scc.h functional backend: topological sort starts with the output and next states nodes, other nodes get deleted 2024-08-21 11:03:29 +01:00
utils.h io: refactor string and file work into new unit 2025-03-19 13:43:42 +01:00
yosys.cc Allows calling yosys_shutdown and then yosys_setup to restart. 2025-06-07 22:21:09 +08:00
yosys.h driver: allow --no-version still write things like Generated by Yosys 2025-05-07 11:34:23 +02:00
yosys_common.h Replace stringf() with a templated function which does compile-time format string checking. 2025-07-29 05:29:33 +00:00
yw.cc rtlil: represent Const strings as std::string 2024-10-14 06:28:12 +02:00
yw.h mark all hash_into methods nodiscard 2025-01-14 12:39:15 +01:00