Top Banner
-1- 1Introduction Embedded System Lab Embedded System Lab Design and Imp. of Algorithms for Fixed-Point and Floating-Point Arith. 전재욱 Embedded System 연구실 성균관대학교
99

Fix Float Art

Apr 22, 2017

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Fix Float Art

- 1 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Design and Imp. of Algorithms

for Fixed-Point and Floating-Point Arith.

전 재 욱

Embedded System 연구실

성균관대학교

Page 2: Fix Float Art

- 2 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Outline

Design of algorithms in fixed-point and floating-point arithmetic

In the microcontroller onboard the ECURelated to several basic issues that occur in the context of design and implementation of machine-based arithmetic

Page 3: Fix Float Art

- 3 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Binary number system In all processorsIn order to represent a number x, the coefficients ai of the binary decomposition are used

Example: Binary notation of the number x = 9After decomposition, the number x = 9

has the binary notation 1001.

Representation of Numbers in Processors

Page 4: Fix Float Art

- 4 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Processors provide only a fixed finite number n of binary positions.

Word lengthIt is determined by processor construction and can be expanded to full multiples (e.g., 2n, 3n) of n.

Microprocessors with a word length of 8 positions8-bit microprocessors

Those with a word length of 16 bits16-bit microprocessors

Representation of Numbers in Digital Processors

Page 5: Fix Float Art

- 5 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Two ways to use the word length of n positions to represent a number.

In fixed-point representationIn floating-pint representation

Representation of Numbers in Digital Processors

Page 6: Fix Float Art

- 6 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Fixed-Point Representation

Not only the number n, but also the numbers n1and n2 of the positions before and after the decimal point are fixed,

where n = n1 + n2

In most cases, n1 = n, or n1 = 0.

To this day, the functions of many processors deployed in ECUs are limited to the fixed-point representation and processing of numbers.

Page 7: Fix Float Art

- 7 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Fixed-Point Representation

We may assume n1 = n for fixed-point notation. Then the number n determines the set of numbers represented.

For example, for n = 8, Numbers 0 through 255 can be represented

By 0000 0000 through 1111 1111.8-bit unsigned integer notation, or uint8

Numbers –128 through +127 can be representedBy 1000 0000 through 0111 1111.8-bit signed integer notation, or sint8

Page 8: Fix Float Art

- 8 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Fixed-Point Representation

We may assume n1 = n for fixed-point notation. Then the number n determines the set of numbers represented.

Range of numbers for n = 16 and 32uint16 ?sint16 ?unit32 ?sint32 ?

Page 9: Fix Float Art

- 9 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Fixed-Point Representation

Number of Binary Position Abbreviation Range

8-bit unsigned integer uint8 0 ~ 255

8-bit signed integer sint8 -128 ~ 127

16-bit unsigned integer uint16

16-bit signed integer sint16

32-bit unsigned integer uint32

32-bit signed integer sint32

Page 10: Fix Float Art

- 10 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Floating-Point Representation

The decimal point floats in accordance with the value that a given number assumes.

A real number x can be expressed as the product of

with |a| < 1 and b as an integer.

The exponent b indicates the position of the decimal point in the mantissa a.

Page 11: Fix Float Art

- 11 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Floating-Point Representation

The decimal point floats in accordance with the value that a given number assumes.

Example: Binary representation of the number x = 9.5

produces binary notation 1001.1 or 0.10011 * 2100.

Page 12: Fix Float Art

- 12 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Floating-Point Representation

For the representation of mantissa a and exponent b,

processors provide only a fixed finite number m and e of binary positions, where n = m + e.

Page 13: Fix Float Art

- 13 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Floating-Point Representation

Depending on the requirements of the respective application,

ECUs are equipped with microprocessors capable of supporting floating-point operations.

But there is ALWAYS limitation in floating-point representation.

Page 14: Fix Float Art

- 14 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Floating-Point Representation

Floating-point representations of a given number are not necessarily unique.

9.5 = 0.010011 * 2101 = 0.10011 * 2100

For this reason, the floating-point notation of any number for which the first digit of mantissa a is unlike 0 (“nonzero”) is termed normalized.

In the binary system, |a| ≥ 2–1 applies. Thus, all numbers of mantissa a, excluding the leading zeros, are termed significant digits.

Page 15: Fix Float Art

- 15 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Floating-Point Representation

