Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ului

Divisions are Slower, are Ifs slower that Multiplying?

This topic is 5153 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m programming in C++ @ the moment, & in ASM, i read few documents on ASM, but what I would like to know-- Does anyone know of a table or chart that has the operators & their speed. Dun mes wit me!

Share this post


Link to post
Share on other sites
Advertisement
MASM, just inline asm code with c++.

I know that divsions are slower than Multiplications, and muliplications are slower than just addition but then im using shift bitwise operators too, and I don''t know where that fits in, speed wise.

Dun mes wit me!

Share this post


Link to post
Share on other sites
Sweet as.
I assumed it was, and i just searched the net & for sure it is.

http://www.developer.com/java/j2me/print.php/10934_2234631_5

for anyone wanting that optimizing edge, check out bottom links too.

I find it funny when people try finding the average of 4 pixels by adding then dividing it by 4. Shifts r better.

Thanks!


Dun mes wit me!

Share this post


Link to post
Share on other sites
Ului, most compilers will automatically convert an integral division by 4 to a shift. As long as the denominator is a constant, there''s little reason to do it yourself.


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites
Hmm, learn something new every day. But I usually code in asm, so i do it manually.



Dun mes wit me!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
These days its not so much what the instruction speed is (although for SOME slow instructions such as mul or div it matters) but rather what is important is what instructions it can be paired with. On modern processors you can often get two for the price of one when you structure your assembler code properly.

- Rockoon

Share this post


Link to post
Share on other sites
A mul is done in 1 cycle IIRC. It doesn''t pair well, and uses two registers, so if you can do it with a single shift it would be faster. I highly doubt that an addition loop could be faster, I suspect it would be many times slower.

Share this post


Link to post
Share on other sites
On modern CPUs it is never as simple as "this instruction takes n cycles"

Because they tend to try and execute instructions in parallel, instruction order makes a difference as well as the instructions themselves. Also loads can take a lot longer depending on caches etc; branching can change.

I would imagine that an optimising compiler could change a constant divide by 4 into a multiply by 0.25.

Anyway if you are doing some scientific computing where you need to worry about this kind of thing, you really need a different forum.

Consider buying different hardware which is better at the operations you need a lot of (obviously profile your code a lot first)

Mark

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!