Thread: One line power
View Single Post
  #9   Spotlight this post!  
Unread 06-03-2002, 17:18
K-RAD K-RAD is offline
Registered User
#0116 (Epsilon Delta)
 
Join Date: Feb 2002
Location: Herndon, VA
Posts: 3
K-RAD is an unknown quantity at this point
Send a message via AIM to K-RAD Send a message via Yahoo to K-RAD
Exclamation

Although one liners are nice, they're not necessarily faster. Multiplication instructions are always SLOW. Once you get to the point where the lines of code are that horribly long (and having non-bitwise operators), I'd question the speed/code size improvements, if any.

In response to the comment about eliminating 'if' statements for speed: you're right and wrong. With today's modern processors you generally want to avoid using 'if' statements as much as possible due to branch prediction. However, I don't believe the simple processor on the BASIC STAMP implements pipelining. You'd probably be taking more cycles, and probably more memory as well, by doing all of that math than if you simply used 'if' statements.

My favorite line from my optimized code is:
Dr_Motor3 = (40 << (~(basket_lift | basket_lower)) << 2) | (15 >> (~(basket_lift) << 2))
It effectively eliminated a 4 condition branch statement ;-)

PBASIC was so horrible that I *wanted* to program in assembly.
__________________
MTV is my source for new and original music