This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Scalar to vector widening


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]