-1

Which kind of calculation: +, -, *, / is fastest on an intel X86 cpu? Somebody told me / is the fastest, but he didn't tell me why. I have no idea. Can it be proven?

michaelmichael
  • 13,755
  • 7
  • 54
  • 60
cherri_zj
  • 109
  • 1
  • 2
  • 7
  • Maybe he's dividing by 1 in his tests. – fouronnes Mar 06 '11 at 15:57
  • 3
    Yeah, with an optimizing compiler, LOL. – Vamana Mar 06 '11 at 16:14
  • 1
    Modern compilers will optimize division by a constant into a multiplication. (Yes, it's possible to do that. The math is fairly tricky.) – Dietrich Epp Dec 11 '11 at 05:04
  • division is the most complex of all and would be the slowest in all architectures – phuclv Nov 20 '14 at 16:44
  • [Why is division more expensive than multiplication?](http://stackoverflow.com/questions/15745819/why-is-division-more-expensive-than-multiplication), [Why is division so much more complex than other arithmetic operations?](http://scicomp.stackexchange.com/questions/187/why-is-division-so-much-more-complex-than-other-arithmetic-operations) – phuclv Nov 20 '14 at 17:13

3 Answers3

14

For integer operations on most chips, generally addition/subtraction are fastest, followed by multiplication, with division coming in last. I don't have a link handy but it's pretty common knowledge.

Vamana
  • 580
  • 2
  • 7
  • For x86, this may be true if you're talking about latency. But in terms of throughput, there's probably precious little difference. – Oliver Charlesworth Mar 06 '11 at 15:55
  • @Oli Charlesworth: Oh, you mean because it's superscalar? Good point. But if you were doing a whole lot of them one after the other, that would matter, right? – Vamana Mar 06 '11 at 16:17
  • @OliCharlesworth: See http://gmplib.org/~tege/x86-timing.pdf; compared to addition, multiplication has 3x latency and 1/3x throughput on most modern "big" processors (i.e., not Atom/Via/Pentium4). Division is 20-140 times slower than addition. – Dietrich Epp Dec 11 '11 at 04:59
2

You can refer to the table of this link http://www.tantalon.com/pete/cppopt/appendix.htm#AppendixB_RelativeCosts

I think it is similar to x86 cpu (32-bit). As the table, '/' is the slowest.

Paul R
  • 208,748
  • 37
  • 389
  • 560
Thuy
  • 994
  • 8
  • 16
-8

All mentioned will be fastest i guess supposed to be. Because these are the common operations in any cpu, so obviously Intel would have tried their best way to keep up the performance with all these operation. So according to my point all these operation will be fast as it should be(that is how they are prepared by the intel)

Ant's
  • 13,545
  • 27
  • 98
  • 148