ZHCUCO7B December 2024 – November 2025 F29H850TU , F29H859TU-Q1
当指针作为函数参数传递时,在指针上使用“Restrict”关键字可以提高性能。通过对指针 p 的类型声明应用限制,编程器向编译器提供以下内容:
在 p 的声明范围内,只有 p 或基于 p 的表达式用于访问 p 指向的对象。
编译器可以利用这一点来生成更高效的代码。
Example:
void matrix_vector_product(float32_t *restrict A, float32_t *restrict b, int nr, int nc, float32_t *restrict c)
{
int i, j;
float32_t s;
for(i = nr -1; i >=0; i--)
{
s =c[i];
for(j = nc -1; j >=0; j--)
{
s = s +A[j*nr+i]*b[j];
}
c[i] = s;
}
}