Optimize granularity layer

@mortenvp I managed to optimize the calculations in the granularity layer. Encoding benchmark for multiply_add improves from 550 MB/s to 640 MB/s.
I included the check-doxygen commits here, so we can delete both branches when we merge.