Add new util.h header and move compat goop to it.

Also add some rotation/swap stuff there (it should be better optimised
than the crap we have now).