The numbers m and e, together with base B = 2 of the notation, determine the set A of numbers that can be accurately represented in the machine.

This set A comprises a subset of the real numbers R(A ⊆ R) . The elements of which set A is composed are termed machine numbers.

Page 16: Fix Float Art

- 16 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Floating-Point Representation

For n = 32 and n = 64, floating-point representations are defined in the IEEE standard.

In a manner similar to fixed-point numbers, 32-bit and 64-bit floating-point numbers are termed real32 and real64, respectively.

Page 17: Fix Float Art

- 17 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Representation of Numbers in Processors

The set A of the numbers available for the rep. of fixed-point and floating point numbers

Finite setDesign and implementation of the behavior of a software component

presents the immediate issue of how to approximate a given number ( ) with a machine number.

This issue manifests itself not only at the time of data entry in the computer, but also during internal data handling in the processor.

Page 18: Fix Float Art

- 18 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Representation of Numbers in Processors

Although ,

it may be possible that

Page 19: Fix Float Art

- 19 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Representation of Numbers in Processors

App. for a number x ( ) by a machine number rd(x)

x is not a machine numberrd(x), gk: machine numbers (rd(x) ≠ gk)rd(x): rounding of x

Schauffele

Page 20: Fix Float Art

- 20 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Rounding Errors in Integer Division

Division for a, b, and c in uint8 notation

Page 21: Fix Float Art

- 21 -

제1장 Introduction

Embedded System LabEmbedded System Lab

is not an integerRounding is requiredRepresentation of c = 9.5 in normal binary representation

Rounding Errors in Integer Division

Page 22: Fix Float Art

- 22 -

제1장 Introduction

Embedded System LabEmbedded System Lab

is not an integerrd(9.5) = 10

1010B

Rounding

Page 23: Fix Float Art

- 23 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Integer division in many processors produces a simple truncation (i.e. round-off)

Gives rd(c) = 9, or 1001B for c = 9.5

Truncation

Page 24: Fix Float Art

- 24 -

제1장 Introduction

Embedded System LabEmbedded System Lab

rd(240/161) = rd(1.49 …) = 1 for both rounding and truncation of the decimal places

In this case, the relative rounding error

fairly large It determines the accuracy of the result

Rounding Errors in Integer Division

Page 25: Fix Float Art

- 25 -

제1장 Introduction

Embedded System LabEmbedded System Lab

rd(100/201) = rd(0.49 …) = 0for both rounding and truncation of the decimal places

Relative rounding error

Particular large This case is especially critical for error propagation

e.g. when further processing the intermediate result in a multiplication

Rounding Errors in Integer Division

Page 26: Fix Float Art

- 26 -

제1장 Introduction

Embedded System LabEmbedded System Lab

rd(100/1) = rd(100) = 100

rd(100/0) Not definedException handling

Rounding Errors in Integer Division

Page 27: Fix Float Art

- 27 -

제1장 Introduction

Embedded System LabEmbedded System Lab

For c > 1, the relative rounding error

i.e. rd(c) can be rep. as

The relative error becomes smaller as the result increases.

Relative Rounding Errors

Page 28: Fix Float Art

- 28 -

제1장 Introduction

Embedded System LabEmbedded System Lab

For c > 1, the relative truncation error

i.e. rd(c) can be rep. as

The relative error becomes smaller as the result increases.

Relative Truncation Errors

Page 29: Fix Float Art

- 29 -

제1장 Introduction

Embedded System LabEmbedded System Lab

(Fixed-point integer rep) Machine number operands

Results of a + b, a – b, and a * binteger values

A rounding error does not occur.

Because of the finite number n of binary positions, there are always numbers that are not machine numbers.

Overflow and Underflow in Add, Sub, and Mul

Page 30: Fix Float Art

- 30 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Addition Example:Variables a, b, and c of uint8 notation Addition with

Test case 2 gives us overflow example.How a microprocessor does detect this?

Overflow and Underflow in Add, Sub, and Mul

Page 31: Fix Float Art

- 31 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Addition Example:Variables a, b, and c of sint8 notation Addition with

Overflow example?How detect?

Overflow and Underflow in Add, Sub, and Mul

Page 32: Fix Float Art

- 32 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Subtraction Example:Variables a, b, and c of uint8 notation Addition with

