8

While checking the datasheet of ATMEGA 32 I have found a feature called 'On-chip 2-cycle Multiplier'. enter image description here

Can anyone explain to me what's that and what's the advantage of it?

Sadat Rafi
  • 2,467
  • 10
  • 34
  • 3
    Note that the ATMEGA 32 is an 8 bit MCU and the multiplier in question multiplies two 8-bit register values and provides a 16-bit result. So it may take a number of operations to, say, multiply two 32-bit numbers for a 64-bit result. – Spehro Pefhany May 06 '20 at 21:08
  • 4
    This also implies the MCU **won't** have support for integer division. MCU's are very limited in their capabilities, compared to CPU's. – MSalters May 07 '20 at 12:28
  • 3
    It also implies that there are some AVR models that _don't_ have a hardware multiplier. That line is just inconspicuously missing from e.g. the [ATtiny25 datasheet](http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-2586-AVR-8-bit-Microcontroller-ATtiny25-ATtiny45-ATtiny85_Datasheet-Summary.pdf). See also: [ATtiny: no support for multiplication?](https://electronics.stackexchange.com/questions/86864/attiny-no-support-for-multiplication) – ilkkachu May 07 '20 at 19:16

4 Answers4

20

It means that the ALU in the microcontroller has a hardware multiplier, which takes two instruction clock cycles to perform a calculation.

This is faster than doing multiplication using software (e.g. adding multiple times in a for loop).

Tom Carpenter
  • 63,168
  • 3
  • 139
  • 196
  • A dedicated logic circuit for multiplication to save clock pulses? – Sadat Rafi May 06 '20 at 19:15
  • 2
    @SadatRafi Correct. Multiplication is a frequently used operation, so without a dedicated multiplier, the software would run slower, and take up more instruction memory. – Tom Carpenter May 06 '20 at 19:18
  • 1
    It needn't be a lot of instruction memory, since you'd probably code it as a function and make multiple calls as needed. Definitely slower though. – Mark Ransom May 07 '20 at 17:28
  • This is not necessarily true. It could be the multiplayer is outside of the ALU and function like a co-processor. Although for this CPU it's done by the ALU. – user3528438 May 07 '20 at 23:40
10

It means it has a hardware multiplier that takes can complete a multiply operation in two instruction cycles.

DKNguyen
  • 54,733
  • 4
  • 67
  • 153
3

Some processors can't multiply numbers, they only have addition and bit boolean logic.

This website discusses how to implement multiplication on a 6502 (The old Apple ][ computer, as well as other computers of that era). https://www.lysator.liu.se/~nisse/misc/6502-mul.html

These 8bit x 8bit operations take about 100 cycles per multiplication. You can see that a 2 cycle multiplication (done in hardware) is far superior. You can do simple DSP type calculations if you can do multiplies at half the clock rate.

The best CPUs can still only do 1 multiplication per cycle, because that is the definition of a clock cycle (although they can do many in parallel).

(Now division is a lot harder. Most CPUs take at least N clock cycles to do a division, where N is the number of bits. For some reason, dealing with the "carry" bit in multiplication can be done quickly, while the "carry" bit in division is much more difficult.)

Mark Lakata
  • 354
  • 3
  • 9
  • 1
    "For some reason, dealing with the "carry" bit in multiplication can be done quickly, while the "carry" bit in division is much more difficult." the difference is in the ability to paralellise. In long multiplication you can do all the shifting and masking upfront, then rearrange the addition. In long division you need the results of each subtraction to decide what inputs to use for the next one. – Peter Green May 08 '20 at 00:06
1

It's a feature that would perhaps have been impressive a decade or so ago.


Traditionally basic 8-bit processor cores did not have multiply instructions, silicon area was considered more important than performance.

Higher end 16 and 32 bit processor cores on the other hand typically did have hardware multiply instructions and furthermore worked with larger data word sizes.

Some of the high-end 8 bit (data word size) micro-controller architectures such as the "atmega32" and the "pic18" decided to add a multiply instruction. Since this was a new feature for 8-bit microcontrollers the manufacturers saw reason to shout about it. Both the "pic18" and "atmega32" implementations took a pair of 8 bit inputs and produced a 16 bit output, but the atmega32 version gives more options regarding the exact type of multiply that is desired.

but the elephant in the room is the arm cortex m0+. You can now get micro-controllers with a 32-bit data path and a single-cycle 32*32->32 multiplier for prices comparable to the high-end 8 bit micro-controllers.

Peter Green
  • 21,158
  • 1
  • 38
  • 76