Swap should be better done native?

Ulf Zibis Ulf.Zibis at gmx.de
Wed Mar 31 13:41:52 PDT 2010


Am 31.03.2010 21:06, schrieb Martin Buchholz:
> On Wed, Mar 31, 2010 at 12:01, Ulf Zibis<Ulf.Zibis at gmx.de>  wrote:
>    
>> Am 31.03.2010 20:40, schrieb Martin Buchholz:
>>      
>>> On Wed, Mar 31, 2010 at 11:23, Ulf Zibis<Ulf.Zibis at gmx.de>    wrote:
>>>
>>>        
>>>> Am 30.03.2010 20:23, schrieb Florian Weimer:
>>>>
>>>>          
>>>
>>>        
>>>> Looking at the disassembly, I can't see any intrinsic method for swap.
>>>>
>>>>          
>>> There's a hotspot intrinsic for the reverseBytes methods.
>>>        

Yes, there it is (using Integer.reverseBytes):
   0x00b95d79: bswap  %ebx               ;*invokevirtual putInt
   ...
   0x00b95d8d: mov    %ebx,(%eax,%ecx,1)  ;*invokevirtual putInt

It's nearly perfect, as it could be:
   ...
   0x00b95d8b: movbe    %ebx,(%eax,%ecx,1)  ;*invokevirtual putInt

You remember on UTF-8 twiddling:

Am 16.03.2010 22:51, schrieb Ulf Zibis:
> Am 16.03.2010 21:57, schrieb Martin Buchholz:
>> On Tue, Mar 16, 2010 at 12:48, Ulf Zibis<Ulf.Zibis at gmx.de>  wrote:
>>>>>   8-bit shift + compare would allow HotSpot to compile to smart 
>>>>> 1-byte
>>>>> immediate op-codes.
>>>>> In encodeBufferLoop() you could use putChar(), putInt() instead 
>>>>> put().
>>>>> Should perform better.
>>>>>
>>>> I'm not convinced.  You would need to assemble bytes into an
>>>> int, and then break them apart into bytes on the other side?
>>>>
>>> Some time ago, I disassembled such code. I could see, that the int was
>>> copied directly to memory by one 32-bit move instruction.
>>> In case of using put(byte), I saw 4 8-bit move instructions.
>> Ulf, I'd like to understand this better.
>>
>> How are you generating the machine code
>> (pointer to docs?)?
>
> I must prepare it. Takes some time.

Now you can see, that putInt(int) is done at once, so faster as 4 put(byte).

-Ulf

>
>> Bits.java is doing byte-oriented put instructions in any case.
>> If the VM can optimize putInt, it should be able to optimize
>> the equivalent series of put(byte) as well, no?
>
> Yes, it should, but it doesn't.




More information about the nio-discuss mailing list