mesa: convert a bunch of math macros to inline functions