Machado’s 3-run homer gives Padres dramatic win over Giants