[PATCH] [ConstantRange] Add a smultiply method for signed multiply

James Molloy James.Molloy at arm.com
Sat Feb 21 13:17:03 PST 2015


Hi both,

OK, this is clearer now. Nick's suggestion of calculating both signed and unsigned and picking the smallest range makes sense as an implementation.

Thanks both for your patience! I'll put a new patch up for review based on Nick's suggestion shortly.

Cheers,

James



> On 21 Feb 2015, at 21:06, Sanjoy Das <sanjoy at playingwithpointers.com> wrote:
>
> Is it fair to say that your question is: given that
> ConstantRange::multiply uses the unsigned and signed max of the range
> to calculate its result, how can it possibly work in a signed context?
>
> So the first half of the answer is that you're right, in general the
> result computed by using the smax and smin vs. using the umax and umin
> will be different.  For instance, given this scheme, [-1, 2) `smult`
> [-1, 2) is [-1, 2) (everything is i8 in this email) while [-1, 2)
> `umult` [-1, 2) is the full i8 range. **
>
> However, we need to look at the "contract" umult and smult have to
> follow:
>
> X `umult` Y returns Zu such that Zu is a (sometimes proper) subset of
> { x * y (mod 2^n) | x \in X, y \in Y }
>
> X `smult` Y returns Zs such that Zs is a (sometimes proper) subset
> of { x * y (mod 2^n) | x \in X, y \in Y }
>
> In other words, both of them follow the exact same contract.  You can
> see how this is true for the [-1, 2) example -- both [-1, 2) and the
> full i8 set are legitimate answers for *both* [-1, 2) `smult` [-1, 2)
> and [-1, 2) `umult` [-1, 2).  Since [-1, 2) is a more "precise"
> answer, *both* `smult` and `umult` should try to return [-1, 2).
>
> Concretely, if in ConstantRange::multiply you can produce a better
> (smaller) range
> as answer with the signed interpretation of the two ranges you're
> multiplying, you should do so.  There is no need for a separate
> ConstantRange::smultiply.
>
> ** I did not bother to verify the math here
>
> -- Sanjoy
>

-- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium.  Thank you.

ARM Limited, Registered office 110 Fulbourn Road, Cambridge CB1 9NJ, Registered in England & Wales, Company No:  2557590
ARM Holdings plc, Registered office 110 Fulbourn Road, Cambridge CB1 9NJ, Registered in England & Wales, Company No:  2548782





More information about the llvm-commits mailing list