Test case 4 gives us underflow (overflow) example.How a microprocessor does detect this?

Overflow and Underflow in Add, Sub, and Mul

Page 33: Fix Float Art

- 33 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Subtraction Example:Variables a, b, and c of sint8 notation Addition with

Overflow example?How detect?

Overflow and Underflow in Add, Sub, and Mul

Page 34: Fix Float Art

- 34 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Similar situations may occur in conjunction with multiplications.

Overflow and Underflow in Add, Sub, and Mul

Page 35: Fix Float Art

- 35 -

제1장 Introduction

Embedded System LabEmbedded System Lab

The implementation in floating-point arithmetic is another area in which errors in the input data as well as approximation errors have such an effect on the selected calculation modes.

However, when compared with fixed-point arithmetic, the rounding errors occurring in floating-point integers and floating-point arithmetic are smaller by several orders of magnitude.

Overflow and Underflow in Add, Sub, and Mul

Page 36: Fix Float Art

- 36 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Binary representation in the processor

If the operand b is in the set ,a*b and a/b may be handled quite efficiently by means of shift operations .

Shift Operations

Page 37: Fix Float Art

- 37 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Example: Decimal number x = 9

binary notation 01001

Shift Operations

Page 38: Fix Float Art

- 38 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Example: Decimal number x = 9

binary notation 01001

Product of 9 * 2a left-shift operation 01001≪ 1 è 10010 (decimal 18)

Shift Operations

Page 39: Fix Float Art

- 39 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Example: Decimal number x = 9

binary notation 01001

Division 9/2

a right-shift operation 01001≫1 è 00100 (decimal 4)may cause the decimal positions to be truncated.

Shift Operations

Page 40: Fix Float Art

- 40 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Shift in signed integers ?

Logical Shift & Arithmetic Shift Overflow check

Shift Operations

Page 41: Fix Float Art

- 41 -

제1장 Introduction

Embedded System LabEmbedded System Lab

The actions taken in the event of a value range violation due to overflow or underflow depend on the processor.

Each algorithm may provide different responses.

Handling Overflows and Underflows

Page 42: Fix Float Art

- 42 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Some options for overflow handling Overflow with or without overflow detectionLimiting the resultExtending the value range of the resultRescaling the result

Example: Overflow handlingVariables a, b, and c in uint8 notation.Addition with

Handling Overflows and Underflows

Page 43: Fix Float Art

- 43 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Overflow is permitted.

Most microprocessors output

A compare operation can be used to detect and handle an overflow of unsigned integers in the algorithm.

Carry in unit and Overflow in sint?

Overflow with or without Overflow Detection

Page 44: Fix Float Art

- 44 -

제1장 Introduction

Embedded System LabEmbedded System Lab

The overflow is recognized in the algorithm

The result c is limited to the max representable value c = 255.

Limiting The Result

Page 45: Fix Float Art

- 45 -

제1장 Introduction

Embedded System LabEmbedded System Lab

The result c is represented in a variable with extended value range (e.g., in a uint16 or sint16 variable).

Thus,

and

or

An overflow can no longer occur. In the event that c is represented as a variable of the sint16 type, an underflow can no longer occur in a subtraction also.

Extending The Value Range of The Result

Page 46: Fix Float Art

- 46 -

제1장 Introduction

Embedded System LabEmbedded System Lab

The overflow is recognized, and the result c is rescaled to rd(c) .

To do this, a quantification or resolution q for c at |q| > 1 is introduced.

By rescaling the result c to the equation c = q * rd(c) , the value range of c can be extended, and overflow no longer occurs.

Rescaling The Result

Page 47: Fix Float Art

- 47 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Rescaling The Result

Rescaling with factors q from the set

can be realized by means of shift operations.

Thus,

where

Page 48: Fix Float Art

- 48 -

제1장 Introduction

Embedded System LabEmbedded System Lab

An overflow can no longer occur. On the downside, the accuracy of the result rd(c) = 256 is reduced.

The relative error ε is as follows:

As in a previous example, the relative error decreases as the size of the result increases.

Rescaling The Result

Page 49: Fix Float Art

- 49 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Errors propagate within a given algorithm.

Algorithmclearly defined sequence of a finite number of “simple” operations

which can be used to produce the solution to a problem through the calculation of specific input data.

Error Propagation with Algorithms in Fixed-Point Arithmetic

