<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div><font class="Apple-style-span" color="#0000FF" face="'Gill Sans'"><span class="Apple-style-span" style="font-size: medium;">The MIPS for example has overflow traps on signed arithmetic.</span></font></div></span></span></span></span></span></span></span></span></div></span></span>
</div><div>SPARC has tagged arithmetic that causes an overflow trap.</div><div>x86 probably needs explicit test of the condition codes -- sigh! That's why C is silent about integer arithmetic overflow... because Intel can't support it via traps...</div><div><br></div><div><div>On 12 Jan 2010, at 13:47, Jay K wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><br>What hardware traps?<br><br>Sure, maybe integer divide by zero.<br><br><br>Unlikely I think for integer overflow.<br>I agree out of line inefficient.<br>Probably want "check the carry flag" generated inline,<br>in whatever machine-specific way that is done, may<br>or may not require extra work in m3cg.<br><br><br>I might try this soon though, where a command line option (for now)<br>uses function calls and raises exceptions.<br>My slightly refined thinking is that the generate code will look like:<br><br><br>a := b + c * d;<br>Foo()<br>d := a + b * c;<br>Bar()<br><br><br>overflow = 0;<br>a = add(b, mult(c, d), &overflow);<br>if (overflow) Raise...<br>Foo();<br>overflow = 0;<br>a = add(a, mult(b, c), &overflow);<br>if (overflow) Raise...<br><br><br>That is -- the overflow flag need only be checked "occasionally", such as before any function call, maybe at the start of any loop.<br>Or at the very least, if a statement contains no function calls, only at the end of the statement, not after evaluating each term in an expression.<br><br><br>Once overflow occurs, there's little requirement on how the statement proceeds. Though divide by zero shouldn't result. Probably if an expression contains any division, check overflow at each step.<br>?<br><br><br>But maybe "check the overflow flag" is easy enough and right surely far more efficient.<br><br><br><br> - Jay<br><br><br><br>________________________________<br><blockquote type="cite">From: <a href="mailto:hosking@cs.purdue.edu">hosking@cs.purdue.edu</a><br></blockquote><blockquote type="cite">Date: Tue, 12 Jan 2010 13:18:27 -0500<br></blockquote><blockquote type="cite">To: <a href="mailto:jkrell@elego.de">jkrell@elego.de</a><br></blockquote><blockquote type="cite">CC: <a href="mailto:m3commit@elegosoft.com">m3commit@elegosoft.com</a><br></blockquote><blockquote type="cite">Subject: Re: [M3commit] CVS Update: cm3<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Do we really want to do this via compilation and out-of-line functions? Surely we would prefer to implement the FloatMode interface to catch hardware traps... I haven't looked at the details but that seems to be the intent...<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">On 12 Jan 2010, at 12:16, Jay Krell wrote:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">CVSROOT: /usr/cvs<br></blockquote><blockquote type="cite">Changes by: jkrell@birch. 10/01/12 12:16:59<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Modified files:<br></blockquote><blockquote type="cite">cm3/m3-libs/m3core/src/Csupport/Common/: hand.c<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Log message:<br></blockquote><blockquote type="cite">add portable possible functions for implementing overflow checking of add/sub/mult of int, int64, uint, uint64<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span> <span class="Apple-tab-span" style="white-space:pre"> </span> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span> <br></blockquote></div></blockquote></div><br></body></html>