Improvement from precomputing row masks