handcrafted loop unrolling, because gcc won't do it