<html><head><base href="x-msg://4802/"></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><span class="Apple-style-span" style="font-size: medium; ">On 21 Feb 2010, at 05:31, Jay K wrote:</span></div></span></span></span></span></span></span></span></span></div></span></span></div><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; ">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></div></span></blockquote><div><br></div><div>Yeah, but it doesn't need to be totally opaque does it? An array of sign-extended bytes in little-endian order seems pretty general. You don't even need to specify the length of the array. I actually contemplated having TInt take open arrays of arbitrary length, with the result array length indicating the precision desired, but didn't do that just to maintain a simple implementation.</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; "> 2) Are you sure having a fixed precision of 8 bytes is correct here?<br></div></span></blockquote><div><br></div><div>There is nothing to stop it having more precision. In fact, increasing the size shouldn't affect any client code (so long as it uses appropriate array constructors to fill the sign in to the end, and performs bounds-checking to results to the desired precision, as well as checking the return values for potential overflow in whatever precision is implemented by TInt).</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; ">More generally are you sure TInt has the right interface?<br>How does one check for overflow within the precision one cares about?<br></div></span></blockquote><div><br></div><div>Bounds check.</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; ">I think I know.<br>I think Chop should return a boolean, as to if the value fits.<br></div></span></blockquote><div><br></div><div>No, because you may choose to ignore the high bits yet still want to sign-extend from the precision desired. That is exactly what I do for word operations in the front-end.</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; ">For that matter, have SignedChop and UnsignedChop.<br></div></span></blockquote><div><br></div><div>You should not need these.</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; "> Or TInt.Chop and TWord.Chop.<br></div></span></blockquote><div><br></div><div>What do you need TWord.Chop for. For example, TWord.And(val, Target.Word.max) gives me just the bits I need for a Word.Size full value.</div><div><br></div><div>Take a look at the (relatively small number of) changes I made to the front-end to do the appropriate checks and conversions.</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; ">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>