C++ Logo

std-proposals

Advanced search

Re: [std-proposals] 回复: 回复: Proposal: Integer division/remainder/division-remainder functions with exception throwing behavior

From: Thiago Macieira <thiago_at_[hidden]>
Date: Wed, 30 Apr 2025 13:06:38 -0700
On Wednesday, 30 April 2025 10:49:46 Pacific Daylight Time None via Std-
Proposals wrote:
> 2. About implementation efficiency:
> The proposed solution leverages CPU's native division-by-zero exception
> mechanism, which is fundamentally different from manual checking:
> No branch instructions in the main execution path.
> Zero runtime overhead for the non-zero case (>99.9% scenarios).
> Exception handling path is completely out of line.
> Modern CPUs have dedicated hardware for exception handling.

You clearly did not try to prototype this. See my other email for details on
how this could be implemented, but this one is also wrong: you do have a
runtime overhead for the non-zero case too, to enable and disable the div-by-
zero catcher.

You're also confusing hardware exceptions with C++ exceptions. The only thing
common about them is that they use "exceptions" in the name. A hardware
exception isn't delivered to the application, it's delivered to the OS, which
then decides how to deliver that to the application. On Unix, that's via Unix
signals (not to be confused with Qt signals); on Windows, that's via a
vectored exception.... which Visual C++ does allow to unwind the stack and run
C++ destructors, but can't be caught with catch() statements (use __except
instead)

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Platform & System Engineering

Received on 2025-04-30 20:06:42