When KMP_AFFINITY is set, each thread's gtid value is used as an index into the place list to determine the thread's placement. With hidden helpers enabled, this gtid value is shifted down leading to unexpected shifted thread placement. This patch restores the previous behavior by adjusting the mask index to take the number of hidden helper threads into account.
Hidden helper threads are given the full initial mask and do not participate in any of the affinity mechanisms besides the initial affinity assignment.