use a mask trick to speed up the square update