xref: /illumos-gate/usr/src/lib/libc/amd64/threads/tls_get_addr.S (revision 34bbc83afbf22a6f8e504cb99d76c97c017cb5f4)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26	.file	"tls_get_addr.s"
27
28/*
29 * To make thread-local storage accesses as fast as possible, we
30 * hand-craft the __tls_get_addr() function below, from this C code:
31 * void *
32 * __tls_get_addr(TLS_index *tls_index)
33 * {
34 *	ulwp_t *self = curthread;
35 *	tls_t *tlsent = self->ul_tlsent;
36 *	ulong_t moduleid;
37 *	caddr_t	base;
38 *
39 *	if ((moduleid = tls_index->ti_moduleid) < self->ul_ntlsent &&
40 *	    (base = tlsent[moduleid].tls_data) != NULL)
41 *		return (base + tls_index->ti_tlsoffset);
42 *
43 *	return (slow_tls_get_addr(tls_index));
44 * }
45 *
46 * ___tls_get_addr() is identical to __tls_get_addr() except that it
47 * assumes its argument is passed in %eax rather than on the stack.
48 */
49
50#include "SYS.h"
51#include <../assym.h>
52
53	ENTRY_NP(__tls_get_addr)
54	ALTENTRY(___tls_get_addr)
55	movq	%fs:UL_TLSENT, %rax
56	movq	TI_MODULEID (%rdi), %rdx
57	cmpq	%fs:UL_NTLSENT, %rdx
58	jae	slow_tls_get_addr	/* tail call */
59	/* movq	TLS_DATA (%rax,%rdx,SIZEOF_TLS_T), %rax */
60	shlq	$4, %rdx	/* SIZEOF_TLS_T == 16 */
61	movq	TLS_DATA (%rax,%rdx), %rax
62	testq	%rax, %rax
63	je	slow_tls_get_addr	/* tail call */
64	addq	TI_TLSOFFSET (%rdi), %rax
65	ret
66	SET_SIZE(___tls_get_addr)
67	SET_SIZE(__tls_get_addr)
68