public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
To: Jeremy Fitzhardinge <jeremy@goop.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>,
	akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
	Andi Kleen <ak@muc.de>, Chuck Ebbert <cebbert@redhat.com>,
	Christoph Hellwig <hch@infradead.org>
Subject: Re: [patch 4/7] Immediate Values - i386 Optimization
Date: Wed, 19 Sep 2007 09:01:23 -0400	[thread overview]
Message-ID: <20070919130122.GA21750@Krystal> (raw)
In-Reply-To: <46F050E8.5020206@goop.org>

* Jeremy Fitzhardinge (jeremy@goop.org) wrote:
> H. Peter Anvin wrote:
> > Allowing different registers should be doable, but if so, one would have
> > to put 0: at the *end* of the instruction and use (0f)-4 instead, since
> > the non-%eax forms are one byte longer.
> >   
> 
> OK, that's already a problem since its using "=r" as the constraint.
> 
> > This also seems "safer", since an imm32 is always the last thing in the
> > instruction.
> 
> Good idea.  If gas/gcc generates entirely the wrong addressing mode,
> then we've got bigger problems.
> 

Ok, let's have a good look at what we want:

1 - get a pointer to the beginning of the immediate value within the
    instruction.
2 - make sure that the immediate value, within the instruction, is
    written to atomically wrt all CPUs, even on older architectures
    where non aligned writes are not atomic.

Effectively, placing a label at the end of the instruction, and then
offsetting backward from there, will give us (1).

Then, for the alignment, we have to give a good look at the instruction
set reference, mov instruction, to see what the variants of mov
immediate value to register are on i386.

First, let's look at the possible prefixes:
- Lock and repeat prefixes : no
- Segment override prefixes: no memory reference there, so doesn't
  apply.
- Branch hints : no, it's a mov instruction
- Operand-size override prefix: *yes*, can be used for 2 bytes mov
- Address-size override prefix: no address in there, only immediate
  value and register.

(looking at the Compat/Leg Mode)

3 cases:

* 1 byte
B0 + rb         MOV r8, imm8     (1 byte opcode)
REX + B0 + rb   MOV r8, imm8     (only on 64 bits archs, never generated)
C6 /0           MOV r/m8, imm8   (2 bytes opcode)
(this one doesn't require alignment at all, since we do a 1 byte write)

* 2 bytes
B8 + rw         MOV r16, imm16   (1 byte opcode)
66 B8 + rd      MOV r16, imm16   (2 bytes opcode) (with 66H prefix)
C7 /0           MOV r/m16, imm16 (2 bytes opcode)
(Alignment on 4 bytes boundaries would be required because of the
possible 1 byte opcode ? Or is the 66H prefix mandatory there ? If it
is, then we can safely align on 2 bytes boundaries.)

* 4 bytes
B8 + rd         MOV r32, imm32   (1 byte opcode)
C7 /0           MOV r/m32, imm32 (2 bytes opcode)
(the 2 bytes opcode can be a problem)

I have missed anything ?

Mathieu

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

  reply	other threads:[~2007-09-19 13:01 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-18 21:07 [patch 0/7] Immediate Values for 2.6.23-rc6-mm1 Mathieu Desnoyers
2007-09-18 21:07 ` [patch 1/7] Immediate Values - Architecture Independent Code Mathieu Desnoyers
2007-09-18 21:07 ` [patch 2/7] Immediate Values - Kconfig menu in EMBEDDED Mathieu Desnoyers
2007-09-18 22:02   ` Randy Dunlap
2007-09-19 11:13     ` Mathieu Desnoyers
2007-09-18 21:07 ` [patch 3/7] Immediate Values - Move Kprobes i386 restore_interrupt to kdebug.h Mathieu Desnoyers
2007-09-18 21:07 ` [patch 4/7] Immediate Values - i386 Optimization Mathieu Desnoyers
2007-09-18 21:51   ` Jeremy Fitzhardinge
2007-09-18 22:12     ` H. Peter Anvin
2007-09-18 22:27       ` Jeremy Fitzhardinge
2007-09-19 13:01         ` Mathieu Desnoyers [this message]
2007-09-19 16:03           ` Mathieu Desnoyers
2007-09-19 16:12           ` H. Peter Anvin
2007-09-19 17:30             ` Jeremy Fitzhardinge
2007-09-19 17:39               ` H. Peter Anvin
2007-09-19 18:31                 ` Mathieu Desnoyers
2007-09-19 18:22               ` Mathieu Desnoyers
2007-10-20 16:47         ` Mathieu Desnoyers
2007-10-20 18:32           ` H. Peter Anvin
2007-10-22 15:40             ` Mathieu Desnoyers
2007-10-22 16:39               ` H. Peter Anvin
2007-10-22  9:53           ` Andi Kleen
2007-09-19 11:00       ` Mathieu Desnoyers
2007-09-18 22:14     ` Andi Kleen
2007-09-18 22:29       ` Jeremy Fitzhardinge
2007-09-18 22:33         ` H. Peter Anvin
2007-09-18 22:44         ` Andi Kleen
2007-09-19 11:08       ` Mathieu Desnoyers
2007-09-19 11:14         ` Andi Kleen
2007-09-19 10:59     ` Mathieu Desnoyers
2007-09-20 10:24   ` Denys Vlasenko
2007-09-21 13:31     ` Mathieu Desnoyers
2007-09-18 21:07 ` [patch 5/7] Immediate Values - Powerpc Optimization Mathieu Desnoyers
2007-09-18 21:07 ` [patch 6/7] Immediate Values - Documentation Mathieu Desnoyers
2007-09-18 21:07 ` [patch 7/7] Scheduler Profiling - Use Immediate Values Mathieu Desnoyers
  -- strict thread matches above, loose matches on Subject: below --
2007-09-17 18:42 [patch 0/7] " Mathieu Desnoyers
2007-09-17 18:42 ` [patch 4/7] Immediate Values - i386 Optimization Mathieu Desnoyers
2007-09-18  6:04   ` Borislav Petkov

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=20070919130122.GA21750@Krystal \
    --to=mathieu.desnoyers@polymtl.ca \
    --cc=ak@muc.de \
    --cc=akpm@linux-foundation.org \
    --cc=cebbert@redhat.com \
    --cc=hch@infradead.org \
    --cc=hpa@zytor.com \
    --cc=jeremy@goop.org \
    --cc=linux-kernel@vger.kernel.org \
    /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