TOKYO, May 25 (Reuters) - Japan's Nikkei share average clawed back lost ground on Thursday after two consecutive sessions of losses, supported by chip-related companies on earnings optimism and robust inflows from foreign investors.

Chip-testing equipment maker Advantest Corp soared 16.22%, leading the semiconductor sub-index after a blockbuster earnings forecast by U.S.-based chipmaker Nvidia Corp.

Rakuten Group Inc climbed 0.68% after the online retailer priced a new share offering to fund its mobile expansion.

The Nikkei advanced 0.4% to close at 30,801.13. Earlier this week, the index touched 31,352.53, its highest since August 1990. The broader Topix slid 0.3% to 2,146.15.

Japanese stocks outperformed other major markets recently, underpinned by strong corporate earnings, increased chip investment, and optimism for a consumer sector tailwind as the country reopens from the pandemic.

Foreign investors bought a net 867.5 billion yen ($6.42 billion) of Japanese shares in the week ended May 20, an eight straight week of inflows, Finance Ministry data showed.

"Foreign investors are buying Japanese equities instead of U.S. equities because economic conditions are not good in the U.S. due to the banking problems, financial tightening, and the debt ceiling issue," said Masayuki Kubota, chief strategist at Rakuten Securities. "But in Japan, as the country reopens, the service sector is looking very strong now."

"Manufacturing, in particular the semiconductor industry, is picking up," he added.

Japan's southern prefecture of Kumamoto is becoming a hotbed of chip activity, with Sony Group Corp announcing that its semiconductor subsidiary would buy land there to expand production of image sensors.

Shares of Advantest Corp staged their steepest climb since July 2019 and scaled a record high. Chip-equipment maker Tokyo Electron Ltd jumped 3.01%.

There were 149 decliners in the Nikkei versus 71 that gained ground. Financial shares were the biggest drags.

Among decliners in the broader market, shares of Riberesute Corp plunged 10.9% after the real estate developer said its president was arrested on Wednesday on suspicion of violating moneylending regulations.

(Reporting by Rocky Swift in Tokyo; Editing by Sonia Cheema and Sherry Jacob-Phillips)