Shares of Advanced Micro Devices (AMD 2.37%) and Taiwan Semiconductor Manufacturing (TSM 1.26%) have both doubled over the past 12 months. AMD dazzled investors with robust sales of its CPUs and GPUs. TSMC, the world's largest contract chipmaker, benefited from soaring orders for new chips.

Both companies profited from Intel's (INTC -9.20%) misfortunes. Intel's chip shortage, which was caused by a difficult jump from 14nm to 10nm chips, caused PC makers to buy more AMD chips.

Intel's own foundry also fell behind TSMC in the "process race" to create smaller and more power-efficient chips. That failure allowed AMD, which outsources its chip production to TSMC, to produce more advanced chips.

A wafer of chips being manufactured.

Image source: Getty Images.

That's why AMD and TSMC both easily outperformed Intel, which lost more than 10% of its value over the past 12 months, as well as the benchmark Philadelphia Semiconductor Index, which advanced nearly 60%. Let's take a fresh look at both chipmakers to see which stock is the better buy.

The differences between AMD and TSMC

AMD is a fabless chipmaker that doesn't manufacture its own chips like Intel. It develops x86 CPUs for PCs and servers, GPUs, and other types of custom chips, but a foundry like TSMC manufactures the chips.

AMD competes against Intel in the x86 CPU market and NVIDIA (NVDA 6.18%) in the discrete GPU market. AMD controlled 39.8% of the x86 CPU market in the first quarter of 2021, according to PassMark, up from 33.2% a year ago. Intel's share tumbled from 66.7% to 60.2%.

AMD faces a tougher battle against NVIDIA. Its share of the add-in GPU board market dipped from 27% to 23% between the third quarters of 2019 and 2020, according to a report from Jon Peddie Research. NVIDIA's share of the market grew from 73% to 77%. AMD also produces CPUs and custom GPUs for Sony and Microsoft's latest gaming consoles.

TSMC produces chips for many other customers besides AMD, including Apple (AAPL -0.35%), Qualcomm, and NVIDIA. Last quarter, it generated 46% of its revenue from smartphone chips, 37% from HPC (high-performance computing) chips, 9% from Internet of Things (IoT) chips, and the rest from other markets.

In terms of process, 35% of TSMC's revenue came from its current-gen 7nm node. Another 8% came from its next-gen 5nm chips, which just entered mass production last year. The rest of TSMC's revenue came from older chips.

TSMC's only meaningful competitor in the high-end foundry market is Samsung, which also started producing 5nm chips last year. In the low-end market, it competes against smaller and less advanced rivals like GlobalFoundries and UMC.

Which chipmaker is growing faster?

AMD's revenue rose 4% in fiscal 2019 as its adjusted earnings grew 39%. In the first nine months of 2020, its revenue surged 42% year over year -- with 47% growth in its computing and graphics business and 31% growth in its enterprise, embedded, and semi-custom (EESC) business -- and its adjusted earnings soared 141%.

A desktop PC with an open case.

Image source: Getty Images.

AMD attributed that growth to robust sales of its Ryzen CPUs and Radeon GPUs in its computing and graphics segment, with remote work and stay-at-home trends sparking sales of new PCs, and healthy demand for its EPYC data center chips in the EESC segment.

Analysts expect AMD's revenue and earnings to rise 42% and 92%, respectively, for the full year. Next year, they expect its revenue and earnings to grow 27% and 47%, respectively.

AMD might face tougher year-over-year comparisons after the pandemic passes, but the underlying tailwinds remain strong. Strong sales of the PS5 and Xbox Series X and S consoles could also boost its EESC revenue and offset a slowdown in its PC-oriented CPU and GPU businesses.

TSMC's revenue rose 4% in fiscal 2019, but its earnings dipped 2% as it grappled with a slowdown in the saturated smartphone market. It also got off to a rough start in 2020 as the pandemic disrupted the production of chips for smartphones and connected cars. New restrictions against the Chinese tech giant Huawei, which relied on TSMC to produce its in-house chips, exacerbated the pain.

Despite all those challenges, TSMC's revenue still rose 30% year over year in the first nine months of 2020 as orders from top customers like Apple and Qualcomm flowed in, and its earnings surged 64%. Analysts expect its revenue and earnings to rise 36% and 60%, respectively, for the full year.

Next year, analysts expect TSMC's revenue and earnings to rise 16% and 12%, respectively, as those orders cool off. However, new orders from Apple, which is replacing Intel's CPUs with its own TSMC-produced chips; the growth of the HPC market; and even outsourced orders from Intel could help it top analysts' expectations next year.

The better buy: AMD

AMD and TSMC are still both great long-term investments on the semiconductor market. But AMD is generating stronger growth with fewer moving parts, and its stock isn't too expensive at about 50 times forward earnings.

TSMC's stock seems cheaper at about 30 times forward earnings, but it's a broader and more diversified play on the entire sector. Its growth could decelerate as softer segments -- like smartphones and automotive chips -- overwhelm its higher-growth HPC business. Therefore, I believe AMD is a slightly better buy than TSMC.