Mammals thrived long before dinosaurs died: study