public inbox for cgen@sourceware.org
 help / color / mirror / Atom feed
From: Alexander Viro <aviro@redhat.com>
To: cgen@sourceware.org
Subject: [RFC] cgen_parse_signed_integer() and 64bit bugs
Date: Sat, 12 Aug 2006 17:20:00 -0000	[thread overview]
Message-ID: <20060812171950.GA25038@devserv.devel.redhat.com> (raw)

[apologies if it ends up double-posted]

Consider the following example (on FRV):
        setlos #0xffffffff,gr4
FRV is a 32bit target and instruction above takes a 16bit immediate
that gets sign-expanded.  So when we run native gas(1) or cross-build
on e.g. i386 we will get no complaints:
	1 0000 88FCFFFF              setlos #0xffffffff,gr4
Everything is fine - 16bit all-ones gets sign-expanded to 32bit all-ones.
Perhaps writing it as
	setlos #-1,gr4
would be cleaner, perhaps it would not, but in any case gas takes either
form without any complaints and produces expected results.

Unfortunately, as soon as you move to 64bit host, you'll get breakage.
Note that this is not a theoretical example - it's pulled straight from
arch/frv/lib/tlb-flush.S in Linux kernel.  Similar examples for other
architectures exist in a lot of places waiting for cross-toolchain to
be moved to another host.

Mechanism of this particular breakage is pretty simple:
  return cgen_parse_signed_integer (cd, strp, opindex, valuep);
in the very end of parse_uslo16() in cpu/frv.opc is sensitive to
word size of _host_.  That's documented behaviour, so in this
case the obvious answer would be "so truncate the value and sign-expand
it after the call".  As the matter of fact, _any_ 32bit target using
that puppy should be doing that.  Each case where such fixup is not
done means a portability bug.  And such bugs exist:
	* frv.opc never does fixups.  Each instance is a bug.
	* m32r.opc never does fixups.  Buggy.
	* m32c.opc never does fixups.  Buggy.
	* mt.opc has something that might be a fixup, but it's (a) broken
and (b) #if 0'd.  Buggy.
	* iq2000.opc does manual fixups.  Correct.
That's 4 out of 5.

Unfortunately, the situation is even messier.  We can do manual fixups,
all right.  But every time we describe something as h-sint we get a call
inserted into *-asm.c.  And for those we can't deal with that way.

Potential solutions:
	* deal with those suckers manually in frv-asm.c, etc.  Unacceptable,
since fixes will be lost the next time somebody reruns cgen.
	* add cgen_parse_signed_32bit() that would do fixups and h-s32 in
addition to h-sint.  Teach cgen to produce cgen_parse_signed_32bit() for
those.  Possible, but requires messing with cgen guts.
	* change the rules and make cgen_parse_signed_integer() to do
fixups.  Unfortunately, that means changes of behaviour for sh64-*.cpu.
All uses of h-sint in there are for 32 or fewer bits, so we are not
breaking any valid code, but currently we *do* fail for 0xffffffff as
argument and after that change we won't.  Plus there might be out-of-tree
users in similar situations.

Suggestions?

             reply	other threads:[~2006-08-12 17:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-12 17:20 Alexander Viro [this message]
2006-08-14 20:24 ` Dave Brolley

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=20060812171950.GA25038@devserv.devel.redhat.com \
    --to=aviro@redhat.com \
    --cc=cgen@sourceware.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).