I made a some changes a few weeks back that greatly simplified code optimization, so I thought I would share. The first was to build a compiler with more detailed output, and the second was to get Gnu Octave up and running on Xcode 5.1.1, OSX 10.9.2 since I wanted to see the results and costs of the auto-vectorizor in LLVM/Clang, and you don’t have the option to do that using the stock Apple release build.
Building the compiler was a fairly simple (although LONG) process, and it took some massaging along the way. Since I used Homebrew , it was really just as easy as typing ‘brew install llvm’ with the relevant option flags (you need the debug version for the output I wanted to see) and then fixing files along the way at it choked on various parts of the build and install process. It was much more difficult and hackey to get the compiler linked into Xcode, but I eventually got it working with the help of some internet sleuthing.
I used this plugin and these instructions as the basis for the XCode plugin hacking (but with Homebrew not MacPorts), XCode 5.1.1 and LLVM 3.4… I also used TextWrangler with sudo privileges in place of vi because life is too short for command line text editors). It took an evening of fiddling, but now I can view the auto-vectorizor output, which is incredible helpful when tweaking code for efficiency (I was able to vastly increase the efficiency of a few plugins I have been working on with about an hour of tweaking the loops and checking against the output).
Here is a sample shot of the output using the compiler flags ‘-mllvm -debug-only=loop-vectorize’ showing a loop that failed to vectorize:
The second addition was Gnu Octave (Matlab workalike) which opened a whole new world of fun. Suddenly, calculating coefficients went from a nightmare to a breeze. I used Homebrew for that as well, added the signal package and dependencies, and after a few hours of hacking to get it to compile… it was up and running and calculating filter coeffs for an upsampling algo.
Here is the obligatory sombrero plot screenshot:
So as a quick example, to get the second-order coeffs for a string of seven biquads to build an elliptic filter, you would run:
[B,A] = ellip(14,1,500,0.333);
[co] = tf2sos(B, A)
And this would be the result: