Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/15/08 07:57
Modified:
  01/15/08 07:59

Read: times


 
#149460 - Hm, as far as I can see ...
Responding to: ???'s previous message
INT16U_A = INT16U_A * 100 / INT16U_B;

(INT16U_A * 6) / INT16U_B + INT16U_C;


As far as I can see, the two multiplications always have a constant as one of the operands (100 and 6). In assembly, they don't even need to be long multiplications - they could use a 24-bit datatype.

100 is 2^6 + 2^5 + 2^2, so the multiplication with 100 can be done with 3 bit-shifts and 3 adds. 6 is 2^2 + 2^2.

The divisions probably need to be done "by hand" with conditional subtraction. Assembly is probably faster, since it can be taken into account that it's not a true long-long division, but a 32-bit-by-16-bit division.

I don't really know much about the PIC, but if it's halfway sane, it should be able to add, subtract, and check numbers if they're <= 0.

Depending on the range of INT16U_B, the two equations may not even need 32-bit datatypes at any point (i.e. if INT16U_B is always larger than 2, in which case the whole thing can be done in 24 bits.).

List of 8 messages in thread
TopicAuthorDate
32bit divide and mult Not using the Libraries?            01/01/70 00:00      
   Hm, as far as I can see ...            01/01/70 00:00      
      Yes 24 bits            01/01/70 00:00      
   is there any predictible relationship between...            01/01/70 00:00      
      Math in Interrupt Context            01/01/70 00:00      
         SMBus clock stretching            01/01/70 00:00      
            Slicing Prob Not Necessary            01/01/70 00:00      
               True except for AT RATE            01/01/70 00:00      

Back to Subject List