Page 50: Fix Float Art

- 50 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Example: d = a + b + c d = (a + b) + c and d = a + (b + c)

mathematically equivalentmay produce divergent results due to numerical reasons in fixed-point calculation.

Error Propagation with Algorithms in Fixed-Point Arithmetic

Page 51: Fix Float Art

- 51 -

제1장 Introduction

Embedded System LabEmbedded System Lab

a, b, c, d in sint8

Algorithm 1:

Algorithm 2:

Error Propagation with Algorithms in Fixed-Point Arithmetic

Page 52: Fix Float Art

- 52 -

제1장 Introduction

Embedded System LabEmbedded System Lab

For a = 101, b = –51, and c = –100,

The propagation of rounding and limitation errors is an essential factor.

Error Propagation with Algorithms in Fixed-Point Arithmetic

Page 53: Fix Float Art

- 53 -

제1장 Introduction

Embedded System LabEmbedded System Lab

In fixed-point calculation, an approx. value rd(d) is obtained instead of d.

For Algorithm 1, rd1(d) can be determined:

The relative error

Error Propagation with Algorithms in Fixed-Point Arithmetic

Page 54: Fix Float Art

- 54 -

제1장 Introduction

Embedded System LabEmbedded System Lab

As the first approx., when disregarding higher order terms such as

In Algorithm 1

In Algorithm 2

èThe rounding errors of the intermediate results affect the relative error

Error Propagation with Algorithms in Fixed-Point Arithmetic

Page 55: Fix Float Art

- 55 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Critical factor

and

Depending on whether (a+b) or (b+c) is smaller, “numerically more stable” to calculate the sum a+b+c

(a+b)+c or a + (b+c)

Error Propagation with Algorithms in Fixed-Point Arithmetic

Page 56: Fix Float Art

- 56 -

제1장 Introduction

Embedded System LabEmbedded System Lab

For a = 101, b = –51, and c = –100,a + b = 50 and b + c = –151

Error Propagation with Algorithms in Fixed-Point Arithmetic

Page 57: Fix Float Art

- 57 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Algo 1 and 2 for a = 101, b = –51, and c = –100Algo 2

The relative error of Step 1 enters the result with an

amplification factor of ≈ 3

Step 2 is executed without a relative error.

This explains why Algo1, considering the input values of this

test case, is more beneficial in numerical terms.

Error Propagation with Algorithms in Fixed-Point Arithmetic

Page 58: Fix Float Art

- 58 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Algo 3Rescaling and not limiting the intermediate result in Algo2 of the preceding example by a factor of 2

Error Propagation with Algorithms in Fixed-Point Arithmetic

Page 59: Fix Float Art

- 59 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Algo 3

Error Propagation with Algorithms in Fixed-Point Arithmetic

Page 60: Fix Float Art

- 60 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Algo 3With these input values, the selected rescaling produces a much more accurate result than Algorithm 2 with a limitation of the intermediate result. Limitations of this type must be watched closely because they may implicitly occur in algorithms (e.g., through the transfer of arguments in conjunction with subprogram calls).

Error Propagation with Algorithms in Fixed-Point Arithmetic

Page 61: Fix Float Art

- 61 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Two physical signals in the microprocessor with different scaling must be handled in an arithmetical operation.

Example: Addition of two signals of different scalingAddition of the two signals a and bImplementation of the physical relation cphys = aphys + bphys.In the microprocessor, the signals a, b, and c are available in the form of fixed-point variables aimp1, bimp1 , and cimp1 in uint8 representation.

Physical Interrelation and Fixed-Point Arithmetic

Page 62: Fix Float Art

- 62 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Interrelation btw A Physical Variable and Imp

<Schauffele>

Page 63: Fix Float Art

- 63 -

제1장 Introduction

Embedded System LabEmbedded System Lab

The interrelation btw the physical continuous variables and the imp variables in discrete fixed-point notation

is specified by a linear formula and by the lower and upper limits.

The value range of aimp1 in uint8: {0, 1, 2, …, 255}Or the general value range {a imp1 MIN, …, a imp1 MAX}.

Physical Interrelation and Fixed-Point Arithmetic

Page 64: Fix Float Art

- 64 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Accordingly, this example yields the upper and lower limits for the physically representable value range:

The range of physically occurring values{aphysmin … aphysmax }

Different from { aphysMIN … aphysMAX }

