replace expensive modular arithmetics with non-constant values with logical AND (assuming that we pass power of 2 constants, of course)