STINNER Victor <vstin...@python.org> added the comment:

PR 23976 stores the currrent interpreter and the current Python thread state 
into a Thread Local Storage (TLS) using GCC/clang __thread keyword.

On x86-64 using LTO and GCC -O3, _PyThreadState_GET() and 
_PyInterpreterState_GET() become a single MOV.

Assembly code using LTO and gcc -O3.

_PyThreadState_GET() in _PySys_GetObjectId():

   0x00000000004adabe <+14>: mov rbx,QWORD PTR fs:0xfffffffffffffff8

_PyThreadState_GET() in PyThreadState_Get():

   0x000000000046b660 <+0>: mov  rax,QWORD PTR fs:0xfffffffffffffff8

_PyInterpreterState_GET() in PyTuple_New():

   0x000000000048dfcc <+12>: mov  rax,QWORD PTR fs:0xfffffffffffffff0

_PyInterpreterState_GET() in PyState_FindModule():

   0x000000000044bf20 <+16>: mov  rax,QWORD PTR fs:0xfffffffffffffff0

---

Note: Without LTO, sometimes there is an indirection:

_PyThreadState_GET() in _PySys_GetObjectId(), 2 MOV (PIC indirection):

   mov    rax,QWORD PTR [rip+0x1eb270]        # 0x713fe0
   # rax = 0xfffffffffffffff0 (-16)
   mov    r13,QWORD PTR fs:[rax]

_PyInterpreterState_GET() in PyTuple_New(), 2 MOV (PIC indirection):

  mov    rax,QWORD PTR [rip+0x294d95]        # 0x713ff8
  mov    rax,QWORD PTR fs:[rax]

An optimized Python should always be built with LTO.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40522>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to