moving int to byte[] in single step

Ulf Zibis Ulf.Zibis at gmx.de
Wed Dec 23 16:02:13 PST 2009


In my code I have following snippet:

        byte[] da = ...;
        int dp = ...;
        int qb = ...;
        da[dp+3] = (byte)qb;
        da[dp+2] = (byte)(qb >> 8);
        da[dp+1] = (byte)(qb >> 16);
        da[dp+0] = (byte)(qb >> 24);

This could be compiled to something like:
mov    0x24(%esp),%edi
..
mov    %eax,%ebx
bswap  %ebx     ; only little-endian architectures
mov    0x20(%esp),%esi
mov    0x8(%esi),%edx     ; implicit exception: dispatches to 0x00ba49e4
cmp    %edx,%edi
jae    0x00ba49a5
mov    0x24(%esp),%ebp
add    $0x3,%ebp
cmp    %edx,%ebp
jae    0x00ba49c1
mov    %ebx,0xc(%esi,%edi,4)  ;*bastore
...

... but disassembly output results:
(copies each of the 4 bytes in single steps)

  0x00ba48d6: mov    0x24(%esp),%edi
  ...
  0x00ba492a: mov    %eax,%ebx
  0x00ba492c: sar    $0x18,%ebx         ;*ishr
                                        ; - 
sun.nio.cs.ext.EUC_TW_C_d_b_c1_f3_shortMap4$Encoder::encode at 93 (line 491)
  0x00ba492f: mov    0x20(%esp),%esi
  0x00ba4933: mov    0x8(%esi),%edx     ; implicit exception: dispatches 
to 0x00ba49e4
  0x00ba4936: cmp    %edx,%edi
  0x00ba4938: jae    0x00ba49a5
  0x00ba493a: mov    %bl,0xc(%esi,%edi,1)  ;*bastore
                                        ; - 
sun.nio.cs.ext.EUC_TW_C_d_b_c1_f3_shortMap4$Encoder::encode at 95 (line 491)
  0x00ba493e: mov    0x24(%esp),%ebp
  0x00ba4942: add    $0x3,%ebp
  0x00ba4945: mov    %eax,%ecx
  0x00ba4947: sar    $0x10,%ecx         ;*ishr
                                        ; - 
sun.nio.cs.ext.EUC_TW_C_d_b_c1_f3_shortMap4$Encoder::encode at 104 (line 492)
  0x00ba494a: cmp    %edx,%ebp
  0x00ba494c: jae    0x00ba49c1
  0x00ba494e: mov    %cl,0xd(%esi,%edi,1)  ;*bastore
                                        ; - 
sun.nio.cs.ext.EUC_TW_C_d_b_c1_f3_shortMap4$Encoder::encode at 106 (line 492)
  0x00ba4952: mov    %eax,%ebx
  0x00ba4954: sar    $0x8,%ebx
  0x00ba4957: mov    %bl,0xe(%esi,%edi,1)  ;*bastore
                                        ; - 
sun.nio.cs.ext.EUC_TW_C_d_b_c1_f3_shortMap4$Encoder::encode at 117 (line 493)
  0x00ba495b: mov    %al,0xf(%esi,%edi,1)  ;*bastore
                                        ; - 
sun.nio.cs.ext.EUC_TW_C_d_b_c1_f3_shortMap4$Encoder::encode at 125 (line 494)
 ...

Complete output here (line 2497):
https://java-nio-charset-enhanced.dev.java.net/source/browse/java-nio-charset-enhanced/branches/j7_EUC_TW/log/C_d_b_c1_f3_shortMap4_PA_2.xml?rev=888&view=markup

As you can see, copying the 4 bytes could be done at once.
I guess this would be faster here.

-Ulf




More information about the hotspot-compiler-dev mailing list