Physical Interrelation and Fixed-Point Arithmetic

Page 65: Fix Float Art

- 65 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Similar interrelations apply to the variables b and c.

For the linear range, the following applies:

Because of only fixed-point values at the imp level, each case requires a rounding

1/K1i is also termed a quantization or resolutionK0i is known as offset.

Physical Interrelation and Fixed-Point Arithmetic

Page 66: Fix Float Art

- 66 -

제1장 Introduction

Embedded System LabEmbedded System Lab

The addition of the physical variables at the imp level can be accomplished with the following algorithm:

Step 1: Removing offset from aimp1 and bimp1

Step 2: Approx. quantization of aimp1_1 and bimp1_1

Physical Interrelation and Fixed-Point Arithmetic

Page 67: Fix Float Art

- 67 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Step 3: Addition

Step 4: Approx. quantization of cimp1

Step 5: Allowing for offset of cimp1

Physical Interrelation and Fixed-Point Arithmetic

c _ = a _ + b _

c _ = c _ ∗ KK

Page 68: Fix Float Art

- 68 -

제1장 Introduction

Embedded System LabEmbedded System Lab

At the physical level of a model, a differentiation may be made between continuous-value, discrete-value, and Boolean variables:

Continuous-value variablesphysical signals of continuous valuetemperatures, revolutions per minute, or pressures

Value-discrete variablesnatural variablesthe number of cylinders in an enginethe number of stages (shift levels) in a transmission

Boolean variables describe state pairsa switch position Ø On/Off, High/Low, TRUE/FALSE

Physical Model Level and Imp Level

Page 69: Fix Float Art

- 69 -

제1장 Introduction

Embedded System LabEmbedded System Lab

If a continuous-value variable is to be implemented in fixed-point representation, it first must be discretized.

For this reason, this aspect of value discretization often gains central significance in data modeling.Each physical value Xphys must be assigned exactly one discrete implementation value that is unique and unambiguous.

Physical Model Level and Imp Level

Page 70: Fix Float Art

- 70 -

제1장 Introduction

Embedded System LabEmbedded System Lab

The relative error is the determining quality factor for the result produced by an algorithm.

Integer divisions, as well as overflow and underflow handling, limit the numerical accuracy.

Notes on Imp in Fixed-Point Arithmetic

Page 71: Fix Float Art

- 71 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Because the relative error in integer divisions is large, every effort should be made to avoid their utilization.

Divisions by 0 (zero) are not defined and therefore must be handled as an exception.

Divisions by {21, 22, …, 2n}by using shift operations.

Useful Pointers on Integer Divisions

Page 72: Fix Float Art

- 72 -

제1장 Introduction

Embedded System LabEmbedded System Lab

For necessary divisions,the division operations should occur as late in the algorithm as possible.

In this way, the relative error enters the result only at a very late stage.

Useful Pointers on Integer Divisions

Page 73: Fix Float Art

- 73 -

제1장 Introduction

Embedded System LabEmbedded System Lab

The larger the result of the integer division, the smaller the relative error.

If possible, the value of the numerator should be considerably larger than that of the denominator.

This may be accomplished by defining an offset or through a requantization by means of a shift operation prior to the actual division.

Useful Pointers on Integer Divisions

Page 74: Fix Float Art

- 74 -

제1장 Introduction

Embedded System LabEmbedded System Lab

aimp1 , temp in uint16, bimp1 , cimp1 in uint8

Physical values aphys = 79, bphys = 5

The exact value of cphys would be

Calculation of Division c = a/b

Page 75: Fix Float Art

- 75 -

제1장 Introduction

Embedded System LabEmbedded System Lab

The conversion formulas

Value range

Calculation of Division c = a/b

Page 76: Fix Float Art

- 76 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Step 1Shift operation by 8 places for aimp1 to take advantage of the full 16-bit value range

Algo. for Calculation of Division c = a/b

Page 77: Fix Float Art

- 77 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Step 2Executing the actual integer division

For ,

The equivalent of 15.7968 … * 28 .

Compared with the integer division ,

Ø rescaling the variable temp aids in obtaining significantly higher accuracy.

Algo. for Calculation of Division c = a/b

Page 78: Fix Float Art

- 78 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Step 3: Rescaling the result by 8 decimal places

The variable temp must be rescaled to the scale of cimp1:

