# core_matrix.c

Summary

core_matrix.c |
Description | Matrix manipulation benchmark
Functions |
core_bench_matrix | Benchmark function
matrix_test | Perform matrix manipulation.
matrix_sum | Calculate a function that depends on the values of elements in the matrix.
matrix_mul_const | Multiply a matrix by a constant.
matrix_add_const | Add a constant value to all elements of a matrix.
matrix_mul_vect | Multiply a matrix by a vector.
matrix_mul_matrix | Multiply a matrix by a matrix.
matrix_mul_matrix_bitextract | Multiply a matrix by a matrix, and extract some bits from the result.

### Description

Matrix manipulation benchmark

This very simple algorithm forms the basis of many more complex algorithms.

The tight inner loop is the focus of many optimizations (compiler as well as hardware based) and is thus relevant for embedded processing.

#### The total available data space will be divided to 3 parts

NxN Matrix A | initialized with small values (upper 3/4 of the bits all zero).
NxN Matrix B | initialized with medium values (upper half of the bits all zero).
NxN Matrix C | used for the result.

The actual values for A and B must be derived based on input that is not available at compile time.

### Functions

### core_bench_matrix

> ee_u16 core_bench_matrix( | mat_params | * | p,
> | ee_s16 |  | seed,
> | ee_u16 |  | crc | )

Benchmark function

Iterate matrix_test N times, changing the matrix values slightly by a constant amount each time.

### matrix_test

> ee_s16 matrix_test( | ee_u32 |  | N,
> | MATRES | * | C,
> | MATDAT | * | A,
> | MATDAT | * | B,
> | MATDAT |  | val | )

Perform matrix manipulation.

#### Parameters

N | Dimensions of the matrix.
C | memory for result matrix.
A | input matrix
B | operator matrix (not changed during operations)

#### Returns

A CRC value that captures all results calculated in the function. In particular, crc of the value calculated on the result matrix after each step by matrix_sum.

#### Operation

1 | Add a constant value to all elements of a matrix.
2 | Multiply a matrix by a constant.
3 | Multiply a matrix by a vector.
4 | Multiply a matrix by a matrix.
5 | Add a constant value to all elements of a matrix.

After the last step, matrix A is back to original contents.

### matrix_sum

> ee_s16 matrix_sum( | ee_u32 |  | N,
> | MATRES | * | C,
> | MATDAT |  | clipval | )

Calculate a function that depends on the values of elements in the matrix.

For each element, accumulate into a temporary variable.

As long as this value is under the parameter clipval, add 1 to the result if the element is bigger then the previous.

Otherwise, reset the accumulator and add 10 to the result.

### matrix_mul_const

> void matrix_mul_const( | ee_u32 |  | N,
> | MATRES | * | C,
> | MATDAT | * | A,
> | MATDAT |  | val | )

Multiply a matrix by a constant. This could be used as a scaler for instance.

### matrix_add_const

> void matrix_add_const( | ee_u32 |  | N,
> | MATDAT | * | A,
> | MATDAT |  | val | )

Add a constant value to all elements of a matrix.

### matrix_mul_vect

> void matrix_mul_vect( | ee_u32 |  | N,
> | MATRES | * | C,
> | MATDAT | * | A,
> | MATDAT | * | B | )

Multiply a matrix by a vector. This is common in many simple filters (e.g. fir where a vector of coefficients is applied to the matrix.)

### matrix_mul_matrix

> void matrix_mul_matrix( | ee_u32 |  | N,
> | MATRES | * | C,
> | MATDAT | * | A,
> | MATDAT | * | B | )

Multiply a matrix by a matrix. Basic code is used in many algorithms, mostly with minor changes such as scaling.

### matrix_mul_matrix_bitextract

> void matrix_mul_matrix_bitextract( | ee_u32 |  | N,
> | MATRES | * | C,
> | MATDAT | * | A,
> | MATDAT | * | B | )

Multiply a matrix by a matrix, and extract some bits from the result. Basic code is used in many algorithms, mostly with minor changes such as scaling.

> ee_u16 core_bench_matrix( | mat_params | * | p,
> | ee_s16 |  | seed,
> | ee_u16 |  | crc | )

Benchmark function

> ee_s16 matrix_test( | ee_u32 |  | N,
> | MATRES | * | C,
> | MATDAT | * | A,
> | MATDAT | * | B,
> | MATDAT |  | val | )

Perform matrix manipulation.

> ee_s16 matrix_sum( | ee_u32 |  | N,
> | MATRES | * | C,
> | MATDAT |  | clipval | )

Calculate a function that depends on the values of elements in the matrix.

> void matrix_mul_const( | ee_u32 |  | N,
> | MATRES | * | C,
> | MATDAT | * | A,
> | MATDAT |  | val | )

Multiply a matrix by a constant.

> void matrix_add_const( | ee_u32 |  | N,
> | MATDAT | * | A,
> | MATDAT |  | val | )

Add a constant value to all elements of a matrix.

> void matrix_mul_vect( | ee_u32 |  | N,
> | MATRES | * | C,
> | MATDAT | * | A,
> | MATDAT | * | B | )

Multiply a matrix by a vector.

> void matrix_mul_matrix( | ee_u32 |  | N,
> | MATRES | * | C,
> | MATDAT | * | A,
> | MATDAT | * | B | )

Multiply a matrix by a matrix.

> void matrix_mul_matrix_bitextract( | ee_u32 |  | N,
> | MATRES | * | C,
> | MATDAT | * | A,
> | MATDAT | * | B | )

Multiply a matrix by a matrix, and extract some bits from the result.
Close