Optimization with Goto's?
I was talking with some friends of mine, and for some strange reason we started talking about goto statements. Then it came to me that a goto statement could possibly be used as an optimization. Now I don''t think people should use them, since they''re evil to debug and the code gets unreadable, but a theoretical discussion on the subject would be nice.
I''m assuming that when you have a goto statement, the label gets converted by the compiler to a asm label, and the goto gets converted to a jmp.
Now, do other branchning techniques use more asm calls, or is nothing gained by using a goto?
A goto blows up the cache, I don''t think that it can be of much use for speeding up code
Tim
--------------------------
glvelocity.gamedev.net
www.gamedev.net/hosted/glvelocity
Tim
--------------------------
glvelocity.gamedev.net
www.gamedev.net/hosted/glvelocity
Tim--------------------------glvelocity.gamedev.netwww.gamedev.net/hosted/glvelocity
I do recall seeing some crypto algorithms that use goto''s but there are generally better solutions. Optimizing compilers don''t like goto''s much. I haven''t found a situation yet where I''d reccommend using them.
What does gotos do to ''blow up'' the cache?
Snyper
Snyper
=============================Where's the 'any' key?=============================
If you seriously have a problem with gotos then you are wrong. I don''t use them because it is more elegant code without them, and debugging becomes a nightmare with them... But they still have their uses. I think Knuth has a doc on it (Someone does, but I cannot remember who). The doc explains all the right reasons to use gotos. Gotos can speed up your code, but I would not use them until I consider myself adept and probably ''advanced'' programmer. I don''t think that I will ever use them though.
Just because they are bad style (throw structured programming right out the window) doesn''t mean that they are not useful or do not increase speed. Just my $(2*rant/100)
-Chris Bennett ("Insanity" of Dwarfsoft)
Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet :)
Just because they are bad style (throw structured programming right out the window) doesn''t mean that they are not useful or do not increase speed. Just my $(2*rant/100)
-Chris Bennett ("Insanity" of Dwarfsoft)
Check our site:
http://www.crosswinds.net/~dwarfsoft/
Check out our NPC AI Mailing List :
http://www.egroups.com/group/NPCAI/
made due to popular demand here at GDNet :)
quote: Original post by Ataru
Now, do other branchning techniques use more asm calls, or is nothing gained by using a goto?
In the end, ALL is converted to asm, is converted to machine code. An "if" is converted into one or more conditional jumps (jc, jz, jns, ...)
quote: Original post by tcs
A goto blows up the cache, ...
? With all respect tcs, I think you''re wrong this time...
Um, goto''s are the spawn of satan. The only reason it was kept in C, is to try to get the {Fortan, ASM, etc.} coders to use C, then teach em that they are wrong and show them how to code the right way.
-----------------------------
A wise man once said "A person with half a clue is more dangerous than a person with or without one."
-----------------------------
A wise man once said "A person with half a clue is more dangerous than a person with or without one."
-----------------------------A wise man once said "A person with half a clue is more dangerous than a person with or without one."The Micro$haft BSOD T-Shirt
Heh, "goto" may be the spawn of Satan, but if you''re talking optimization of short routines, anything goes. You don''t optimize for elegance--you do it for speed. Now, I''ve never tried optimizing with goto before, probably because the idea never occurred to me (it''s been a loooooong time since BASIC)... but, provided that it does speed up the code, it can''t look any better than some of the routines I''ve seen (converting known integers into bit-shifting powers of two, killing multiplications and indices, etc.).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement