# Multiply-Accumulate

Perform a multiply-accumulate operation on the inputs

• Library:
• HDL Coder / HDL Operations / Multiply-Accumulate

## Description

The Multiply-Accumulate block performs this operation on the inputs `u1` and `u2`, and the bias `k`, to compute the result `y`.

```y = sum(u1.* u2) + k ```

The inputs `u1` and `u2` can be scalars or vectors. By default, the bias `k` is equal to zero, and the block computes the dot product of the inputs `u1` and `u2`. You can specify a nonzero value for `k` using `Dialog` or `Input port` as the Source. The block adds this bias to the dot product of `u1` and `u2`. The multiplication operation is full precision irrespective of the Output data type setting. The Output data type and Integer rounding mode settings apply to the addition operation.

## Ports

### Input

expand all

Port to provide input to the block.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `uint8` | `uint16` | `uint32` | `fixed point`

Port to provide input to the block.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `uint8` | `uint16` | `uint32` | `Boolean` | `fixed point` | `enumerated` | `bus`

Port to provide the bias signal to the block. The block adds this bias to the inputs. Make sure that the bias signal data type matches that of the dot product of the inputs.

#### Dependencies

To enable this port, set Source to `external`.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `uint8` | `uint16` | `uint32` | `fixed point`

### Output

expand all

Port that generates output of the multiply-accumulate operation.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `uint8` | `uint16` | `uint32` | `fixed point`

## Parameters

expand all

You can specify the bias with:

• Source as `Dialog`. Then, specify the Value.

• Source as `Input port`. This setting creates an external input port `c` to input the bias signal to the block.

Set the output data type to:

• A rule that inherits a data type, such as ```Inherit: Same as first input```.

• A built-in data type, such as `single` or `int16`.

• The name of a data type object. for instance, a `Simulink.NumericType` object.

• An expression that evaluates to a valid data type, for example, `fixdt(1,16,0)`

When you set the Output data type, you can use the Data Type Assistant. To display the assistant, click the .

#### Programmatic Use

 Block parameter: `OutDataTypeStr` Type: character vector Default: `{'Inherit: Inherit via internal rule'}`

To see possible values that you can specify for this parameter, see Block-Specific Parameters.

Specify the rounding action as:

`Ceiling`

Rounds positive and negative numbers toward positive infinity. Equivalent to the MATLAB® `ceil` function.

`Convergent`

Rounds number to the nearest representable value. If a tie occurs, rounds to the nearest even integer. Equivalent to the Fixed-Point Designer™ `convergent` function.

`Floor`

Rounds positive and negative numbers toward negative infinity. Equivalent to the MATLAB `floor` function.

`Nearest`

Rounds the number to the nearest representable value. If a tie occurs, rounds toward positive infinity. Equivalent to the Fixed-Point Designer `nearest` function.

`Round`

Rounds number to the nearest representable value. If a tie occurs, rounds positive numbers toward positive infinity and rounds negative numbers toward negative infinity. Equivalent to the Fixed-Point Designer `round` function.

`Simplest`

Chooses between rounding toward floor and rounding toward zero to generate rounding code that is as efficient as possible.

`Zero`

Rounds number toward zero. Equivalent to the MATLAB `fix` function.

#### Programmatic Use

 Block parameter: `RndMeth` Type: character vector Default: `{'Floor'}`

To see possible values that you can specify for this parameter, see Block-Specific Parameters.

## Block Characteristics

 Data Types `double` | `single` | `base integer` | `fixed point` | `bus` Sample Time `Inherit` Direct Feedthrough `Yes` Multidimensional Signals `Scalar` Variable-Size Signals `Yes` Zero-Crossing Detection `No`