So if the overflow happens for either one of the case, the return value will be implementation dependent? best kevin On Feb 17, 2015, at 2:01 PM, Tim Northover <t.p.northover at gmail.com> wrote:> Hi Kevin, > > On 17 February 2015 at 10:41, kewuzhang <kewu.zhang at amd.com> wrote: >> I just noticed that the LLVM has some node for signed/unsigned type( like udiv, sdiv), but why the ADD, SUB do not have the counter part sadd, uadd? > > That's because in 2s complement arithmetic the bit pattern of the > result doesn't depend on whether the operation is signed (unlike > multiplication & division). > > Cheers. > > Tim.
On 17 February 2015 at 11:08, kewuzhang <kewu.zhang at amd.com> wrote:> So if the overflow happens for either one of the case, the return value will be implementation dependent?If the instructions have "nuw" or "nsw" flags, the results are undefined in the respective case. Otherwise they're defined to follow C's unsigned rules (i.e. they return the full precision unsigned sum/difference reduced mod 2^n). Cheers. Tim.
That is very clear! best kevin On Feb 17, 2015, at 2:13 PM, Tim Northover <t.p.northover at gmail.com> wrote:> On 17 February 2015 at 11:08, kewuzhang <kewu.zhang at amd.com> wrote: >> So if the overflow happens for either one of the case, the return value will be implementation dependent? > > If the instructions have "nuw" or "nsw" flags, the results are > undefined in the respective case. > > Otherwise they're defined to follow C's unsigned rules (i.e. they > return the full precision unsigned sum/difference reduced mod 2^n). > > Cheers. > > Tim.