The galaxy stellar mass function at 3.5 ≤z ≤ 7.5 in the CANDELS/UDS, GOODS-South, and HUDF fields