Fortran is faster than C

20 views
Skip to first unread message

Federico Lucifredi

unread,
Mar 25, 2012, 7:43:31 PM3/25/12
to Computing Performance
Hello Computing Performance,

I have run into the issue of optimizing memory-copy operations in C
being interfered with by C's ability to have pointers to overlapping
memory areas at least twice in the past month, so I thought I'd point
to this essay I was reading yesterday in NYC:

http://beza1e1.tuxen.de/articles/faster_than_C.html

---
For example, consider the canonical memory copy (not memcpy from
stdlib.h!):
void* memcopy(void* dst, const void* src, size_t count) {
while (count--) *dst++ = *src++;
return dst;
}
Depending on the target architecture, a compiler might perform a lot
of optimizations with this code. For example, on a modern x86 with the
SSE instruction MOVDQU, it could copy 16 Byte blocks instead of 4 Byte
(sizeof(void*)). Unfortunately, no. Due to aliasing, dst could for
example be src+1. In this case, the result must be the first word *src
repeated count times at dst. The compiler is not allowed to use MOVDQU
due to the semantics of C...
---

the argument goes that since Fortran does not allow pointer
arithmetic, overlapping memory blocks in the language are not
possible, hence faster memory copies are possible. Regardless of
other merits of the essay (it has some weaknesses), it makes for a
good example of this issue.

Best -Federico
Reply all
Reply to author
Forward
0 new messages