This causes a relative error and loss of accuracy.

Therefore, this step should be inserted in the algorithm at the latest possible time.

From this point onward, any calculating steps should use the more accurate intermediate temp variable.

Algo. for Calculation of Division c = a/b

Page 79: Fix Float Art

- 79 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Overflow and underflow handling limit the accuracy of additions, subtractions, and multiplications.

Several strategies for overflow and underflow handling are available.

RescalingLimitationExtension of the value range by means of type conversionPermitting overflow or underflow with or without detection and response in the algorithm

Useful Pointers on Add, Sub, and Mult

Page 80: Fix Float Art

- 80 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Rescaling the value range reduces the relative accuracy across the entire value range, even if overflow or underflow does not occur.

Limiting the value range causes a drop in relative accuracy only if an overflow or underflow occurs.

Useful Pointers on Add, Sub, and Mult

Page 81: Fix Float Art

- 81 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Converting physical signal to imp variablesthe offset can be set in such a way that the calculations at the implementation level occur “in the middle” of the chosen value range.

This also aids the in-processor representation using a shorter word length. However, offsets may cause additional conversion operations when linking different signals.

Useful Pointers on Add, Sub, and Mult

Page 82: Fix Float Art

- 82 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Multiplications and divisions using values from the set {21, 22, …, 2n}

By shift operationsLogical shift and Arithmetic shift

Unsigned and Signed numbers

Useful Pointers on Add, Sub, and Mult

Page 83: Fix Float Art

- 83 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Even with accurately executed operations such as additions, subtractions, and multiplications,

a relative error in the input variables may quickly become amplified.

Useful Pointers on error Propagation

Page 84: Fix Float Art

- 84 -

제1장 Introduction

Embedded System LabEmbedded System Lab

The machine number set A is finite for floating-point numbers.

Rounding errors in the arithmetical operations

Associative and distributive laws do not apply herebecause the exact arithmetical operations are approximated by floating-point operations

Notes on Imp in Floating-Point Arith

Page 85: Fix Float Art

- 85 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Not all numerical problems are solved by means of floating-point arithmetic.

The adv of larger numerical value rangeReduction of the influence of numerical rounding errors as well as overflows and underflows Scaling of physical variables—a frequent source of error in the implementation in integer arithmetic—is not required.

Notes on Imp in Floating-Point Arith

Page 86: Fix Float Art

- 86 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Disadv of higher numerical accuracygreater word length è Increased memory and runtimeIn a preemptive arbitration strategy,

backing up and restoring floating-point data may have a significant influence on runtime in real-time systems.

Notes on Imp in Floating-Point Arith

Page 87: Fix Float Art

- 87 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Thus, a solution of combining fixed-point and floating-point arith is used for many applications.

An awareness and understanding of general numerical methods is essential in solving problems:

Conversion of fixed-point numbers to floating-point numbers, and vice versa Handling “division by zero” conditionsPropagation of approximation errors that may be generated by filter and integration algorithmsPropagation of rounding errors

Notes on Imp in Floating-Point Arith

Page 88: Fix Float Art

- 88 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Compare operations of two floating-point numbers a and b should be avoided in many cases.

Instead, compare the diff δ =|a – b| vis-à-vis a barrier ε,

which also requires consideration of the relative accuracy (e.g., in the form of δ = |a * ε| or δ = |b * ε| ).

Divisions by 0 (zero) must be excluded by means of conditions and queries.

Useful Pointers on Compare and Div Operations

Page 89: Fix Float Art

- 89 -

제1장 Introduction

Embedded System LabEmbedded System Lab

The optimizations for production ECUs depend onthe applicationthe hardware platform

Thus, close cooperation is necessary btwfct developer responsible for the model-based physical specificationSW engineer in charge of the design and implementation

Modeling and Imp Guidelines

Page 90: Fix Float Art

- 90 -

제1장 Introduction

Embedded System LabEmbedded System Lab

Modeling and imp guidelines are vital prerequisites for dedicated optimization measures.

The function model must facilitate the explicit specification of all software relevant information without unnecessarily impeding physical understanding.

Example of modeling guidelinesMSR(Manufacturer Supplier Relationship) standards

Example of imp guidelinesMISRA(Motor Industry SW Reliability Association) Guidelines

Modeling and Imp Guidelines

Page 91: Fix Float Art

