SMS dit: Stable and efficient computation of generalized polar decompositions