-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option for unchecked divison methods #9
Comments
As suggested in #7 (comment), we would be able to explicitly use Fixed-point numbers have characteristics intermediate between integers and floating-point numbers, i.e. they can easily overflow as well as divide-by-zero. So, there can be more disagreement as to whether the default division should be checked. In other words, we have at least the possibility of drawing boundaries in terms of two aspects: operation (operator) and type.
|
Might be easiest for users for the default to emulate how Julia treats its integer types. That way they don't have to think about the peculiarities of which possibly-overflowing number type is being used. Should we consider Maybe the API could be something like this? Since it can potentially crash Julia, marking it as
And then a new |
Personally, I don't think that is necessary.
Do users really want "unsafe"? I believe there is little speed benefit. As noted above, we should be able to use |
I don't know if there are immediate performance differences between the two in normal usage, but the unchecked div is marked no-throw. I assume there are some benefits to being able to compile sections of code guaranteed to never lead to an exception (assuming one is careful about the UB cases). |
So, I think we need a guard for UB in the "unchecked" context as well. |
Can you say more? Adding a branch would make it slower. I was thinking that if someone really wanted this, they'd be taking the responsibility of that check. |
Tracking what may happen here wrt promotion: JuliaLang/julia#54485 |
I am not opposed to adding an unsafe-specific option like Also, speculative execution is a common technique for speeding up. While it is generally good practice to perform checks first, there might be cases where checks are performed later. |
Fair enough, I'm testing some things out and it doesn't seem like there's much, if any, penalty to doing so...
|
Julia's default integer division is checked. This occurs with division by 0, and
typemin(T) ÷ -one(T)
.LLVM deems either of these cases undefined behavior, which is very very bad because the compiler is allowed to do whatever it wants in that case. Also on Windows it may throw a Win32 exception that crashes Julia.
This is in contrast to +/-/*/^/abs where overflow has a defined result of wrapping around. And for example, C# doesn't stop checking division in an unchecked context. So it makes sense to not automatically follow this.
However, we could consider an option passed to the
unchecked
macros that allows people to opt in to unchecked division.The text was updated successfully, but these errors were encountered: