<html><head><base href="x-msg://4804/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On 21 Feb 2010, at 08:33, Jay K wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; 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: 0px; "><div class="hmmessage" style="font-size: 10pt; font-family: Verdana; ">I *suspect* the "real" "big" problem is that left and right shift and "plain" shift should take a size.<br></div></span></blockquote><div><br></div><div>No! Simply mask the bits you want and perform the shift right, or shift left and mask the result. Easy!</div><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; 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: 0px; "><div class="hmmessage" style="font-size: 10pt; font-family: Verdana; "> <br> - Jay<br><br><br> <br><hr id="stopSpelling">From:<span class="Apple-converted-space"> </span><a href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</a><br>To:<span class="Apple-converted-space"> </span><a href="mailto:hosking@cs.purdue.edu">hosking@cs.purdue.edu</a>;<span class="Apple-converted-space"> </span><a href="mailto:m3devel@elegosoft.com">m3devel@elegosoft.com</a><br>Subject: opacity of Target.Int, overflow of Target.Int<br>Date: Sun, 21 Feb 2010 10:31:06 +0000<br><br>1) Tony, I claim that if Target.Int is really opaque, then values of it should only be formed in Target.i3/Target.m3.<br>Or TInt/TWord/.i3/.m3, since they know deeply about it.<br>Having m3back know about them seems a bit off.<br>Granted, pushing constants that only m3back uses into Target/TInt/TWord isn't great either, pollutes them some.<br>This is a minor dilemna though.<br> <br> <br>2) Are you sure having a fixed precision of 8 bytes is correct here?<br>More generally are you sure TInt has the right interface?<br>How does one check for overflow within the precision one cares about?<br>I think I know.<br>I think Chop should return a boolean, as to if the value fits.<br>For that matter, have SignedChop and UnsignedChop.<br> Or TInt.Chop and TWord.Chop.<br>TInt.Chop is already SignedChop.<br> <br>Do the math in 64bits, if that overflows, then overflow.<br>And then truncate to whatever, and that can overflow too.<br>This is related to "you all have convinced me that overflow isn't<br>all that important really, but range checking is".<br>So you in sense defer the overflow. You don't do the complete<br>overflow check at Add or whatever, but then you do a range<br>check converting to a small size.<br> <br>But hm. This will skip "intermediate overflow". Does that matter?<br>1 billion * 8 / 8<br> <br> <br>Should that overflow in 32bits?<br> <br> <br>Well, easy enough, do the chop after each operation.<br>I said "defer", but it is brief.<br>1B * 8 / 8<br>isn't written as<br>1* 8 / 8<br>convert to 32bits<br> <br>but rather<br>1B * 8<br>convert to 32bits<br> => failure here<span class="Apple-converted-space"> </span><br>/ 8<br>convert to 32bits<br> <br>?<br> <br> <br>3) Related to #2.<br>Where should RightShift insert zeros?<br>I guess you chop first, and then it works.<br> <br> <br>Proposed something like:<br> <br><br>TInt:<br>PROCEDURE Chop (VAR r: Int; n: CARDINAL): BOOLEAN =<br> VAR extension := Mask * ORD(And (r [n-1], SignMask) = 0);<br> result := TRUE;<br> BEGIN<br> FOR i := n TO LAST(Int) DO<br> result := (result AND (r[i] # extension));<br> r[i] := extension;<br> END;<br> return result;<br> END Chop;<br><br>TWord:<br>PROCEDURE Chop (VAR r: Int; n: CARDINAL): BOOLEAN =<br> CONST extension = 0;<br> VAR result := TRUE;<br> BEGIN<br> FOR i := n TO LAST(Int) DO<br> result := (result AND (r[i] # extension));<br> r[i] := extension;<br> END;<br> return result;<br> END Chop;<br><br> <br> <br>But I have to back to your version of m3back and try these out.<br>Very speculative at the moment.<br> <br>Could also leave the data alone upon failure, trivially related to previous:<br> <br>TInt:<br>PROCEDURE Chop (VAR r: Int; n: CARDINAL): BOOLEAN =<br> VAR extension := Mask * ORD(And (r [n-1], SignMask) = 0);<br> BEGIN<br> FOR i := n TO LAST(Int) DO<br> IF r[i] # extension THEN<br> RETURN FALSE;<br> END;<br> END;<br> FOR i := n TO LAST(Int) DO<br> r[i] := extension;<br> END;<br> RETURN TRUE;<br> END Chop;<br><br> <br>TWord:<br>PROCEDURE Chop (VAR r: Int; n: CARDINAL): BOOLEAN =<br> VAR result := TRUE;<br> BEGIN<br> FOR i := n TO LAST(Int) DO<br> IF r[i] # 0 THEN<br> RETURN FALSE;<br> END;<br> END;<br> FOR i := n TO LAST(Int) DO<br> r[i] := 0;<br> END;<br> return TRUE;<br> END Chop;<br><br> <br>I'm not sure I like the subtlety of TInt.Chop vs. TWord.Chop.<br>I'd prefer TInt.UnsignedChop and TInt.SignedChop.<br>Granted, "Un" doesn't exactly stand out, but at least "signed" does and makes you wonder about and discover the existance of signed vs. unsigned.<br> <br> <br>Alternatively Chop and UChop. More subtle, but I think plenty programmars are used to the names "uchar", "ushort", "uint", "ulong". "u" is pretty widely recognized as meaning "unsigned". More so I believe than "Word".<br>(I still don't like the name "interface Long"!, it doesn't imply unsigned at all!)<br> <br> <br> - Jay<br></div></span></blockquote></div><br></body></html>