I\'m searching for an algorithm to multiply two integer numbers that is better than the one below. Do you have a good idea about that? (The MCU - AT Tiny 84/85 or similar - wher
Well, mix of LUT and shift usually works
Something along the line, multiplying 8 bit entities. Lets consider them made up of two quads
uint4_t u1, l1, u2, l2;
uint8_t a = 16*u1 + l1;
uint8_t b = 16*u2 + l2;
product = 256*u1*u2 + 16*u1*l2 + 16*u2*l1 + l1*l1;
inline uint4_t hi( uint8_t v ) { return v >> 4; }
inline uint4_t lo( uint8_t v ) { return v & 15; }
inline uint8_t LUT( uint4_t x, uint4_t y ) {
static uint8_t lut[256] = ...;
return lut[x | y << 4]
}
uint16_t multiply(uint8_t a, uint8_t b) {
return (uint16_t)LUT(hi(a), hi(b)) << 8 +
((uint16_t)LUT(hi(a), lo(b)) + (uint16_t)LUT(lo(a), hi(b)) << 4 +
(uint16_t)LUT(lo(a), lo(b));
}
just fill lut[] with results of multiplication. In your case depending on memory you could go with quads (256 sized LUT) or with bytes (65536 size LUT) or anything in between