No other code, just Variable declaration and END,for a F877:
For BYTE variable:
For WORD variable:Code:x=x*25 '40 bytes x=x<<4+x<<3+x '43 bytes
IoannisCode:x=x*25 '43 bytes x=x<<4+x<<3+x '49 bytes x=x<<25 '27 bytes!!!
No other code, just Variable declaration and END,for a F877:
For BYTE variable:
For WORD variable:Code:x=x*25 '40 bytes x=x<<4+x<<3+x '43 bytes
IoannisCode:x=x*25 '43 bytes x=x<<4+x<<3+x '49 bytes x=x<<25 '27 bytes!!!
whats the point of the last one? shift a word variable 25 times either way and you will just get 0.
i was multiplying a word var and saving into a long var
"I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams
I know 25 shift will not give the result you want.
Just tested to see how much less program space and how faster a shift will be. Useless for you but quite impressive!
Which PIC are you using? Is there any chance to use one with hardware multiplier?
Ioannis
To me, the time it takes to execute is more important than the size of the code.
And the fastest way will usually <strike>be the smallest too</strike> not be the smallest.
On a 16F @ 4Mhz with WORD variables ...
<table cellpadding=6 border=1><tr><td align=center>Formula</td><td align=center>Execution Time</td><td align=center>Words per<br>Instance</td><td align=center>Words added<br>to Library</td></tr><tr><td>x = x*25</td><td align=center>230 - 250uS<br>depends on X value</td><td align=center>12</td><td align=center>27</td></tr><tr><td>x = x<<4 + x<<3 + x</td><td align=center>110uS</td><td align=center>34</td><td align=center>13</td></tr><tr><td> T = X << 1
T = T << 1
T = T << 1
X = T << 1 + T + X </td><td align=center>31uS</td></td><td align=center>30</td><td align=center>13<br>adds SHIFTL to library<br>but doesn't use it.</td></tr></table>
I wonder if ASM will help![]()
Last edited by Darrel Taylor; - 8th April 2010 at 01:31. Reason: Updated table with code size
DT
Nice work DT.
It's amusing that doing a single shift twice takes less time than a double shift.
I have run into a problem though. Does anyone know why this gives me an incorrect result?
T is 64800 (as expected), but Y is 2516719364 ?!Code:X VAR WORD T VAR LONG Y VAR LONG X=8100 T = X << 1 T = T << 1 T = T << 1 Y = T << 1 + T + X LCDOUT $FE,$80,"T=",DEC T LCDOUT $FE,$C0,"Y=",DEC Y
I'm guessing that its something about long variables that I am missing.
"I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams
Nice find Kamikaze!
There's a small bug in the pbppi18l.mac file.
The SHIFTL?NCN macro should be changed as follows. (3's in red)
I'll let the guys know.Code:SHIFTL?NCN macro Nin, Cin, Nout if ((Cin) == 1) bcf STATUS, C if ((Nout) == (Nin)) CHK?RP Nout rlcf Nout, F rlcf (Nout) + 1, F rlcf (Nout) + 2, F rlcf (Nout) + 3, F else CHK?RP Nin rlcf Nin, W MOVE?AB Nout CHK?RP Nin rlcf (Nin) + 1, W MOVE?AB (Nout) + 1 CHK?RP Nin rlcf (Nin) + 2, W MOVE?AB (Nout) + 2 CHK?RP Nin rlcf (Nin) + 3, W ; was 2 MOVE?AB (Nout) + 3 endif else MOVE?NN Nin, R0 movlw Cin L?CALL SHIFTL MOVE?ANN R0, Nout endif endm SHIFTL_USED = 1 endmod
<br>
DT
Yep, that fixed it. Thanks DT.
I'm surprised that the bug hasn't been found before now.
Out of curiosity, why did it only affect the shift on the last line, and not the first three?
Code:T = X << 1 T = T << 1 T = T << 1 Y = T << 1 + T + X
"I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams
Bookmarks