Thermodynamic stability of hexagonal and cubic ices