Secret Hardware Multiplier
dfletch
Posts: 165
We've been hearing lots about the Propeller2 lately. One of the neat things it has is a hardware multiplier.
But Parallax has been holding out on us! There's a hidden multiplier in your Propeller 1!! It's triggered with the lovely MUL assembly instruction.
This opens us all up to a whole new world of DSP awesomeness!
Sample code that multiplies 8000 by 10000:
Happy multiplying!
Cheers,
--fletch
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Join us in the Un-Official Propeller IRC channel: irc.freenode.net #propeller
Newbies, oldies, programmers, math professors, and everyone in-between welcome!
Propeller IRC howto
spinc - open source Spin compiler
But Parallax has been holding out on us! There's a hidden multiplier in your Propeller 1!! It's triggered with the lovely MUL assembly instruction.
This opens us all up to a whole new world of DSP awesomeness!
Sample code that multiplies 8000 by 10000:
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 VAR LONG a, b OBJ term : "VGA_Text" PUB start | cog a := 8000 b := 10000 term.start(16) term.dec(a) term.str(string(" * ")) term.dec(b) term.str(string(" = ")) cog := cognew(@testmul, @a) waitcnt(cnt + clkfreq) term.dec(b) ' b after multiply cogstop(cog) repeat DAT ORG 0 testmul MOV t1, par ' Appropriate the A parameter RDLONG _a, @t1 ' Provide the data ADD t1, #4 ' Release t1, making it a pointer to B RDLONG _b, @t1 ' Internalize the data MUL _a, _b ' Look here <------ WOW AMAZING! Result in B. WRLONG _b, t1 ' Forward the data back to SPIN. :stop JMP #:stop _a LONG 0 ' Overshadowed A parameter. _b LONG 0 ' Overshadowed B parameter. t1 LONG 0 ' Loaded with parameter addresses. FIT 496 ' Squeeze it all in (HA!)
Happy multiplying!
Cheers,
--fletch
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Join us in the Un-Official Propeller IRC channel: irc.freenode.net #propeller
Newbies, oldies, programmers, math professors, and everyone in-between welcome!
Propeller IRC howto
spinc - open source Spin compiler
Comments
How did you find it?
OK - assuming this find isn't date related (1/4/2008)- its on page 419 as a reserved PASM word, and the IDE picks it up - but no documentation seems to be in the manual...... (not checked the errata!)
But it doesn't appear to work - 10 x 10 seems to give 10, 80 x 100 gives 163.....
J
Post Edited (Javalin) : 4/1/2008 7:31:39 PM GMT
Cheers,
--fletch
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Join us in the Un-Official Propeller IRC channel: irc.freenode.net #propeller
Newbies, oldies, programmers, math professors, and everyone in-between welcome!
Propeller IRC howto
spinc - open source Spin compiler
That's why it is secret. It's probably this way because it doesn't set the flags (Z & C) correctly, so people wouldn't use it in production code. And also it doesn't seem to work with negative numbers.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Read the first letter of each line of ASM comments :-P
Cheers,
--fletch
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Join us in the Un-Official Propeller IRC channel: irc.freenode.net #propeller
Newbies, oldies, programmers, math professors, and everyone in-between welcome!
Propeller IRC howto
spinc - open source Spin compiler
The value in _b is wrong. The ASM does a RDLONG of the address of the address of VAR B. The value in that HUB RAM happens to be 8000000. So I just picked 2 numbers that multiplied to it and arranged the code so MUL didn't zero the value.
APRIL FOOLS!
Cheers,
--fletch
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Join us in the Un-Official Propeller IRC channel: irc.freenode.net #propeller
Newbies, oldies, programmers, math professors, and everyone in-between welcome!
Propeller IRC howto
spinc - open source Spin compiler
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
mul a,b is equivalent to mov a,#0. It sets flags accordingly (sets Z and clears C) if flags are requested.
dfletch, its a good thing your working on a compiler otherwise you might be sorry
I think you had several of us going for awhile...
Intended ? Bug ? Magic ?
Cheers,
--fletch
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Join us in the Un-Official Propeller IRC channel: irc.freenode.net #propeller
Newbies, oldies, programmers, math professors, and everyone in-between welcome!
Propeller IRC howto
spinc - open source Spin compiler
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The World's First Open Source Guitar Pedal:··http://www.OpenStomp.com