<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class='hmmessage'>please confirm my understanding<BR>
<BR>I don't feel great being a lone reader/changer of code esp. that I didn't write and that lacks<BR> sufficient documentation for my small brain/confidence. (I'm not stupid, but this isn't trivial stuff either.)<BR>
<BR>I am bound to make mistakes.<BR>
<BR>In the context of Modula-3 code gen interfaces, and the word interfaces, which apparently are identical/analogous/whatever:<BR>
<BR>
There is:<BR>
<BR>Shift (aka, my bad naming, "generic" shift)<BR>LeftShift<BR>RightShift<BR>
<BR>LeftShift and RightShift allow only positive shift counts, 0 .. 31 or 0 .. 63 (given<BR> particular word sizes and depending on types..) <BR>The "front end" checks constants against these.<BR>The "front end" inserts checks for variables against these.<BR>The back end can assume 0 .. 31 or 0 .. 63.<BR>
<BR>It looks like the x86 back end does redundant masks against 31, at least when shifting by a constant,<BR> only in its own data, not in the codegen. Just a small waste of time in the compiler, no negative affect on codegen.<BR>
<BR>"generic" Shift accepts any number for a shift count.<BR>Negative numbers mean a right shift.<BR>Positive numbers mean a left shift.<BR>If the shift count is >31|63 or <-31|63, the result is not an error, but zero.<BR>
<BR>In all cases, right shifts are unsigned, zero filling.<BR>
<BR>There is no shift operation that propagates the sign bit.<BR>In the Modula-3 language even. Perhaps, yes, integer division. But the frontend does not optimize<BR>there and turn multiplication or division into shifts, I think, haven't read much of the frontend. The backend could.<BR>
<BR>Rotate is presumably similar, but I have not looked at it.<BR>(LeftRotate, RightRotate, Rotate...)<BR>
<BR>m3-sys\m3back\src\m3x86.m3 implements left_shift, and right_shift,<BR> very redundanty code, could be combined.<BR>
<BR>The layering is /roughly/ <BR> m3x86 on top <BR> stackx86 in the middle <BR> codex86 at the bottom <BR>
<BR>However m3x86 does call through to codex86 directly.<BR>They are largely one layer. There is no strict division.<BR>"stack" is a simple way to implement some optimizations and stategies<BR>around constant propagation and register allocation.<BR>
<BR>It is a stack of "operands", which may be constants, globals, or locals.<BR>If something is needed in a register, a register will be freed up.<BR>If something is later needed and the register hasn't been spilled, it will be<BR> reused. If not, not.<BR>
<BR>Presently the operands are assumed to be of word size, 32 bits, register size.<BR>That is largely a convenience, and very convenient.<BR>I will expand it to allow two word operands.<BR>It could be expanded to arbitrarily, at least to "fill" "all" the registers, for some<BR> not particularly interesting but theoretically useful scenarios -- passing "medium"<BR> sized structs around by value or such. There are ABI concerns though, this could<BR> only be amongst local functions that aren't visible/used externally (aka "custom calling conventions").<BR>
<BR>The "generic" shift (vs. left_shift, right_shift) is implemented in stackx86<BR>while left_shift, right_shift are in m3x86. All three functions are very similar,<BR>could be combined, and there is no good reason for some to be in one layer<BR>vs. the other and it's a just a pointless inconsistency.<BR>
<BR>Granted, "generic" shift is a good bit different, it has to check the sign and the magnitude,<BR>whereas left and right can just blindly do the operation with no comparisons or branches.<BR>
<BR>Some of this I gather from attempting to compile code with shifts -- esp. the frontend checking of stuff, which then lead me to look at word.i3<BR>which declares subranges for the parameters.<BR>
<BR>Is Bill Kalsow around?<BR>Or the other original authors?<BR>Everyone just figured stuff out from the code, comments, and "literature" (I ordered another copy of Nelson's good book. :) )<BR>
<BR> - Jay<BR><BR><br /><hr />Connect and share in new ways with Windows Live. <a href='http://www.windowslive.com/connect.html?ocid=TXT_TAGLM_Wave2_newways_112007' target='_new'>Connect now!</a></body>
</html>