In this lab we are looking at the assembly code in an open source package. I chose the mjpegtools package, which is a package for working with mjpeg video.
Lets begin by looking at how much assembler there is and where it is.
Running this command will find any asm files.
find . -name ‘*.[sS]’
In this project there are no assembly files. So any assembler will be inline.
These command will find any inline assembler.
egrep -R “__asm” *
egrep -R “asm *\(“ *
This package has a bit of both inline assembler syntaxes. In total there are 26 assembly blocks in the package.
Most of these are in utils/mmx.h.
Looking in this file we do not see a means of doing platform selection.
So we will search for platform references.
egrep -Ri "x86" *
We can see in many places in the code the following block.
This flag comes from the configure script.
The configure script gathers cpu info and uses the asm code in cpuinfo.c in order to decide what optimizations to use. On supported platforms it will use cpu_accel mmx, and other optimized routines.
Assembler code like this is worth the extra effort to maintain portability. As it gathers low level cpu info and lets the code be configured for the greatest performance on a system. In a package like this, dealing with streaming data it is critical the code is as performant as possible.