') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Inline TLS field access for linux/osx x64/arm64 by kunalspathak · Pull Request #87082 · dotnet/runtime · GitHub
Skip to content

Inline TLS field access for linux/osx x64/arm64 - #87082

Merged
kunalspathak merged 88 commits into
dotnet:mainfrom
kunalspathak:tls_linux
Jul 6, 2023
Merged

Inline TLS field access for linux/osx x64/arm64#87082
kunalspathak merged 88 commits into
dotnet:mainfrom
kunalspathak:tls_linux

Conversation

@kunalspathak

@kunalspathakkunalspathak commented Jun 2, 2023

Copy link
Copy Markdown
Contributor

Extending #85619 and #82973 for linux.

movrdi,0x7FA9DB182F28 ; GOT descriptor address of `maxThreadStaticBlocks`movrax,0x7FA9DB7A5DB0 ; function address of __tls_get_addrcallrax ; gets the address of `maxThreadStaticBlocks`cmp dword ptr [rax],2jl SHORT G_M8151_IG06movrdi, qword ptr [rax+08H] ; access the `threadStaticBlocks` variablemovrdi, qword ptr [rdi+10H]testrdi,rdije SHORT G_M8151_IG06movrax, bword ptr [rdi]addrax,16

Base:

| Method | Mean | Error | StdDev | Median | Min | Max | Allocated |
|---------------- |---------:|----------:|----------:|---------:|---------:|---------:|----------:|
| GetThreadStatic | 3.383 ns | 0.0378 ns | 0.0316 ns | 3.374 ns | 3.346 ns | 3.459 ns | - |
| SetThreadStatic | 5.334 ns | 0.0733 ns | 0.0650 ns | 5.338 ns | 5.261 ns | 5.451 ns | - |

Diff:

| Method | Mean | Error | StdDev | Median | Min | Max | Allocated |
|---------------- |---------:|----------:|----------:|---------:|---------:|---------:|----------:|
| GetThreadStatic | 1.048 ns | 0.0200 ns | 0.0177 ns | 1.041 ns | 1.026 ns | 1.087 ns | - |
| SetThreadStatic | 2.844 ns | 0.0379 ns | 0.0354 ns | 2.837 ns | 2.807 ns | 2.915 ns | - | 

This also adds mrs instruction in arm64 to access TLS on linux. The codegen is:

G_M8151_IG02:  mrs x0, tpidr_el0 ldr w1,[x0, #0xE8] ; `maxThreadStaticBlocks` valuecmp w1, #2 blt G_M8151_IG05 ldr x0,[x0, #0xF0] ; `threadStaticBlocks` array ldr x1,[x0, #0x10] cbz x1, G_M8151_IG05G_M8151_IG03: mov w0, #5str w0,[x1, #0x24]

osx/arm64:

Because of register allocator doesn't reuse the x0 properly, we end up creating the same constant again in x1, but this is how osx/arm64 looks like:

 movz x0, #0x8C00 movk x0, #817LSL #16 movk x0, #1LSL #32 movz x1, #0x8C00 movk x1, #817LSL #16 movk x1, #1LSL #32 ldr x1,[x1] blr x1

osx/x64:

image

@ghostghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jun 2, 2023
@ghost

ghost commented Jun 2, 2023

Copy link
Copy Markdown

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Issue Details

Extending #85619 and #82973 for linux.

Author:kunalspathak
Assignees:-
Labels:

area-CodeGen-coreclr

Milestone:-

Comment threadsrc/coreclr/jit/helperexpansion.cpp Outdated
Comment threadsrc/coreclr/inc/corinfo.h Outdated
Comment threadsrc/coreclr/vm/jitinterface.cpp Outdated
Comment threadsrc/coreclr/vm/jitinterface.cpp Outdated
Comment threadsrc/coreclr/jit/helperexpansion.cpp
Comment threadsrc/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp Outdated
Comment threadsrc/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp Outdated
Comment threadsrc/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp Outdated
Comment threadsrc/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp Outdated
Comment threadsrc/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp Outdated
Comment threadsrc/coreclr/jit/helperexpansion.cpp Outdated
Comment threadsrc/coreclr/jit/helperexpansion.cpp Outdated
Comment threadsrc/coreclr/jit/helperexpansion.cpp Outdated
Comment threadsrc/coreclr/jit/helperexpansion.cpp Outdated
Comment threadsrc/coreclr/jit/helperexpansion.cpp Outdated
JITDUMP("offsetOfThreadLocalStoragePointer= %u\n", threadStaticBlocksInfo.offsetOfThreadLocalStoragePointer);
JITDUMP("offsetOfMaxThreadStaticBlocks= %u\n", offsetOfMaxThreadStaticBlocksVal);
JITDUMP("offsetOfThreadStaticBlocks= %u\n", offsetOfThreadStaticBlocksVal);
JITDUMP("tlsIndex= %u\n", (ssize_t)threadStaticBlocksInfo.tlsIndex.addr);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dump threadStaticBlocksInfo.tlsIndex.accessType also?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it will be useful? I don't see we print accessType elsewhere.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it will be useful? I don't see we print accessType elsewhere.

I don't know. Structurally, it seems odd to omit it. Up to you.

@ghostghost added needs-author-action An issue or pull request that requires more info or actions from the author. and removed needs-author-action An issue or pull request that requires more info or actions from the author. labels Jul 1, 2023
Comment threadsrc/coreclr/jit/gentree.cpp Outdated
Comment threadsrc/coreclr/jit/helperexpansion.cpp Outdated
Comment threadsrc/coreclr/jit/lsraarmarch.cpp Outdated
Comment threadsrc/coreclr/jit/lsraxarch.cpp Outdated
jakobbotsch
jakobbotsch previously requested changes Jul 3, 2023
Comment threadsrc/coreclr/jit/helperexpansion.cpp Outdated
Comment threadsrc/coreclr/jit/lsraxarch.cpp Outdated
@ghostghost added needs-author-action An issue or pull request that requires more info or actions from the author. and removed needs-author-action An issue or pull request that requires more info or actions from the author. labels Jul 3, 2023
@kunalspathak

Copy link
Copy Markdown
ContributorAuthor

Ping @BruceForstall

@BruceForstallBruceForstall left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM w/ one nit

Comment threadsrc/coreclr/jit/lsraarmarch.cpp Outdated
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@kunalspathak@jkotas@jakobbotsch@BruceForstall