tinyAVR: multiplication of multi-byte integers

Wolfgang Hospital <[email protected]>
Newsgroups gmane.comp.hardware.avr.gcc
Message-ID <[email protected]>
For multiplication by iterated conditional additions, a different 
context brought up retiring two multiplier bits per trip, which I think 
too good to pass, e.g.:

__mulhi3:           ;    0
     movw    a0, p0  ; 1
# if codePinched
     clr     p1      ; 2     partialProduct = 0
     clr     p0      ; 3
     rjmp    shiftM0 ; 5
# else
     lsr     m0      ; 2
#  if greedy
     brcs    shiftM1 ;3/4    neither helps nor hurts worst case:
; without this, it's 4 to clear, 1 to not skip 2 to add = 7
; exp -1.5 cycles, +1 word
#  endif
     clr     p1      ;3/4    partialProduct = 0
     clr     p0      ;4/5
#  if !greedy
     brcc    shiftM1 ;5/7    said worst case
#  else
     lsr     m1      ; 6
     brcs    addHigh ;7/8 8(-4)
     rjmp    shiftA  ; 9  9(-5)	-1 cycle, +4 words
#  endif
# endif
addFull:
     add     p0,a0   ; 1
     adc     p1,a1   ; 2
shiftM1:            ;       handling this 2nd multiplier bit even
     lsr     m1      ; 3      if the multiplicand is zero after its
     brcc    pc+2    ;4/5     next/first shift adds 3 cycles to the
addHigh:            ;		earlyOutA variant, more with fastIn
     add	    p1, a0  ; 5
shiftA:
     add     a0, a0  ; 6     why is adc zero-flag handling ...
     adc     a1, a1  ; 7		... different from subc/sbci/cpc?
shiftM0:            ;    7
     lsr     m0      ; 8
     brcs    addFull ;9/10
# if earlyOutA && !earlyOutA2
     cpse    a0,_zero;+1     _no help_ with m0's most significant 1s
# endif
     sbci    m1, 0   ; 10    presume a zero reg or a high reg?
     brne    shiftM1 ;11/12-2 early(?) out because m is zero
done:               ; wc: 8*10+8+1/2=88+1/2  @14+1/2+1 words ?!
     ret             ; best: 14 (0=b&0xfffe) (none for a)
                     ;(earlyOutA: wc: 8*11+6=98 @15+1/2+1 words)

(Considering the apparent enthusiasm for meta questions(&advice), this 
may be going the other extreme, not elaborating on rationale&circumstances.)

regards,

HoW

-- 
Wolfgang Hospital
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.