Optimize Perl thread-local state access.
When casting between pointers and integers use intermediate ptrdiff_t.

On some 64-bit systems (notably Windows) long is still 32-bit so the
compiler could warn about different operand widths.