This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

how to implement fast div/mod operation with C on f28234 ??



Hi all,

we need a very fast division / modulo procedure for Uint16 values.

The Compiler (5.2.2) begin with the division, and then calls a separate MOD-Function. (see picture, disassembly)

--> why Compiler don't use the AH-Register which IS the MOD-Result ??

 

  • Mike,

    The compiler has an intrinsic to return a 32 bit value with both the quotient and remainder.   This will also save the overhead of the call/return.

    Uint32 result;

    ....

    result = __rpt_subcu(val, 10000, 15);        // result == quotient::remainder
    remainder = (Uint16)result;

    Intrinsics are documented in the compiler reference guide (www.ti.com/lit/spru514 )

    -Lori

  • Lori,

    Thank you for pointing the direction. I knew the intinsincs but did not see the solution in front of me.

    It works with format  result = remainder::quotient ( AH=rmainder, AL = quotient )

    have a nice day,

    Mike

     

  • I think You should try to compile your project with optimizations(at least Register(-o0) )

    Full symblic debug also can affect optimizer, so, probably you should try to turn it off. Then You need to chek Keep Generated .asm Files(-k) in the Assembly section of Compiler options, so You can open corresponding .asm file and see the code generated by compiler.

    Also, if You don't want to turn off Full symblic debug , You may try to turn on Normal Optimizations woth Debug(-mn) option. It is located in Advanced section on the Compiler tab. But this is not always helps.