In-place matrix packing