Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Ulrich Weigand" <uweigand@de.ibm.com>
To: ken@linux.vnet.ibm.com (Ken Werner)
Cc: gdb-patches@sourceware.org
Subject: Re: [patch] Scalar to vector widening
Date: Fri, 08 Oct 2010 13:14:00 -0000	[thread overview]
Message-ID: <201010081314.o98DEfAx031234@d12av02.megacenter.de.ibm.com> (raw)
In-Reply-To: <201010072241.13455.ken@linux.vnet.ibm.com> from "Ken Werner" at Oct 07, 2010 10:41:13 PM

Ken Werner wrote:

> @@ -2035,8 +2042,12 @@ evaluate_subexp_standard (struct type *e
>  
>  	  /* For shift and integer exponentiation operations,
>  	     only promote the first argument.  */
> -	  if ((op == BINOP_LSH || op == BINOP_RSH || op == BINOP_EXP)
> -	      && is_integral_type (value_type (arg2)))
> +	  if (op == BINOP_LSH || op == BINOP_RSH)
> +	    {
> +	      arg2 = value_cast (check_typedef (value_type (arg1)), arg2);
> +	      unop_promote (exp->language_defn, exp->gdbarch, &tmp);
> +	    }

I don't think these are quite right.  If, say, arg2 is a vector of
different type, this may get simply cast away.  Likewise, if arg1
is a very short integer type, the cast may actually remove valid
bits in arg2 ...   I think the cast really should only be done if
one side is a vector and the other a scalar.

However, I don't quite like distributing the code between the various
promotion routines.  In fact, I'm starting to think this shouldn't
actually be though of as a promotion at all.  Instead, why not simply
handle the case directly in vector_binop?  If only one side is a vector
and the other is a scalar, cast it there.  This should simplify the
patch even further.

[ Note that value_binop already today performs type conversions (e.g.
from integer to float).  We only split off those performed by the
GDB logic (value_binop) itself from those performed by language-
specific promotion rules where the latter are ambiguous of change
between languages.

If value_binop gets called with a pair of a vector and a scalar,
it ought to do *something* anyway, so we might as well decide
the straight-forward widening is what happens. ]

> +# Test scalar to vector widening
> +gdb_test "print i4a + ib" "\\\$$decimal = \\{3, 5, 9, 17\\}"
> +gdb_test "print fa - f4b" "\\\$$decimal = \\{1, 0, -6, -2\\}"
> +gdb_test "print f4a * fb" "\\\$$decimal = \\{2, 4, 8, 16\\}"
> +gdb_test "print ia / i4b" "\\\$$decimal = \\{2, 1, 0, 0\\}"
> +gdb_test "print i4a % ib" "\\\$$decimal = \\{0, 0, 0, 0\\}"
> +
> +gdb_test "print ia & i4b" "\\\$$decimal = \\{0, 2, 0, 0\\}"
> +gdb_test "print i4a | ib" "\\\$$decimal = \\{3, 5, 9, 17\\}"
> +gdb_test "print ia ^ i4b" "\\\$$decimal = \\{3, 0, 10, 6\\}"
> +gdb_test "print i4a << ib" "\\\$$decimal = \\{4, 8, 16, 32\\}"
> +gdb_test "print i4a >> ib" "\\\$$decimal = \\{1, 2, 4, 8\\}"
> +
> +gdb_test "print i4b = ia" "\\\$$decimal = \\{2, 2, 2, 2\\}"
> +gdb_test "print i4a = 3" "\\\$$decimal = \\{3, 3, 3, 3\\}"
> +gdb_test "print f4a = fb" "\\\$$decimal = \\{1, 1, 1, 1\\}"
> +gdb_test "print f4b = 2" "\\\$$decimal = \\{2, 2, 2, 2\\}"
> +
> +gdb_test "print i4a = \{2, 4, 8, 16\}" "\\\$$decimal = \\{2, 4, 8, 16\\}"
> +gdb_test "print i4a <<= ib" "\\\$$decimal = \\{4, 8, 16, 32\\}"

Since we've now added support for casts, maybe a couple of
tests for that capability would also be helpful.

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


  reply	other threads:[~2010-10-08 13:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-17 14:39 Ken Werner
2010-09-28 16:08 ` Ken Werner
2010-10-05 18:08 ` Ulrich Weigand
2010-10-07 20:41   ` Ken Werner
2010-10-08 13:14     ` Ulrich Weigand [this message]
2010-10-08 16:37       ` Ken Werner
2010-10-08 16:44         ` Ulrich Weigand
2010-10-08 16:52           ` Ken Werner

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=201010081314.o98DEfAx031234@d12av02.megacenter.de.ibm.com \
    --to=uweigand@de.ibm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=ken@linux.vnet.ibm.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