Thank you Nicolas! If you send me a method with your date stamp on it it'll get integrated in my changes...<br><br><div class="gmail_quote">On Fri, Jul 4, 2008 at 1:22 PM, nicolas cellier <<a href="mailto:ncellier@ifrance.com">ncellier@ifrance.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
Hello VM gods,<br>
every little improvment counts, so my 2 pennies:<br>
<br>
Interpreter>>byteSwapped: w<br>
"Answer the given integer with its bytes in the reverse order."<br>
<br>
BytesPerWord = 4<br>
ifTrue:<br>
[^((w bitShift: Byte3ShiftNegated) bitAnd: Byte0Mask)<br>
+ ((w bitShift: Byte1ShiftNegated) bitAnd: Byte1Mask)<br>
+ ((w bitShift: Byte1Shift ) bitAnd: Byte2Mask)<br>
+ ((w bitShift: Byte3Shift ) bitAnd: Byte3Mask)]<br>
ifFalse:<br>
[^((w bitShift: Byte7ShiftNegated) bitAnd: Byte0Mask)<br>
+ ((w bitShift: Byte5ShiftNegated) bitAnd: Byte1Mask)<br>
+ ((w bitShift: Byte3ShiftNegated) bitAnd: Byte2Mask)<br>
+ ((w bitShift: Byte1ShiftNegated) bitAnd: Byte3Mask)<br>
+ ((w bitShift: Byte1Shift ) bitAnd: Byte4Mask)<br>
+ ((w bitShift: Byte3Shift ) bitAnd: Byte5Mask)<br>
+ ((w bitShift: Byte5Shift ) bitAnd: Byte6Mask)<br>
+ ((w bitShift: Byte7Shift ) bitAnd: Byte7Mask)]<br>
<br>
<br>
Can be written with less operations with the classical:<br>
<br>
byteSwapped: w<br>
| x |<br>
x := w.<br>
BytesPerWord = 4<br>
ifTrue: [<br>
"Note: In C, x unsigned 64 bits, first bitAnd: is not required"<br>
x = ((x bitAnd: 16rFFFF0000 >> 16)<br>
+ ((x bitAnd: 16r0000FFFF << 16).<br>
x = ((x bitAnd: 16rFF00FF00 >> 8)<br>
+ ((x bitAnd: 16r00FF00FF << 8)]<br>
ifFalse: [<br>
"Note: In C, x unsigned 64 bits, first bitAnd: is not required"<br>
x = ((x bitAnd: 16rFFFFFFFF00000000 >> 32)<br>
+ ((x bitAnd: 16r00000000FFFFFFFF << 32).<br>
x = ((x bitAnd: 16rFFFF0000FFFF0000 >> 16)<br>
+ ((x bitAnd: 16r0000FFFF0000FFFF << 16).<br>
x = ((x bitAnd: 16rFF00FF00FF00FF00 >> 8)<br>
+ ((x bitAnd: 16r00FF00FF00FF00FF << 8)].<br>
^x<br>
<br>
Yeah, the cost is (BytesPerWord log: 2).<br>
Of course, you can use named constants, with proper unsigned long declarations, that's a detail i let you deal with.<br><font color="#888888">
<br>
Nicolas<br>
<br>
<br>
</font></blockquote></div><br>