Gated XNOR Networks: Deep Neural Networks with Ternary Weights and Activations under a Unified Discretization Framework