gcov: Split atomic bitwise-or for 64-bit counters on targets with 32-bit atomics
gcc: Gcov updates 64-bit atomic bitwise-or for condition/decision coverage on targets with only 32-bit atomics.
For targets that only support 32-bit atomic operations, such as 32-bit RISC-V, the 64-bit atomic bitwise-or operation for updating gcov counters is now split into two 32-bit operations. This change optimizes counter updates by avoiding calls to libatomic and folding away compile-time zero halves, while maintaining the existing behavior for targets with 64-bit atomic instructions.
In Details
Gcov's decision coverage instrumentation now handles targets with only 32-bit atomic primitives by splitting the 64-bit atomic bitwise-or operation into two 32-bit operations. The new split_update_decision_counter function in tree-profile.cc determines availability of 64-bit atomics and conditionally splits the operation. This optimization avoids libatomic calls for targets like rv32ima, folding zero high-order bits at compile time.
- gcov
- A code coverage tool used with GCC. It measures which lines of C, C++, Objective-C, Fortran, and Ada code are executed by a program.
- atomic operation
- An operation that is guaranteed to execute indivisibly. In the context of gcov, atomic operations are used to update coverage counters safely in multi-threaded environments.
- bitwise-or
- A binary operation that compares each bit of its two operands. If both bits are 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0.
- condition coverage
- A type of code coverage that tracks the number of times each boolean subexpression within a conditional statement evaluates to true or false.
- decision coverage
- A type of code coverage that tracks whether each possible outcome of a control flow statement (e.g., if, while) has been executed.
- RISC-V
- An open-standard instruction set architecture (ISA) based on reduced instruction set computer (RISC) principles, known for its modularity and extensibility.
- libatomic
- A GCC library that provides implementations of atomic memory access operations, often used when hardware-level atomic instructions are not available or are not directly supported by the compiler.