Front page | perl.perl5.porters |
Postings from March 2008
Re: left_shift problem
Thread Previous
From:
Reini Urban
Date:
March 23, 2008 17:31
Subject:
Re: left_shift problem
Message ID:
47E6F679.8030502@x-ray.at
Reini Urban schrieb:
> Yitzchak Scott-Thoennes schrieb:
>> On Sun, March 23, 2008 3:45 pm, Reini Urban wrote:
>>> What makes we wonder is why the IV/UV discrimination is stored in the op
>>> (PL_op->op_private & HINT_INTEGER), and not taken from the type of the
>>> 1st arg at TOPi - 1st pop, 2nd arg -, which is here also used as return
>>> value.
>>>
>>> To my lisp trained eye, the signedness should be taken dynamically from
>>> the variable, and not stored at compile-time in the function.
>>>
>>> At compile-time the compiler must check the type of the arg and store it
>>> in the left_shift op. But what is when the type of the arg is
>>> upgraded from
>>> an IV to an UV? Or vice versa. Is this possible, or is the IV guaranteed
>>> to be static? Or, what if the arg is a UV, but the op has HINT_INTEGER?
>>> Well, it is degraded to a signed than.
>
>> I'm not sure I understand all those questions. But maybe this will
>> answer them:
>>
>> By design, the numeric bit ops give their arguments UV context (or,
>> under use integer, IV context). If another type of numeric arg is
>> provided, it is converted via a C cast (which doesn't quite match
>> your terms "upgraded" or "degraded") and produce a UV-range (or, under
>> use integer, IV-range) result. Like all context application, it is
>> something imposed on the operands by the operator.
>
> Thanks! This explains it perfectly.
>
> But still, the degration detail.
> Assume UV 2^32-1 and HINT_INTEGER in the op =>
> IV not representable.
> left_shift would make it representable again, but the cast in
> const IV i = TOPi; threw it away before, before shifting.
I always mix up left with right.
I meant a right_shift would make it representable again, but
the cast in const IV i = TOPi; threw it away, before shifting.
$ grep -A15 right_shift pp.c
PP(pp_right_shift)
{
dVAR; dSP; dATARGET; tryAMAGICbin(rshift,opASSIGN);
{
const IV shift = POPi;
if (PL_op->op_private & HINT_INTEGER) {
const IV i = TOPi;
SETi(i >> shift);
}
else {
const UV u = TOPu;
SETu(u >> shift);
}
RETURN;
}
}
--
Reini Urban
http://phpwiki.org/ http://murbreak.at/
Thread Previous