UCR CS122B, Winter 2001, T. Givargis and F. Vahid
This will be a two week lab. A lecture on the
Trimedia chip and how to proceed will be given during the first
hour of the first week. Do not miss it!
Lab prepared by J. Villarreal and T. Givargis.
Setup Documentation
Click Here
Problem
The NTSC (National Television Standards Committee) is a standard
protocol for TV signals in the US. An NTSC TV image has 525 horizontal
lines per frame, which are scanned from left to right, and from top to
bottom. To reduce the amount of data that must be sent, each frame is
sent and displayed in two halves, the odd lines, followed by the even lines.
Each halve-frame scans in approximately 1/60 of a second, so a complete
frame is scanned every 1/30 second. Such interlacing occurs
so quickly that humans can't see it happening.
However, PC monitors do not perform such interlacing, instead
displaying progressive pictures where each frame contains all the lines,
so one must perform scan rate conversion if one wants to display a
standard video signal onto a PC monitor. In order to display an NTSC
picture on the PC monitor, first the picture must be de-interlaced.
The algorithm that you will be using to de-interlace the
picture so it can be displayed on the monitor is the median
filter algorithm. In this algorithm, pixels in the missing
lines are filled in by taking the median of two pixels from the
neighboring lines in the current field and one pixel from the
same vertical position from the previous frame.
A simple median filter algorithm is given to you to begin with
in the file median.c below. The simple algorithm generates the correct
output, but is too slow, and so doesn't display the picture properly.
This is an example of a real-time algorithm. You need to be optimize
the algorithm to display fast enough. Your job will be to
optimize this function for the TriMedia
(www.trimedia.com)
processor so that an
interlaced picture from a DVD player can be displayed on the
PC monitor correctly. You'll be using the TriMedia development tools,
and testing your algorithms on a real TriMedia processor.
Details of the TriMedia environment will be given in lab.
The algorithm is an example of media processing, a class of applications
becoming extremely common with the growth of audio and video business
and consumer electronics applications. Special microprocessors, known
as media processors , have evolved to meet the unique needs
of media processing, which different from general-purpose PC processing
needs. Among other things, media processors contain special hardware
to perform common media processing operations much more quickly.
These sped-up operations can be accessed by C-level library calls.
Trimedia, a spinoff of Philips, licenses one of the most popular such
media processors.
Procedure
- Think
- Modify median.c to run faster.
- Compile and test
- Go back to step 1
Function
The function that you will need to modify is as follows:
void median_filter(pixel_t* input, pixel* prev_input,
pixel_t* output, const int pixelsPerLine,
const int linesPerField, const int field)
The arguments are as follows:
- input -- An array of pixels that correspond to one set of interlaced lines.
- prev_input -- An array of pixels that correspond to the previous set of
interlaced lines.
- output -- This will be the set of pixels that correspond to the
complete picture.
- pixelsPerLine -- The number of pixels per line.
- linesPerField -- The number of lines per field.
- field -- Which field we are processing (1=odd, 0=even).
Things to consider
- Custom Operations -- Using the built-in hardware instructions of the TriMedia
processor as opposed to straight C-code will improve the
speed of your algorithm.
- Loop improvements -- Cleaning up the loops and removing any unecessary
instructions will improve your execution time. Unrolling the
loop might also be helpful.
- Load/Store activity -- Parallelizing load store activity will reduce the time.
- Cache behavior -- Prefetching correctly will reduce the number of data stalls
dramatically.
Custom Operations
All of custom operations use "unsigned int" as arguments. The
following are all of the operations you might find useful:
- IMAX(a, b) -- The integer maximum between a and b
- IMIN(a, b) -- The integer minimum between a and b.
- IABS(a) -- The absolute value of a.
- INEG(a) -- The negation of a.
- BITANDINV(a, b) -- Compute the bitwise, logical and of the first argument with
the one's complement of the second argument.
- ROL(a, b) -- Rotate a left b times.
- SEX8(a) -- Sign extend eight bits.
- SEX16(a) -- Sign extend sixteen bits.
- ZEX8(a) -- Zero extend eight bits.
- ZEX16(a) -- Zero extend sixteen bits.
- ASLI(shift, a) -- Arithmetic shift left immediate.
- ROLI(shift, a) -- Rotate left immediate.
- ASRI(shift, a) -- Arithmetic shift right immediate.
- LSRI(shift, a) -- Logical shift right immediate.
- LSLI(shift, a) -- Logical shift left immediate.
- IADDI(imm, a) -- Integer add with immediate.
- ISUBI(imm, a) -- Integer subtract with immediate.
- IGTRI(imm, a) -- Signed compare greater than with immediate.
- IGEQI(imm, a) -- Signed compare greater than or equal to with immediate.
- IEQLI(imm, a) -- Signed compare equal with immediate.
- INEQI(imm, a) -- Signed compare not equal with immediate.
- ILESI(imm, a) -- Signed compare less with immediate.
- ILEQI(imm, a) -- Signed compare less than or equal to with immediate.
- UGTRI(imm, a) -- Unsigned compare greater than with immediate.
- UGEQI(imm, a) -- Unsigned compare greater than or equal to with immediate.
- UEQLI(imm, a) -- Unsigned compare equal with immediate.
- UNEQI(imm, a) -- Unsigned compare not equal with immediate.
- ULESI(imm, a) -- Unsigned compare less than immediate.
- ULEQI(imm, a) -- Unsigned compare less than or equal to immediate.
- DSPIADD(a, b) -- Clipped signed add.
- DSPISUB(a, b) -- Clipped signed subtract.
- DSPUSUB(a, b) -- Clipped unsigned subtraction.
- DSPIMUL(a, b) -- Clipped signed multiplication.
- DSPUMUL(a, b) -- Clipped unsigned multiplication.
- DSPIABS(a) -- Clipped absolute value.
- CARRY(a, b) -- Compute carry bit from unsigned add.
- BORROW(a, b) -- Compute borrow bit from unsigned subtract.
- IMULM(a, b) -- Signed multiply, return most-significant 32 bits
- UMULM(a, b) -- Unsigned multiply, return most-significant 32 bits.
- DSPIDUALABS(a) -- Dual clipped absolute value of signed 16-bit halfwords.
- DSPIDUALADD(a, b) -- Dual clipped add of signed 16-bit halfwords.
- DSPIDUALSUB(a, b) -- Dual clipped subtraction of signed 16-bit halfwords.
- DSPIDUALMUL(a, b) -- Dual clipped multiplication of signed 16-bit halfwords.
- DUALASR(a, b) -- Dul 16 arithmetic shift right.
- PACKBYTES(a, b) -- Pack least significant byte. (returns lsbs of a:b)
- MERGEMSB(a, b) -- Merge most significant bytes.
- MERGELSB(a, b) -- Merge least significant bytes.
- PACK16MSB(a, b) -- Pack 16 most significant bits.
- PACK16LSB(a, b) -- Pack 16 least significant bits.
- MERGEDUAL16LSB(a, b) -- Merge dual 16 bit least significant bytes.
- UBYTESEL(a, sel) -- Select unsigned byte.
- IBYTESEL(a, sel) -- Select signed byte.
- UFIR8UU(a, b) -- Unsigned sum of products of unsigned bytes.
- IFIR8UI(a, b) -- Signed sum of products of unsigned/signed bytes.
- IFIR8IU(a, b) -- Signed sum of products of signed/unsigned bytes.
- IFIR8II(a, b) -- Signed sum of products of signed bytes.
- IFIR16(a, b) -- Sum of products of signed 16-bit halfwords.
- UFIR16(a, b) -- Sum of products of unsigned 16-bit halfwords.
- UME8II(a, b) -- Unsigned sum of absolute values of signed 8-bit differences.
- UME8UU(a, b) -- Sum of absolute values of unsigned 8-bit differences.
- FUNSHIFT1(a, b) -- Funnel-shift 1 byte.
- FUNSHIFT2(a, b) -- Funnel-shift 2 bytes.
- FUNSHIFT3(a, b) -- Funnel-shift 3 bytes.
- ICLIPI(a, b) -- Clip signed to signed.
- UCLIPI(a, b) -- Clip signed to unsigned.
- UCLIPU(a, b) -- Clip unsigned to unsigned.
- QUADUMULMSB(a, b) -- Unsigned quad 8-bit multiply most significant.
- QUADAVG(a, b) -- Unsigned byte-wise quad average.
- DSPUQUADADUI(a, b) -- Quad clipped add of unsigned/signed bytes.
- QUADUMAX(a, b) -- Unsigned byte-wise quad maximum.
- QUADUMIN(a, b) -- Unsigned byte-wise quad minimum.
- IZERO(a, b) -- If zero, select zero.
- INONZERO(a, b) -- If nonzero, selecgt non-zero.
- IAVGONEP(a, b) -- Signed average.
- IFLIP(a, b) -- If non-zero, negate.
- COPYBACK(a, n) -- Copy back to memory location a, n bytes.
- INVALIDATE(a, n) -- Invalidate in the cache address a for n bytes.
- PREFETCH(a, n) -- Prefetch n blocks (1 block = 64 bytes) starting
at a into the cache.
- ALLOCATE(a, n) -- Allocate n bytes in the cache starting at a.
- MUX(a, b, c) -- If a is true, return b, otherwise return c.
File
median.c
median.h
ooti.tar.gz