public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Uros Bizjak <ubizjak@gmail.com>
Cc: Jakub Jelinek <jakub@redhat.com>,
	Eric Botcazou <ebotcazou@adacore.com>,
	gcc-patches@gcc.gnu.org, 	Richard Henderson <rth@redhat.com>
Subject: Re: PATCH: Properly generate X32 IE sequence
Date: Tue, 20 Mar 2012 19:26:00 -0000	[thread overview]
Message-ID: <CAMe9rOo=YtiRCWx5qm-hQ7vC=ergVNqiTAD+Rn+coBLA-yi+_A@mail.gmail.com> (raw)
In-Reply-To: <CAFULd4bdFY1eYvrBP5dCQJA1Vq1Pf13_NB9beQSovxF4EM+zwg@mail.gmail.com>

On Tue, Mar 20, 2012 at 11:43 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
> On Tue, Mar 20, 2012 at 7:27 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>
>>>> I think use the OS provided instruction to load TP into DImode register
>>>> could simplify the code.
>>>
>>> Which OS provided instruction?
>>>
>>> Please see how TP is defined in get_thread_pointer, it is in ptr_mode:
>>>
>>>  rtx tp = gen_rtx_UNSPEC (ptr_mode, gen_rtvec (1, const0_rtx), UNSPEC_TP);
>>>
>>> This says that TP is in SImode on X32.
>
>> TP is defined as (unspec:DI [(const_int 0]) UNSPEC_TP)
>> and provided by OS.  It is a CONST_INT, but its value is opaque
>> to GCC. MODE here has no impact on its value provided by OS.
>> X32 OS provides instructions to load TP to into an SImode and
>> DImode registers.
>
> You must be looking to some other GCC sources than me.
>
> (define_insn "*load_tp_x32"
>  [(set (match_operand:SI 0 "register_operand" "=r")
>        (unspec:SI [(const_int 0)] UNSPEC_TP))]
>  "TARGET_X32"
>  "mov{l}\t{%%fs:0, %0|%0, DWORD PTR fs:0}"
>  [(set_attr "type" "imov")
>   (set_attr "modrm" "0")
>   (set_attr "length" "7")
>   (set_attr "memory" "load")
>   (set_attr "imm_disp" "false")])
>
> (define_insn "*load_tp_x32_zext"
>  [(set (match_operand:DI 0 "register_operand" "=r")
>        (zero_extend:DI (unspec:SI [(const_int 0)] UNSPEC_TP)))]
>  "TARGET_X32"
>  "mov{l}\t{%%fs:0, %k0|%k0, DWORD PTR fs:0}"
>  [(set_attr "type" "imov")
>   (set_attr "modrm" "0")
>   (set_attr "length" "7")
>   (set_attr "memory" "load")
>   (set_attr "imm_disp" "false")])
>

Thread pointer (TP) points to thread control block (TCB).  X32 TCB is

typedef struct
{
  void *tcb;		/* Pointer to the TCB.  Not necessarily the
			   thread descriptor used by libpthread.  */
  ...
}

It is a 32bit address set up by OS.  That is where 0 in "%fs:0" comes
from since it is the first field of the struct %fs points to.  X32 OS provides

mov %fs:0, %eax

to load the address of TCB into EAX and

mov %fs:0, %eax

to load the address of TCB into RAX since OS guarantees that the upper
32bits of the address of TCB are all 0s. We added "*load_tp_x32_zext"
since we zero-extend SI TP to DI TP.   Or we can use

mov %fs:0, %eax

to directly load the value of the tcb field into RAX and remove
"*load_tp_x32_zext".  It will simplify the code.


-- 
H.J.

      reply	other threads:[~2012-03-20 19:26 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-09 22:26 H.J. Lu
2012-03-10 13:10 ` Uros Bizjak
2012-03-10 18:50   ` H.J. Lu
2012-03-11 17:12     ` H.J. Lu
2012-03-11 17:55       ` Uros Bizjak
2012-03-11 18:16         ` H.J. Lu
2012-03-11 18:21           ` Uros Bizjak
2012-03-11 21:25             ` H.J. Lu
2012-03-12 19:39               ` Uros Bizjak
2012-03-12 22:35                 ` H.J. Lu
2012-03-13  1:21                   ` H.J. Lu
2012-03-13  7:11                     ` Uros Bizjak
2012-03-13 10:37                       ` Uros Bizjak
2012-03-13 15:47                         ` H.J. Lu
2012-03-17 17:53                         ` H.J. Lu
2012-03-17 18:10       ` Uros Bizjak
2012-03-17 18:19         ` H.J. Lu
2012-03-17 18:21           ` Uros Bizjak
2012-03-17 21:50             ` H.J. Lu
2012-03-18 16:02               ` Uros Bizjak
2012-03-18 20:55                 ` Uros Bizjak
2012-03-19 15:51                   ` H.J. Lu
2012-03-19 15:54                     ` H.J. Lu
2012-03-19 16:20                       ` H.J. Lu
2012-03-19 16:35                         ` H.J. Lu
2012-03-19 16:38                           ` Uros Bizjak
2012-03-19 16:47                             ` H.J. Lu
2012-03-19 16:49                               ` Uros Bizjak
2012-03-19 16:56                                 ` H.J. Lu
2012-03-19 17:02                                   ` Uros Bizjak
2012-03-19 17:30                                     ` Uros Bizjak
2012-03-19 17:50                                       ` H.J. Lu
2012-03-19 19:14                                         ` Uros Bizjak
2012-03-20  9:35                                           ` Paolo Bonzini
2012-03-19 16:47                         ` Uros Bizjak
2012-03-20  8:52                   ` Eric Botcazou
2012-03-20  8:59                     ` Jakub Jelinek
2012-03-20 11:20                       ` Jakub Jelinek
2012-03-20 15:52                         ` H.J. Lu
2012-03-20 17:55                           ` Uros Bizjak
2012-03-20 18:27                             ` H.J. Lu
2012-03-20 18:44                               ` Uros Bizjak
2012-03-20 19:26                                 ` H.J. Lu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMe9rOo=YtiRCWx5qm-hQ7vC=ergVNqiTAD+Rn+coBLA-yi+_A@mail.gmail.com' \
    --to=hjl.tools@gmail.com \
    --cc=ebotcazou@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=rth@redhat.com \
    --cc=ubizjak@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).