public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/96955] New: Implement __builtin_thread_pointer
@ 2020-09-07 13:46 hjl.tools at gmail dot com
  2020-09-07 14:05 ` [Bug target/96955] Implement __builtin_thread_pointer for x86 TLS jakub at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: hjl.tools at gmail dot com @ 2020-09-07 13:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96955

            Bug ID: 96955
           Summary: Implement __builtin_thread_pointer
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hjl.tools at gmail dot com
                CC: crazylht at gmail dot com, wwwhhhyyy333 at gmail dot com
            Blocks: 96200
  Target Milestone: ---
            Target: i386,x86-64

On Linux/x86-64, The %fs segment register is used to implement the thread
pointer. The linear address of the thread pointer is stored at offset 0
relative to the %fs segment register. The following code loads the thread
pointer in the %rax register:

movq %fs:0, %rax

On Linux/i386, the %gs segment register is used:

movl %gs:0, %eax

We need to

1. Implement __builtin_thread_pointer for Linux/x86.
2. Document its behavior.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96200
[Bug 96200] Implement __builtin_thread_pointer() and
__builtin_set_thread_pointer() if TLS is supported

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/96955] Implement __builtin_thread_pointer for x86 TLS
  2020-09-07 13:46 [Bug target/96955] New: Implement __builtin_thread_pointer hjl.tools at gmail dot com
@ 2020-09-07 14:05 ` jakub at gcc dot gnu.org
  2020-09-08  6:54 ` crazylht at gmail dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-09-07 14:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96955

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
And if possible, optimize, so that if one does say
int *p = (int *)__builtin_thread_pointer ();
return p[4];
or
return p[i];
it will not read %fs:0 into a register and read 16(%reg), but rather read
%fs:16
etc. (of course only if not -mno-tls-direct-seg-refs) or not read
16(%reg,%regI,4) but %fs:16(,%regI,4) etc.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/96955] Implement __builtin_thread_pointer for x86 TLS
  2020-09-07 13:46 [Bug target/96955] New: Implement __builtin_thread_pointer hjl.tools at gmail dot com
  2020-09-07 14:05 ` [Bug target/96955] Implement __builtin_thread_pointer for x86 TLS jakub at gcc dot gnu.org
@ 2020-09-08  6:54 ` crazylht at gmail dot com
  2020-09-08  8:15 ` crazylht at gmail dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: crazylht at gmail dot com @ 2020-09-08  6:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96955

--- Comment #2 from Hongtao.liu <crazylht at gmail dot com> ---
Do we also need "__builtin_set_thread_pointer" ?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/96955] Implement __builtin_thread_pointer for x86 TLS
  2020-09-07 13:46 [Bug target/96955] New: Implement __builtin_thread_pointer hjl.tools at gmail dot com
  2020-09-07 14:05 ` [Bug target/96955] Implement __builtin_thread_pointer for x86 TLS jakub at gcc dot gnu.org
  2020-09-08  6:54 ` crazylht at gmail dot com
