Method 1: using wordsize extension – National Instruments AutoCode NI MATRIX User Manual

Page 57

Advertising
background image

Chapter 2

C Language Reference

AutoCode Reference

2-40

ni.com

Implementation of the Addition and Subtraction
Macros

AutoCode has two implementations of the addition and subtraction macros:

Macros that apply wordsize extension (also called extended
intermediate types) to the two operands before aligning the radix
positions and adding or subtracting. This is the default
implementation. Wordsize extension provides greater accuracy, but is
slower because the operations are performed in a larger wordsize than
specified.

Macros that do not apply wordsize extension.

For example, when using wordsize extension in an 8-bit processor, addition
of two 8-bit operands results in a 16-bit addition operation, because the
8-bit addition macro internally extends the wordsize of the operands from
8 bits to 16 bits.

Not using the wordsize extension on 8-bit and 16-bit processors provides
faster operations. However, you can lose precision if the result radix
position is not smaller than the radix positions of the two operands.
Alignment of the radix positions of the operands to the result radix position
can overflow the 8-bit variable capacity, causing a saturation and loss of
accuracy. Example 2-3 shows this.

Example 2-3

Using Wordsize Extension

Subtraction of fixed-point number

n1 = (17, r4)

and fixed-point

number

n2 = (32, r5)

, to produce a fixed-point result number

n3

with

radix position 7, using 8-bit signed variables for both the operands and the
result.

Method 1: Using Wordsize Extension

In binary representation:

0001^0001

(

n1 = (17,r4)

, decimal value = 1.0625)

001^00000

(

n2 = (32,r5)

, decimal value = 1.0)

Extend the wordsize of

n1

and

n2

to 16 bits, and place the extended results

in

n1'

and

n2'

:

00000000 0001^0001

(

n1' = (17,r4)

, decimal value = 1.0625)

00000000 001^00000

(

n2' = (32,r5)

, decimal value = 1.0)

Advertising