Shop OBEX P1 Docs P2 Docs Learn Events
PASM multiply questions — Parallax Forums

PASM multiply questions

Jack BuffingtonJack Buffington Posts: 115
edited 2011-06-28 20:41 in Propeller 1
I'm deep into working with the vocal tract. So far so good but I'm trying to improve the frication. To do that, I need an unsigned multiply. I suppose that I could use the multiply routine already in it but I don't like using code that I don't understand.

Chip is saving a few longs in HUB memory by building the multiply routine when the program runs. That's cool but it makes it hard to follow. As best as I understand, this is what the multiply routine builds into:
' Multiply
'                                                                                             
'   in:         t1 = unsigned multiplier (15 top bits used)
'               t2 = signed multiplicand (17 top bits used)
'
'   out:        t1 = 32-bit signed product

mult                    shr     t1,#32-15               'position unsigned multiplier

                        sar     t2,#15                  'position signed multiplicand
                        shl     t2,#15-1

                        sar     t1,#1           wc      
                        if_c            add     t1,t2
                        sar     t1,#1           wc      
                        if_c            add     t1,t2
                        sar     t1,#1           wc      
                        if_c            add     t1,t2
                        sar     t1,#1           wc      
                        if_c            add     t1,t2
                        sar     t1,#1           wc      
                        if_c            add     t1,t2
                        sar     t1,#1           wc      
                        if_c            add     t1,t2
                        sar     t1,#1           wc      
                        if_c            add     t1,t2
                        sar     t1,#1           wc      
                        if_c            add     t1,t2
                        sar     t1,#1           wc      
                        if_c            add     t1,t2
                        sar     t1,#1           wc      
                        if_c            add     t1,t2
                        sar     t1,#1           wc      
                        if_c            add     t1,t2
                        sar     t1,#1           wc      
                        if_c            add     t1,t2
                        sar     t1,#1           wc      
                        if_c            add     t1,t2
                        sar     t1,#1           wc      
                        if_c            add     t1,t2
                        sar     t1,#1           wc      
                        if_c            add     t1,t2                   

mult_ret         ret



I have always written my multiply routines on other processors with steps like this. MultiplyA is left justified.
              shl       result   
              shl       multiplyA,#1   wc
        if_c  add       result,multiplyB

This works like long multiplication that I learned in school.

I'm just not following how Chip's routine works but would like to since it appears to use one less instruction per bit.

I must be misunderstanding how it is assembled in COG RAM. Has anyone else figured this one out?

Comments

  • Mark_TMark_T Posts: 1,981
    edited 2011-06-28 20:41
    Its the same idea, just summed in the opposite order - so shift right on every step (t1 holds both the result and one of the arguments)
Sign In or Register to comment.