Retirement tax questions

Let's say I contribute $8,000 to a qualified Roth 401(k), put it into a mutual fund, the value goes to $9,000, I'm 47 years old, the 401(k) is 3 years old, and a do a direct rollover to my Roth IRA. Do I add $9,000 to my Roth IRA basis?

 

From what I've read elsewhere on the Web, the answer must be yes. This is because earnings and contributions in a Roth 401(k) come out at the same time. Or let's say I contributed $40,000 total over a few years, and then transferred one mutual fund position valued at $12,000 (that includes some earnings in that position). Would I add $12,000 to my Roth IRA basis?