@ 2020-09-08  8:15 ` crazylht at gmail dot com
  2020-09-09  8:29 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: crazylht at gmail dot com @ 2020-09-08  8:15 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96955

--- Comment #3 from Hongtao.liu <crazylht at gmail dot com> ---
(In reply to Jakub Jelinek from comment #1)
> And if possible, optimize, so that if one does say
> int *p = (int *)__builtin_thread_pointer ();
> return p[4];
> or
> return p[i];
> it will not read %fs:0 into a register and read 16(%reg), but rather read
> %fs:16
> etc. (of course only if not -mno-tls-direct-seg-refs) or not read
> 16(%reg,%regI,4) but %fs:16(,%regI,4) etc.

This optimization already exists in i386/x86-64 backend.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/96955] Implement __builtin_thread_pointer for x86 TLS
  2020-09-07 13:46 [Bug target/96955] New: Implement __builtin_thread_pointer hjl.tools at gmail dot com
                   ` (2 preceding siblings ...)
  2020-09-08  8:15 ` crazylht at gmail dot com
@ 2020-09-09  8:29 ` cvs-commit at gcc dot gnu.org
  2020-09-09  8:40 ` crazylht at gmail dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-09-09  8:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96955

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by hongtao Liu <liuhongt@gcc.gnu.org>:

https://gcc.gnu.org/g:e470d8af81d390df1166e9d9cf10b00c0692a495

commit r11-3067-ge470d8af81d390df1166e9d9cf10b00c0692a495
Author: liuhongt <hongtao.liu@intel.com>
Date:   Tue Sep 8 15:44:58 2020 +0800

    Implement __builtin_thread_pointer for x86 TLS.

    gcc/ChangeLog:
            PR target/96955
            * config/i386/i386.md (get_thread_pointer<mode>): New
            expander.

    gcc/testsuite/ChangeLog:

            * gcc.target/i386/builtin_thread_pointer.c: New test.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/96955] Implement __builtin_thread_pointer for x86 TLS
  2020-09-07 13:46 [Bug target/96955] New: Implement __builtin_thread_pointer hjl.tools at gmail dot com
                   ` (3 preceding siblings ...)
  2020-09-09  8:29 ` cvs-commit at gcc dot gnu.org
@ 2020-09-09  8:40 ` crazylht at gmail dot com
  2020-09-09 11:05 ` hjl.tools at gmail dot com
  2020-09-09 17:44 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: crazylht at gmail dot com @ 2020-09-09  8:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96955

--- Comment #5 from Hongtao.liu <crazylht at gmail dot com> ---
Fixed in GCC11.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/96955] Implement __builtin_thread_pointer for x86 TLS
  2020-09-07 13:46 [Bug target/96955] New: Implement __builtin_thread_pointer hjl.tools at gmail dot com
                   ` (4 preceding siblings ...)
  2020-09-09  8:40 ` crazylht at gmail dot com
@ 2020-09-09 11:05 ` hjl.tools at gmail dot com
  2020-09-09 17:44 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: hjl.tools at gmail dot com @ 2020-09-09 11:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96955

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |11.0

--- Comment #6 from H.J. Lu <hjl.tools at gmail dot com> ---
Fixed for GCC 11.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/96955] Implement __builtin_thread_pointer for x86 TLS
  2020-09-07 13:46 [Bug target/96955] New: Implement __builtin_thread_pointer hjl.tools at gmail dot com
                   ` (5 preceding siblings ...)
  2020-09-09 11:05 ` hjl.tools at gmail dot com
@ 2020-09-09 17:44 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-09-09 17:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96955

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by H.J. Lu <hjl@gcc.gnu.org>:

https://gcc.gnu.org/g:bf69edf8ce47ca618eff30df2308279a40b22096

commit r11-3081-gbf69edf8ce47ca618eff30df2308279a40b22096
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Sep 9 10:29:47 2020 -0700

    x32: Update gcc.target/i386/builtin_thread_pointer.c

    Update gcc.target/i386/builtin_thread_pointer.c for x32.  For

    int
    foo3 (int i)
    {
      int* p = (int*) __builtin_thread_pointer ();
      return p[i];
    }

    we can't generate:

            movl    %fs:0(,%edi,4), %eax
            ret

    for x32 since the address of %fs:0(,%edi,4) is %fs + zero-extended to 64
    bits of 0(,%edi,4).  Instead, we generate:

            movl    %fs:0, %eax
            movl    (%eax,%edi,4), %eax

            PR target/96955
            * gcc.target/i386/builtin_thread_pointer.c: Update scan-assembler
            for x32.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-09-09 17:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-07 13:46 [Bug target/96955] New: Implement __builtin_thread_pointer hjl.tools at gmail dot com
2020-09-07 14:05 ` [Bug target/96955] Implement __builtin_thread_pointer for x86 TLS jakub at gcc dot gnu.org
2020-09-08  6:54 ` crazylht at gmail dot com
2020-09-08  8:15 ` crazylht at gmail dot com
2020-09-09  8:29 ` cvs-commit at gcc dot gnu.org
2020-09-09  8:40 ` crazylht at gmail dot com
2020-09-09 11:05 ` hjl.tools at gmail dot com
2020-09-09 17:44 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).