While the EU regulation on this is not particularly clear, the Finnish immigration service lays it out crystal clear -- and it's (obviously?) the same across all Schengen countries:
If you have been granted a residence permit for Finland, you may travel in the Schengen area without a visa for up to 90 days in any 180 days period. When travelling you must have with you a passport and residence permit card, or a passport containing your residence permit.
It is reasonably clear by omission only: since it does not make your length of travel a function of your length of stay, the length of stay doesn't matter.
It finishes with:
The 90-day time limit concerns the total time spent in the Schengen area, not an individual country.
but this is still in the context of travel to the Schengen countries and is about the countries that are not Finland.
Finally, while bringing common sense to an immigration fight is not recommended, in this case it is applicable (very cautiously): a stay on a residence permit might be years long and you would not be able to travel at all if those days were counted.