[resolved][puzzle] High five
kuroneko
Posts: 3,623
We all know that multiplying by certain small integers is done faster with dedicated code, e.g. multiply by 5 boils down to:
mov temp, value ' temp := value shl temp, #2 ' temp := value * 4 add temp, value ' temp := value * 4 + valueFor no other reason than to show that it can be done do the same thing with two instructions (8 cycles). As a template use this:
rdlong value, par ' read operand [COLOR="red"]???[/COLOR] ' 1st user instruction [COLOR="red"]???[/COLOR] ' 2nd user instruction
- Whatever setup you require should be done before rdlong, this excludes sneak preview(s) by accessing par!
- Input value and result can be stored in any register you like.
- For the sake of argument, this code is only called once.
Comments
@MagIO: I think I get it now, must be Monday.
A It's not that I was looking for it, I wanted something else entirely.
But I'm not sure wheather one instruction of the setup has to be counted as being part of the multiplication, as you always have to do it before. Would be interesting to see up to which number this way would be faster than a general purpose solution.
Counter accumulates 4 times per instruction so I'm guessing this should work but not sure.
-Phil
@Phil, IIRC I mentioned 8 cycles
So now the value is made negative in value, then PHSA which should now have 6 times the original value is added to the negative of one times the value.
Ingenious, so there's no buffering on the frqa register and write is last in the 4 instruction cycle. Very elegant.