Infer function from 3d plot
I think it should be something proportional to $n\cdot m\cdot \max(m,n)$. By using the xor operation, you are basically shuffling bits around, without changing the number of ones and zeros. So your sum is on average the number of cells in your matrix ($n\cdot m$) times the average value of your cell, which should be proportional to $\max(m,n)$.
This is not a proof, just an intuition which you can check with python.