[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Why do you want to use“cast_int“ to force “ui” to int
- From: Roberto Ierusalimschy <roberto@...>
- Date: Fri, 20 Jan 2023 14:47:53 -0300
> I found this explanation on this webpage
> https://answerbun.com/stack-overflow/why-is-__int128_t-faster-than-long-long-on-x86-64-gcc/
>
> idiv r64 is 56 uops for the front-end, with latency from 41 to 95
> cycles (from divisor to quotient, which is the relevant case here I
> think).
> div r64 is 33 uops for the front-end, with latency from 35 to 87
> cycles. (for that same latency path).
>
> Probably DIV is faster than iDIV,
> the DIV latency is shorter
Precisely. As the comment there explains: "If integer fits as a
non-negative int, compute an int remainder, which is faster. Otherwise,
use an unsigned-integer remainder, which uses all bits and ensures a
non-negative result."
-- Roberto