The use case for *ForKeeps in this post is interesting, which I initially didn’t realize. @physicboy posted his EMI receiver project here, where the C code doesn’t rely on Trunc():
[Share and looking for feedback] CISPR16 EMI receiver emulation - QSPICE - Qorvo Tech Forum
Since other DLLs or devices can trigger hypothetical calls, and this EMI receiver requires heavy computation, @physicboy noted that executing this code during a hypothetical call increases simulation time. Therefore, he used if(*ForKeeps == 0) return; to skip the execution of this code during hypothetical calls.
In general, we don’t do that because if the code is part of the circuit, skipping it entirely during a hypothetical call will alter the circuit simulation results in hypothetical call and mess up the timestep estimation (I guess it will…
). However, because this EMI receiver just receives signal, skipping the code won’t mess up the hypothetical state.
Since this situation is less common, that is why I didn’t initially understand the need for it. But it is a very interesting idea to speed up simulations by not wasting time on hypothetical calls if:
- The code will not alter the circuit’s behavior
- The code computation is heavy (I guess you simulation time difference is negligible for simple code)
I think the most common use case for *ForKeeps is to help identify when a transient simulation step truly begins, or to skip writing to an external file by identifying that the call is not in a hypothetical state. In these cases, the goal is not to skip the entire code block.