[Icc-430] ICC430 7.08A divmod8u instead of shifts for power-of-2 division on byte vars

Richard Man richard-lists at imagecraft.com
Wed Aug 20 01:57:55 PDT 2008


All 3 improvements should be doable. I will take a look.

At 07:01 PM 8/19/2008, Kris Heidenstrom wrote:
>It looks like ICC430 7.08A uses a helper function divmod8u
>instead of register shift-right operations for unsigned
>division by two if the variables are bytes (unsigned char)
>instead of words (unsigned int).
>
>Compiling with 7.08A for MSP430F1232 target:
>
>  1  ...
>  2  (1912)                           unsigned char length;
>  3  (1913)                           unsigned char nfactors;
>  4  ...
>  5  (1922)                           nfactors = (length / 2) - 1;
>  6    E68E 436F       mov.B   #2,R15
>  7    E690 454E       mov.B   R5,R14
>  8    E692 12B0 F602  call    #divmod8u  <-------  helper function!
>  9    E696 4E46       mov.B   R14,R6
>10    E698 8356       dec.B   R6
>11  (1923)                           if (nfactors != 0) {
>12    E69A 9346       tst.B   R6
>13    E69C 2439       jeq     ...
>
>But if I change the variables to 16-bit unsigned:
>
>  1  ...
>  2  (1912)                           unsigned int length;
>  3  (1913)                           unsigned int nfactors;
>  4  ...
>  5  (1922)                           nfactors = (length / 2) - 1;
>  6    E68E 454B       mov.B   R5,R11
>  7    E690 C312       clrC
>  8    E692 104B       rrc.B   R11  <-------------- register rotate
>  9    E694 835B       dec.B   R11
>10    E696 4B46       mov.B   R11,R6
>11  (1923)                           if (nfactors != 0) {
>12    E698 9346       tst.B   R6
>13    E69A 2439       jeq     ...
>
>As far as I can see, there's no reason why unsigned division
>by 2 should ever be done with a helper function on the MSP430,
>no matter what size the variables are.
>
>There are two more missed opportunities for optimisation
>visible in this code fragment.
>
>1. The CLRC / RRC.B instructions (lines 7 and 8) could be
>    replaced with an RRA instruction, because the top half
>    of R11 is known to be zero because it was just loaded
>    using a MOV.B instruction.
>
>2. The TST.B R6 instruction on line 12 isn't needed because
>    the zero flag is still set/cleared from the DEC.B R11
>    instruction at line 9.
>
>Both of these optimisations would fall into the general
>category of "keep track of known aspects of the MCU's
>state, and take advantage of this to reduce code size
>and/or execution time", and if ICC430 isn't already
>doing this, I expect it would be a major change to add
>it, but I think the benefits could be significant.
>
>Anyway the real issue for me is the helper function used
>for unsigned division by two.
>
>Regards
>
>Kris
>--
>Kris Heidenstrom       Embedded systems designer / programmer
>kris at abbey.co.nz       Abbey Systems Ltd - Telemetry Specialists
>Wellington NEW ZEALAND  Voice +64-4-385-6611  Fax +64-4-385-6848
>
>_______________________________________________
>Icc-430 mailing list
>Icc-430 at imagecraft.com
>http://dragonsgate.net/mailman/listinfo/icc-430

// richard (This email is for mailing lists. To reach me directly, 
please use richard at imagecraft.com) 



More information about the Icc-430 mailing list