http://lxr.linux.no/ provides cross-referenced search of Linux kenrel code. [There are many articles and blogposts explaining the Linux kernel tree in a nutshell, e.g., http://www.linuxchix.org/content/courses/kernel_hacking/lesson6 Feel free to post to the class list any good ones you find! ] Through various major kernel versions, one can see the trends towards hand-optimized assembly and back to trusting the compiler. [For an intro to x86 assembly, see "A Tiny Guide to Programming in 32-bit x86 Assembly Language" by Adam Ferrari, in the course directory.] [For an intro to x86 history, endianness and assembly features, read http://www.cs.dartmouth.edu/~sergey/cs108/solaris-on-x86.pdf by Frank Hoffman: page 9-18 for platform history, 19-20 for general interest, page 24-33 about assembly, and all around these as you please. This is a remarkable book, sadly unfinished AFAIK. Mind the slogan on page 6, it may as well be one for this class!] Today's GCC inline assembly example was at the top of: http://lxr.linux.no/#linux+v3.2/arch/x86/include/asm/string_64.h [Skim through examples of simple GCC inline assembly at http://ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html#s3 or http://www.delorie.com/djgpp/doc/brennan/brennan_att_inline_djgpp.html to get the hang of the syntax, then refer back to them as you read the following:] Examine the 32bit version and its C case-by-case logic: http://lxr.linux.no/#linux+v3.2/arch/x86/include/asm/string_32.h [Make sure you read and understand it.] You can also look at an older kernel's many hand-coded assembly routines: http://lxr.linux.no/#linux-bk+v2.6.11.5/include/asm-i386/string.h Our next topic: system calls. ============================================================================= Suggested homework: experiment with compiling various string copy routines, and see which work fastest on your system. Look at the disassembly of compiled code. Use the "time" command to time your code (you will need to execute your loops in 100s or 1000s to get a proper measurement of what they take on average, of course). ============================================================================= Miscellaneous: Some useful commands: gcc -E hello.c | grep size_t [see http://en.wikipedia.org/wiki/C_data_types about standard data types I don't really know :) and use this trick to find out.] gcc -o hello hello.c VS gcc -O2 -o hello hello.c objdump -d hello | less +/main [disassemble all code sections and search for the first occurance of "main"] [If you haven't encountered "find" and "xargs" before, by all means do https://www.google.com/search?q=find+xargs and read the first five matches, e.g., http://www.cyberciti.biz/faq/linux-unix-bsd-xargs-construct-argument-lists-utility/ http://www.hcidata.info/find.htm http://www.infoanda.com/resources/find.htm http://www.linuxplanet.com/linuxplanet/tutorials/6522/1 and, of course, "man find" and "man xargs"]