LLVM and TLS

Dan Olson via digitalmars-d-ldc digitalmars-d-ldc at puremagic.com
Mon Feb 23 08:18:11 PST 2015


"Jonathan Marler" <johnnymarler at gmail.com> writes:

> Here's what happened: I was writing a program that could optionally
> use TLS memory.  When I turned on TLS memory it slowed down
> considerably, but only when using an LLVM compiler.  No matter how I
> used TLS, it was much much slower when using LLVM.

Hi Jonathan.

The reason for slowness on OS X is here in the source code on Apple's
website. A TLS has the extra cost of address lookup by a call to
_tlv_get_addr:

_tlv_get_addr:
	movq	8(%rdi),%rax			// get key from descriptor
	movq	%gs:0x0(,%rax,8),%rax	// get thread value
	testq	%rax,%rax				// if NULL, lazily allocate
	je		LlazyAllocate
	addq	16(%rdi),%rax			// add offset from descriptor
	ret
LlazyAllocate:
        ...

http://www.opensource.apple.com/source/dyld/dyld-210.2.3/src/threadLocalHelpers.s

--
Dan


More information about the digitalmars-d-ldc mailing list