Skip to content

Commit 4e76c21

Browse files
Update description and section title for clarity on the restrict keyword in C99
1 parent 644e7cf commit 4e76c21

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

content/learning-paths/cross-platform/restrict-keyword-c99/_index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ title: Understand the `restrict` keyword in C99
33

44
minutes_to_complete: 30
55

6+
description: Learn how to use the C99 restrict keyword to indicate non-overlapping memory regions and enable better compiler optimizations for vectorization on Arm platforms.
7+
68
who_is_this_for: This is an introductory topic for C developers who are interested in software optimization
79

810
learning_objectives:

content/learning-paths/cross-platform/restrict-keyword-c99/what-is-restrict.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ This doesn't look optimal. `scaleVectors` seems to be doing each load, multiplic
106106

107107
Unsurprisingly, the disassembled output of `scaleVectors` is the same. The reason for this is that the compiler has no hint about the dependency between the two pointers used in the function so it has no choice but to assume that it has to process one element at a time. The function has no way of knowing what arguments need to be called. We see 8 instances of `mul`, which is correct but the number of loads and stores in between indicates that the CPU spends its time waiting for data to arrive from/to the cache. We need a way to be able to tell the compiler that it can assume the buffers passed are independent.
108108

109-
## The Solution: restrict
109+
## The solution: restrict
110110

111111
This is what the C99 `restrict` keyword resolves. It instructs the compiler that the passed arguments are not dependent on each other and that access to the memory of each happens only through the respective pointer. This way the compiler can schedule the instructions in a much more efficient way. Essentially it can group and schedule the loads and stores.
112112

0 commit comments

Comments
 (0)