- 91 -

제1장 Introduction

Embedded System LabEmbedded System Lab

MISRA(Motor Industry Sw Reliability Asso.)

MISRAAn organization that produces guidelines for the SW developed for electronic components used in Automotive Industry. It is a collaboration between vehicle manufacturers, component suppliers, and engineering consultancies.

AimTo provide important advice to the automotive industry for the creation and application of safe, reliable SW within vehicles.The safety requirements of the SW used in Automobiles is different from that of other areas.

Reliability and cost

Page 92: Fix Float Art

- 92 -

제1장 Introduction

Embedded System LabEmbedded System Lab

MISRA(Motor Industry Sw Reliability Asso.)

FormationMISRA was formed by a consortium of organizations formed in response to the UK Safety Critical Systems REsearchProgramme.

This programme was supported by the Department of Trade and Industry and the Engineering and Physical Sciences Research Council.

MISRA steering committeeAB Automotive Electronics Ltd, Ford Motor Company LtdJaguar Cars Ltd, Lotus EngineeringMIRA Ltd, Ricardo UK LtdTRW Automotive Electronics, The University of LeedsVisteon

Page 93: Fix Float Art

- 93 -

제1장 Introduction

Embedded System LabEmbedded System Lab

MISRA(Motor Industry Sw Reliability Asso.)

The GuidelinesMISRA guidelines are the development guidelines for vehicle based SW.

The guidelines are intended to achieve the following.Ensure SafetyBring in robustness, reliability to the SW.Human safety must take precedence when in conflict with security of property.Consider both random and systematic faults in system design.Demonstrate robustness, not just rely on the absence of failures.Application of safety considerations across the design, manufacture, operation, servicing and disposal of products.

Page 94: Fix Float Art

- 94 -

제1장 Introduction

Embedded System LabEmbedded System Lab

MISRA C

First published in 1998

To provide a "restricted subset of a standardized structured language" as required in the 1994 MISRA Guidelines for automotive systems being developed to meet the requirements of Safety Integrity Level (SIL) 2 and above.

Since its launch in 1998, the uptake and usage of MISRA C has far exceeded the authors' original expectations.

Page 95: Fix Float Art

- 95 -

제1장 Introduction

Embedded System LabEmbedded System Lab

MISRA C

MISRA C was originally developed to support the language requirements of the 1994 MISRA Guidelines.

Since that time, however, MISRA C has been adopted and used across a wide variety of industries and applications including the rail, aerospace, military and medical sectors.

Furthermore, a significant number of tools are available that support enforcing the MISRA C rules.

In Japan, a Japanese translation of MISRA C has been published by JSAE, and the MISRA C Study Group have produced a book (in Japanese) giving detailed explanations of the rules and additional code examples.

Page 96: Fix Float Art

- 96 -

제1장 Introduction

Embedded System LabEmbedded System Lab

MISRA C

Updated in 2004

Rules (required) & advisories covering 21 areas:Areas addressed include: language extensions, pointer type conversions, control flow, and standard librariesTotal of 122 rules + 20 advisoriesExample rule: (6.2) “Signed and unsigned char shall only be used for the storage and use of numeric values.”

Some compliance checks can be automatedTI’s TMS470/TMS570 C/C++ compiler will check 70% of the rulesRemaining rules require manual checks

Page 97: Fix Float Art

- 97 -

제1장 Introduction

Embedded System LabEmbedded System Lab

The separation btw specification and design facilitates the porting to new hardware platforms.

In a best-case scenario, only the adaptation of the hardware-specific design decisions will be required to accomplish this.

Modeling and Imp Guidelines

Page 98: Fix Float Art

- 98 -

제1장 Introduction

Embedded System LabEmbedded System Lab

The consistency of specification and design represents a basic problem in function development.

A variety of data and behavioral modeling tools support these design steps.

Tools also facilitate the definition of guidelines in the form of libraries of graphical modeling blocks, scaling recommendations, and naming conventions for variables, as well as formula libraries, data structures, and interpolation routines for characteristic curves and maps, memory segmentation, and so forth.

Modeling and Imp Guidelines

Page 99: Fix Float Art

- 99 -

제1장 Introduction

Embedded System LabEmbedded System Lab

References

J. Schauffele and T. Zurawka, Automotive Software Engineering: Principles, Processes, Methods, and Tools, 2003.