Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Bitshifts and "And" vs Floor-division and Modular

Reply
Thread Tools

Bitshifts and "And" vs Floor-division and Modular

 
 
Paul Rubin
Guest
Posts: n/a
 
      09-07-2012
rusi <(E-Mail Removed)> writes:
> On an 8086/8088 a MUL (multiply) instruction was of the order of 100
> clocks ... On most modern processors (after the pentium) the
> difference has mostly vanished. I cant find a good data sheet to
> quote though


See http://www.agner.org/optimize/ :

4. Instruction tables: Lists of instruction latencies, throughputs
and micro-operation breakdowns for Intel, AMD and VIA CPUs

Multiplication is now fast but DIV is still generally much slower.
There are ways to make fast parallel dividers that I think nobody
bothers with, because of chip area and because one can often optimize
division out of algorithms, replacing most of it with multiplication.

Worrying about this sort of micro-optimization in CPython is almost
always misplaced, since the interpreter overhead generally swamps any
slowness of the machine arithmetic.
 
Reply With Quote
 
 
 
 
Grant Edwards
Guest
Posts: n/a
 
      09-07-2012
On 2012-09-07, Steven D'Aprano <(E-Mail Removed)> wrote:

> My *guess* is that you mean *bitwise* operators, compared to numeric
> operators like * and // (integer division). The runtime cost is mostly
> dominated by the object-oriented overhead -- Python is not C or assembly,
> and the integers are rich objects, not low-level bitfields, so the
> difference between division and bitshifting is much less than you might
> expect from assembly language.


I don't suppose there's much of a chance that the OP is running Python
on a CPU that doesn't have an integer divide instruction? If that
_were_ the case, the difference would be more noticable, but would
still probably not worth worrying about unless a truely huge number of
operations were being done in a very tight loop with no intervening
I/O operations.

--
Grant Edwards grant.b.edwards Yow! I have accepted
at Provolone into my life!
gmail.com
 
Reply With Quote
 
 
 
 
rusi
Guest
Posts: n/a
 
      09-07-2012
On Sep 7, 9:32*am, Paul Rubin <(E-Mail Removed)> wrote:
> rusi <(E-Mail Removed)> writes:
> > On an 8086/8088 a MUL (multiply) instruction was of the order of 100
> > clocks ... *On most modern processors (after the pentium) the
> > difference has mostly vanished. *I cant find a good data sheet to
> > quote though

>
> See http://www.agner.org/optimize/:


Hey Thanks! Seems like a nice resource! How on earth does he come up
with the data though, when Intel does not publish it?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Bitshifts and "And" vs Floor-division and Modular Cameron Simpson Python 0 09-07-2012 01:08 AM
Supply Telephone Voice Modular Adapters,Telephone Modular Couplers,Modular Duplex Jack,Triplex Adapters,Telephone extension Cord samul888@vip.163.com Cisco 1 11-13-2005 09:23 AM
Supply Telephone Voice Modular Adapters,Telephone Modular Couplers,Modular Duplex Jack,Triplex Adapters,Telephone extension Cord samul888@vip.163.com Computer Support 0 11-12-2005 06:22 AM
Supply Telephone Voice Modular Adapters,Telephone Modular Couplers,Modular Duplex Jack,Triplex Adapters,Telephone extension Cord samul888@vip.163.com VOIP 0 11-12-2005 06:22 AM



Advertisments