Divisions are Slower, are Ifs slower that Multiplying?

Started by
26 comments, last by Ului 20 years ago
Teh problem is, you could write it in assembly faster than check all necessary switches in compiler, and verify if compiler didn''t do something stupid.
Advertisement
quote:Original post by Raghar Wasn''t that link about Java Micro edition? Basically handhelds and mobile phones.

Yes, and notice how the first guideline was still "only optimize if you need to."

quote:
Yes there are a lot of nice reasons for it. You need talk to the hardware directly (And don''t like the idea of a buggy template). You need to do something with the CPU. You need to create a very nice library that would work on PII. You need to call system services. BTW macro assembly is nicer than C++, so there are situations where it''s usefull.

Sorry, I disagree. Yes, assembly has its place. That place is 1) if you need hardware access that the programming language doesn''t supply, or 2) for optimization after you''ve profiled, or 3) you are writing a high performance library(we''re talking something that doom3/hl2 might use) and you can reasonably predict bottlenecks because you have a lot of experience.

quote:
BTW when you are writing something in the assembly, you create documentation as well, and you are trying to have that code well structured.

You do this in high level languages as well. Code tends to be better documented and better structured in high level languages than in asm.

quote:
(On other hand Java or C# code could be mess becose programmers have no need to be carefull. C++ is mess nearly always.)

Given any coder who knows both java/c#/c++ and asm, I assert that the java/c#/c++ code will almost always be less messy than
the assembly. Assembly does not allow you to make meaningful abstractions.

To the OP: unless you have a really valid reason for it(like you''re writing OS routines, or microcontroller code), you''re probably better off concentrating on c++ and forgetting about asm.
quote:Original post by Raghar
Teh problem is, you could write it in assembly faster than check all necessary switches in compiler, and verify if compiler didn''t do something stupid.


you''re joking, right?
Although I write most of my code in HLLs, knowing Assembly helped me a lot in understanding of what goes on in the "background".

Even if a programmer never uses it, I think he should at least be able to READ assembly code.

Just had to add my 2 cents


Indeterminatus

--si tacuisses, philosophus mansisses--
Indeterminatus--si tacuisses, philosophus mansisses--
Just answer the topic, hope that still help:

http://packetstormsecurity.nl/programming-tutorials/Assembly/fpuopcode.html

!o)
!o)
The speed of machine language instructions on a CPU like the x86 is a meaningless concept. Instructions are converted into streams of microinstructions, and the performance can vary based on too many factors to consider. Even a "slow" instruction like division or square-root isn''t really slow if the scheduler keeps getting other work done in the background.

If you want to do this kind of hardcore assembly, you should write for the Game Boy Advance or another smaller system.
quote:Original post by sjelkjd
quote:Original post by Raghar
Teh problem is, you could write it in assembly faster than check all necessary switches in compiler, and verify if compiler didn''t do something stupid.


you''re joking, right?


No, why? ~_^ Over 2 hours/30 min.

Raghar
quote:Original post by Anonymous Poster
The speed of machine language instructions on a CPU like the x86 is a meaningless concept. Instructions are converted into streams of microinstructions, and the performance can vary based on too many factors to consider. Even a "slow" instruction like division or square-root isn''t really slow if the scheduler keeps getting other work done in the background.

There''s also pipelining that allows executing a large list of expensive instructions essentially in one tick (minus the initial delay).

This topic is closed to new replies.

Advertisement