The 35-year-old Swiss, who has already won the Australian Open and Indian Wells so far this year, extended his win streak over Berdych to seven matches.
There was plenty of tension in the match-deciding tie-breaker, where Federer saved match point and then Berdych lost on a double-fault.
"I definitely got very lucky at the end, but I think I showed great heart today," Federer said. "I fought and Tomas definitely started to step it up, but it was a great match at the end."
Federer will face Nick Kyrgios in the semifinals after the Australian came through an entertaining 6-4, 6-7 (9/11), 6-3 victory over 19-year-old German Alexander Zverev.
Federer next will play the winner of Thursday's later quarterfinal between two of the ATP's up and coming stars, Australia's Nick Kyrgios and Germany's Alexander Zverev.