[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 + value
For 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.
rdlong value4, par ' [b]doing whatever setup required :)[/b] rdlong value, par shl value4, #2 add value, value4But 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.
mov sum,#0 mov count,multiplier rdlong value,par :loop add sum,value djnz count,#:loop-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.
movi ctra, #%0_11111_000 rdlong phsa, par mov frqa, phsa mov frqa, #0mov dira, #%11 mov outa, #%01 ' 5:%01, 3:%10 movd ctra, #1 ' B (A == 0) movi ctra, #%0_01010_000 ' POSEDGE rdlong frqa, par movi ctra, #%0_11110_000 ' LOGIC A|B movi ctra, #%0_01010_000 ' POSEDGEIngenious, so there's no buffering on the frqa register and write is last in the 4 instruction cycle. Very elegant.