HP shares yo-yoed Thursday amid reports that Xerox had made a cash and stock offer, a takeover that would combine two legacy tech companies that are struggling to reinvent themselves.

Xerox Holdings Corp. offered $22 a share — a 12.4 percent premium over Wednesday’s close — for its much larger rival, CNBC reported, citing unnamed sources. The bid is 77 percent cash and 23 percent stock and, if accepted, would generate about $2 billion in cost savings and give HP shareholders ownership of about 48 percent of the company CNBC reported.

HP shares were up nearly 2 percent by midmorning, but fell to $19.39 at market close. Xerox, which initially spiked more than 2 percent, was trading down and closed at $37.32.

Xerox and HP did not immediately respond Thursday to requests for comment from The Post. The reported offer comes one day after HP confirmed it held talks this week with Xerox over a “potential business combination.”

One of the more unusual aspects of the bid is size: HP is nearly four times larger than Xerox, with a market cap hovering near $29.2 billion versus $8.4 billion for Xerox.

HP, known primarily for its printers and computers, said in a statement on its website it received a proposal from Xerox on Tuesday. It stressed it has confidence in its strategy and path forward, something against which it was weighing the talks — and “what would be required to merit a transaction.”

“We have a record of taking action if there is a better path forward and will continue to act with deliberation, discipline and an eye toward what is in the best interest of all our shareholders,” the company said in the statement.

HP has struggled to find a viable model to move beyond its profitable printing business as customers shift toward digitization. Last month, it said it expected to lose between 7,000 and 9,000 employees through a combination of layoffs and voluntary early retirements.

Still, its third-quarter earnings beat analyst expectations. The company reported net revenue of $14.6 billion, an increase of 0.1 percent compared to the year prior.

The digital age has also taken its toll on Xerox, whose name has become synonymous with the copying machines that became popular in the 1950s.

The confirmation comes a few days after HP’s president and CEO, Dion Weisler, stepped down from the company due to a family health matter. He was replaced by Enrique Lores, formerly the head of the company’s printing and imaging division.

“The opportunities ahead are vast and the need for us to keep reinventing is more important than ever,” Lores said in a statement when the succession plan was announced.

Correction: HP says it has held talks with Xerox. The headline on a previous version of the story said it is in talks.