Achieving Optimal Performance from C/C++ Source Code
Bad: possible alias of arrays
may be disambiguated by writing
int * restrict p = a;
int * restrict q = b;
for (i=0; i<100; i++)
*p++ = *q++;
Good:
restrict
not alias.
The
restrict
Using the Const Qualifier
By default, the compiler assumes that the data referenced by a pointer to
type will not change. Therefore, another way to tell the compiler
const
that the two arrays a and b do not overlap is to use the
void copy(short *a, const short *b) {
int i;
for (i=0; i<100; i++)
a[i] = b[i];
}
Good: pointers disambiguated via
The use of
const
pragma (see in
no_alias
implementation is better since it also allows the optimizer to use the
const
fact that accesses via a and b are independent in other parts of the code,
not just the inner loop.
In C, it is legal, though bad programming practice, to use casts to allow
the data pointed to by pointers to
avoided since, by default, the compiler will generate code that assumes
VisualDSP++ 3.5 C/C++ Compiler and Library Manual
for ADSP-219x DSPs
and
a
qualifier tells compiler that memory accesses do
keyword is particularly useful on function parameters.
in the above example will have a similar effect on the
"#pragma no_alias" on page
.
b
qualifier.
const
type to change. This should be
const
keyword.
const
2-36). In fact, the
2-23
Need help?
Do you have a question about the VISUALDSP++ 3.5 and is the answer not in the manual?
Questions and answers