[Vm-dev] bitShift: and runtime sign discussion

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Sun Dec 23 13:14:37 UTC 2012

As you may know, the CCodeGenerator is clever enough to
#generateBitShift:on:indent: with proper direction << or >> when the
shift is literal.
When the shift in (expr bitShift: shift) is a variable or another
expression, it will produce a runtime test (shift <0) ? expr>>shift :
expr <<shift;
This is good for an arbitrary shift, but more than often we know the
sign and direction of the shift in advance, and this runtime test is
We must be aware that aggressive inlining will spread these useless
code all around.
Well, we might ignore impact on performance but we shall better not
ignore warnings generated by C compiler (or XCode analyzer) if we want
the code to be portable to other compilers (including future versions
of gcc).
...and the eventual warnings will be spreaded too

Maybe we could arrange for CCodeGenerator to recognize more cases when
the shift is unsigned, but
1) the CCodeGenerator is yet unable to infer expression type (except
some hack for declared variable)
2) we almost never use unsigned declaration in vm source anyway.

In the mean time, I suggest we use << and >> directlty in smalltalk
code (slang) when we know the direction in advance.

Find a few examples attached

-------------- next part --------------
A non-text attachment was scrubbed...
Name: JPEGReaderPlugin-scaleAndSignExtendinFieldWidth.st
Type: application/octet-stream
Size: 313 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20121223/a1861218/JPEGReaderPlugin-scaleAndSignExtendinFieldWidth.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LargeIntegersPlugin-anyBitOfBytesfromto.st
Type: application/octet-stream
Size: 1344 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20121223/a1861218/LargeIntegersPlugin-anyBitOfBytesfromto.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: JPEGReaderPlugin-getBits.st
Type: application/octet-stream
Size: 456 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20121223/a1861218/JPEGReaderPlugin-getBits.obj

More information about the Vm-dev mailing list