TMS34010
C
Run-Time
Environment
5.1.2
Global
Variable
Memory
Allocation
Each
external
or
static variable declared in a C program
is
allocated
an
exclu-
sive contiguous space in memory by the compiler. Whereas the actual address
of
the space
is
decided by the linker, the codegen provides
that
the space is
always
allocated in multiples
of
words, and each variable is always aligned on
a
word
boundary.
5.1.3
Structure
Packing
and
Field
Manipulation
Structure elements are generally allocated space
as
needed
to
hold them.
Fields are allocated
as
many bits
as
requested, enumerated types
are
allocated
as
few
bits
as
possible
to
hold the maximum value
of
that
type, bytes are al-
located eight bits, and so on.
See
also
TMS34010
C .Data Sizes, page
4-3,
and Enumeration Declarations, page
4-6.
In the TMS3401 0, structure mapping is
done
according
~.o
standard C practice
with
one exception: a field
of
declared
width
zero does
not
cause a
word
alignment. Because
of
the GSP's bit-addressability,
word
alignment in a
structure does
not
necessarily produce more efficient code. However,
note
that
fields
which
straddle
word
boundaries
do
take longer
to
access since
both
words must be fetched
by
the processor; thus,
it
is
advisable
to
define struc-
tures and arrays
of
structures carefully
to
avoid fields
which
cross
word
boundaries.
If
a structure
is
declared
as
an
external
or
static variable, it
is
always placed
on a
word
boundary and
is
allocated space rounded up
to
a
word
boundary.
However,
when
an
array
of
structures
is
declared, no rounding
of
size
is
used:
exactly enough space
is
allocated
to
hold each structure element in
contig-
uous bits
of
memory.
5.1.4
Array
Alignment
In ANSI standard
C,
as
well
as
K&R C (Kernighan and Ritchie), arrays are
expected
to
always align their elements on a
word
boundary,
with
the excep-
tion
of
bytes,
which
may be aligned on a byte boundary. Because the
TMS34010
is
bit-addressable, this restriction becomes
both
unimportant and
inefficient. Thus, in
TMS34010
C,
arrays have no internal alignment. Each el-
ement
of
the array is allocated exactly
as
much space
as
needed
to
hold the
contents
with
no space between adjacent elements.
Note:
Like structures, a carefully defined array
(with
no
elements overlapping
word
boundaries)
will
allow
the program
to
run faster. In general, pixel
arrays are so aligned.
If
an
array
is
declared
as
an
external
or
static variable, the first element
of
the
array
is
placed
on
a
word
boundary and the array
is
allocated space rounded
up
to
a
word
boundarY:
This method
of
handling
an
array allows more control over the environment
than standard
C allows. Arrays
of
bits
or
pixels
are
now
directly accessible (a.
5-3