[OT] Bit twiddling homework

Chris Angelico rosuav at gmail.com
Fri Jul 20 12:58:39 EDT 2018


On Sat, Jul 21, 2018 at 2:39 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
> Chris Angelico <rosuav at gmail.com>:
>
>> On Sat, Jul 21, 2018 at 1:14 AM, Grant Edwards
>> <grant.b.edwards at gmail.com> wrote:
>>> I refuse to believe there's an extant processor in common use where
>>> an ADD is faster than an OR unless somebody shows me the processor
>>> spec sheet.
>>
>> "Faster than"? I'd agree with you. But "as fast as"? I believe that's
>> how most modern CPUs already operate. (Well, mostly.) There are
>> sophisticated methods of daisy-chaining the carry bit that mean the
>> overall addition can be performed remarkably quickly, and the end
>> result is a one-clock ADD operation, same as OR. For most data, most
>> code, and most situations, integer addition is exactly as fast as
>> integer bit shift.
>
> I'm guessing the clock speed is adjusted for the longest propagation
> delays. According to
>
>    <URL: https://en.wikipedia.org/wiki/Carry-lookahead_adder#Implementa
>    tion_details>
>
> the maximal gate delay of a 16-bit carry-lookahead-adder is 8 gate
> delays. A 64-bit addition results in some more delay:
>
>    <URL: https://en.wikipedia.org/wiki/Lookahead_carry_unit#64-bit_adder>

Right; and since "one clock" is sufficient to propagate through all
the gates of a 64-bit snake (err, I mean adder), and since "one clock"
is also the shortest time from one instruction to the next, the
bitwise operation and the arithmetic operation will generally take the
same amount of time. Generally.

ChrisA


More information about the Python-list mailing list