OPTIMIZATION
(C) Demon / LGN
OPTIMIZE!
Greed fraera
ruin.
Folk wisdom.
> D: (D - a DEMON) Recently, I realized that the word
"Optimization" can hide not only benefit ... This article
is a response to a letter published in the ZX-Review 97/1-2
(p.47), written certain AmiS. Tell him the word.
> A: (A - a AmiS) Many have already written about
that it is time to put an end to raw and untested procedures.
> D: Oh! Unlike you people think!
> A: They themselves do in their papers are not valid from my
point of view, the miscalculations. Here are some examples.
Our task: to write the shortest procedure for cleaning the
screen.
> D: And who is it staged?
> A: Many beginners do things like:
LD HL, # 4000
LD DE, # 4001
LD BC, # 1AFF
LD (HL), L
LDIR
After sitting for some time can be reduced by this
procedure:
LD HL, # 5B00
DEC HL
XOR A
LD (HL), A
OR H
JR NZ, $ -6
> D: I apologize that this nonsense stopped, but
I want to stand up for these most "beginners". If AmiS more for
everything and could be considered, then the prices would be he
was not. First program occupies 12 bytes and works
145,184 cycles. The procedure is a genius - 9 bytes
(Ur-r-r-a!! He won 3 bytes), but the time
performance ... 944,686 cycles ... Tidy
Tsiferki ... True, this work of genius
delirium will speed MORTAL KOMBAT on
ES1841 (namely, 6.5 times slower ...).
It is worth to think about the sense of this optimization. But
AmiS'u achieved little and it does not ceases to surprise us ...
> A: Look at this example. He
Born in a few hours of persistent assault.
> D: Even BAYSYAK (who writes on
BASIC'e) could not slow down much.
> A: But now you can safely use
this idea in their programs:
Challenge: "turn" byte (ie, exchange
Bits 0-7, 1-6, 2-5, 3-4). Was 76543210
(% 01100001), was 01,234,567 (% 1,000,110)
LD A, # 80
ADD HL, HL
RRA
JR NC, $ -2
LD H, A
Bytes arrives at H, it is and leaves.
> D: First give the procedure that I (and not just me!):
RR n
RLA
RR n
RLA
RR n
RLA
RR n
RLA
RR n
RLA
RR n
RLA
RR n
RLA
RR n
RLA
LD n, A, where n - any register
Procedure AmiS'a: takes 7 bytes, running 134 cycles.
Limitations: Input B only H.
The second procedure: occupies 25 bytes,
running 100 cycles. Restrictions: None.
In size the author has saved 18 bytes, but
in the rate of losing 34 cycles.
If I have anyone not yet convinced of the correctness of my
words, then let them turn their eyes on MEGADEMY and many other
programs that "well, oh-oh-oh-a" cool effects. In them, no one
saves memory, as care about how to make it look
beautiful, but it did not take less space (which no one is
never enough).
Also alarming words AmiS'a promised in the next room
ZX-Review present to the "beginners" bend
best coders "perfected." Let's hope that he does not
want to optimize!