Skip to content

Instantly share code, notes, and snippets.

@maxdeliso
Created February 1, 2013 16:32
Show Gist options
  • Save maxdeliso/4692401 to your computer and use it in GitHub Desktop.
Save maxdeliso/4692401 to your computer and use it in GitHub Desktop.
restrict in c99
WITHOUT RESTRICT:
$ echo "void frob(unsigned char* first, unsigned char* second, unsigned int count) {
for(int i = 0; i < count; ++i ) {
first[i] = second[i];
}
}" | clang -cc1 -O3 -S -x c -std=c99 -
_frob:
testl %edx, %edx
je LBB0_2
LBB0_1:
movb (%rsi), %al
movb %al, (%rdi)
incq %rsi
incq %rdi
decl %edx
jne LBB0_1
LBB0_2:
ret
WITH RESTRICT:
$ echo "void frob(unsigned char* restrict first, unsigned char* restrict second, unsigned int count) {
for(int i = 0; i < count; ++i ) {
first[i] = second[i];
}
}" | clang -cc1 -O3 -S -x c -std=c99 -
.align 4, 0x90
_frob:
pushq %rax
testl %edx, %edx
je LBB0_2
decl %edx
incq %rdx
callq _memcpy
LBB0_2:
popq %rax
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment