0% found this document useful (0 votes)
21 views

Lecture 7 - Programming Issues

The document provides an introduction to key programming issues in embedded systems, including variable declaration types, arithmetic operations, lookup tables, fixed point programming, and pipelining. It then discusses implementing a codec using fixed point arithmetic by precomputing cosine values in a lookup table to improve efficiency over floating point operations. Analysis shows the fixed point implementation reduces execution time and energy consumption compared to a floating point version.

Uploaded by

teddy tigabu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Lecture 7 - Programming Issues

The document provides an introduction to key programming issues in embedded systems, including variable declaration types, arithmetic operations, lookup tables, fixed point programming, and pipelining. It then discusses implementing a codec using fixed point arithmetic by precomputing cosine values in a lookup table to improve efficiency over floating point operations. Analysis shows the fixed point implementation reduces execution time and energy consumption compared to a floating point version.

Uploaded by

teddy tigabu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Introduction to Embedded Systems

Programming Issues

Getachew Teshome (Room 120-B)


Addis Ababa University, AAIT
School of Electrical and Computer Engineering
December 2022
1. Variable Declaration
2. Operations
3. Look up Tables/ Pre-computed Values
4. Fixed Point Programming
5. Pipelining
1. Variable Declaration
1. Double, float, int, short, uint8
2. Operations
1. * + >
3. Look up Tables/ Pre-computed Values
1. Eg 0C 0F
2. Trignometry
double
cos_taylor_literal_4terms_n
aive(double x)
{ return 1 - ((x*x)/(2)) +
((x*x*x*x)/(24)) -
((x*x*x*x*x*x)/(720)) +
((x*x*x*x*x*x*x*x)/(40320));
}
Fixed Point Programming
Implementation 2:
Microcontroller and CCDPP
• Analysis of implementation 2
– Total execution time for processing one image:
• 9.1 seconds
– Power consumption:
• 0.033 watt
– Energy consumption:
• 0.30 joule (9.1 s x 0.033 watt)
– Total chip area:
• 98,000 gates
5
Implementation 3: Microcontroller
and CCDPP/Fixed-Point DCT

• Analysis of implementation 3
– Use same analysis techniques as implementation 2
– Total execution time for processing one image:
• 1.5 seconds
– Power consumption:
• 0.033 watt (same as 2)
– Energy consumption:
• 0.050 joule (1.5 s x 0.033 watt)
• Battery life 6x longer!!
– Total chip area:
6
• 90,000 gates
• 8,000 less gates (less memory needed for code)
DCT floating-point cost
• Floating-point cost
– DCT uses ~260 floating-point operations per pixel transformation
– 4096 (64 x 64) pixels per image
– 1 million floating-point operations per image
– No floating-point support with Intel 8051
• Compiler must emulate
– Generates procedures for each floating-point operation
» mult, add
– Each procedure uses tens of integer operations
– Thus, > 10 million integer operations per image
– Procedures increase code size
• Fixed-point arithmetic can improve on this

7
Fixed-point arithmetic
• Integer used to represent a real number
– Constant number of integer’s bits represents fractional portion of real number
• More bits, more accurate the representation
– Remaining bits represent portion of real number before decimal point
• Translating a real constant to a fixed-point representation
– Multiply real value by 2 ^ (# of bits used for fractional part)
– Round to nearest integer
– E.g., represent 3.14 as 8-bit integer with 4 bits for fraction
• 2^4 = 16
• 3.14 x 16 = 50.24 ≈ 50 = 00110010
• 16 (2^4) possible values for fraction, each represents 0.0625 (1/16)
• Last 4 bits (0010) = 2
• 2 x 0.0625 = 0.125
• 3(0011) + 0.125 = 3.125 ≈ 3.14 (more bits for fraction would increase accuracy)

8
Fixed-point arithmetic
• Addition
operations
– Simply add integer representations
– E.g., 3.14 + 2.71 = 5.85
• 3.14 → 50 = 00110010
• 2.71 → 43 = 00101011
• 50 + 43 = 93 = 01011101
• 5(0101) + 13(1101) x 0.0625 = 5.8125 ≈ 5.85
• Multiply
– Multiply integer representations
– Shift result right by # of bits in fractional part
– E.g., 3.14 * 2.71 = 8.5094
• 50 * 43 = 2150 = 100001100110
• >> 4 = 10000110
• 8(1000) + 6(0110) x 0.0625 = 8.375 ≈ 8.5094
• Range of real values used limited by bit widths of possible resulting values

9
Fixed-point implementation of
CODEC
• COS value used extensively.
a= b*cos q a and b are fractions static unsigned char C(int h) { return h ? 64 :
ONE_OVER_SQRT_TWO;}
static int F(int u, int v, short img[8][8]) {
long s[8], r = 0;
unsigned char x, j;
for(j=0; j<8; j++) for(x=0; x<8; x++) {
s[x] = 0;
s[x] += (img[x][j]*COS_TABLE[j][v]) for(j=0; j<8; j++)
s[x] += (img[x][j] * COS_TABLE[j][v] ) >> 6;
>> 6; }
for(x=0; x<8; x++) r += (s[x] * COS_TABLE[x][u]) >> 6;
return (short)((((r * (((16*C(u)) >> 6) *C(v)) >> 6))
>> 6) >> 6);
}

static const char code COS_TABLE[8][8] = {


{ 64, 62, 59, 53, 45, 35, 24, 12 },
{ 64, 53, 24, -12, -45, -62, -59, -35 },
• Build COS_TABLE { 64, 35, -24, -62, -45, 12, 59, 53 },
{ 64, 12, -59, -35, 45, 53, -24, -62 },
Eg. 8-bit fixed-point with 6 bits for fraction {
{
64, -12, -59,
64, -35, -24,
35, 45, -53,
62, -45, -12,
-24,
59,
62
-53
},
},
{ 64, -53, 24, 12, -45, 62, -59, 35 },
{ 64, -62, 59, -53, 45, -35, 24, -12 }
};

10
Pipelining

You might also like