Shop OBEX P1 Docs P2 Docs Learn Events
Multiply cordic support in spin2? — Parallax Forums

Multiply cordic support in spin2?

mwrobertsmwroberts Posts: 75
edited 2021-02-25 13:26 in Propeller 2

I didn't see any spin2 instructions for cordic 32 bit multiplication...
There is a MULDIV64(mult1,mult2,divisor) : quotient method, but not one to use the cordic multiply.
I don't see a square root either... and I didn't see and floating point objects in github...
I wrote this method using inline code, it seems to work.
Is there a better way?

Thanks,
Mike

PRI vectorlength(x,y,z) : length | t1,t2,t3,t4,t5,t6

org
ABS x
ABS y
ABS z
QMUL x,x
QMUL y,y
QMUL z,z
GETQX t1
GETQY t4
GETQX t2
GETQY t5
GETQX t3
GETQY t6
add t1,t2 WC
if_c add t4,#1
add t1,t3 WC
if_c add t4,#1
add t4,t5
add t4,t6
QSQRT t1,t4
GETQX length
GETQY t4

end

Comments

  • cgraceycgracey Posts: 14,151

    What are you getting from that last GETQY? After QSQRT, I'm not sure what GETQY returns.

    We only have 32x32 unsigned multiply, QMUL, which returns a 64-bit unsigned product.

    QDIV can divide a 64-bit unsigned value by a 32-bit unsigned value, as long as the top 32 bits of the numerator is less than the denominator, so that the quotient doesn't overflow.

  • @mwroberts : In general Spin2 doesn't handle 64 bit quantities. The MULDIV64 is a special case where there's an intermediate 64 bit result (32 x 32 multiply -> 64 bits -> 32 bits after divide). Not many of the languages for the P2 do handle 64 bits yet; I think p2gcc does, and riscvp2 does, but that's about it. The others stick to 32 bit (single precision) floats and 32 bit integers.

    I've attached the double precision floating point code from riscvp2. It won't compile as-is (it depends on some serial routines and other internal support functions from the JIT compiler framework riscvp2 uses) but it the core algorithms should be useful. In particular the 64 bit multiplies make use of both the CORDIC and the MUL instruction; while the CORDIC is compute one product the COG can compute another (the COG is actually slightly faster).

  • @cgracey : Yes, the GETQY doesn't belong after the QSQRT and GETQX. It was left over from trying to debug the Vectorlength method. Initially I put 3 QMUL's in the pipeline, didn't care about the first QMUL GETQY result, but wasn't sure if it needed to be read out before I could read out the second QMUL's GETQX. (the problem turned out to be QSQRT inputs were swapped)

    I misspoke about 64 bit multiplication... I was thinking about the 64 bit result of the 32x32bit (maybe I should rename the heading?)
    There are cordic spin methods like ROTXY(x,y,angle): rotx, roty
    so, I thought there might be a cordic spin method like MULXY(x,y) : High32bits, Low32bits
    and SQRT(High32bits,Low32bits) : Sqrt

    @ersmith : I'm not trying to do a lot in 64 bits... it's just that the vector length = sqrt( sum( squares)),
    the sum of the squares term, gets past 32 bits pretty quick... I'd prefer to stick to integers...

    The inline code method I wrote is doing everything I need...
    Thank you both...
    Mike

Sign In or Register to comment.