Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6984886

Transform comparisons against odd border to even border

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P5
    • Resolution: Unresolved
    • Affects Version/s: 7, 9, 10
    • Fix Version/s: tbd
    • Component/s: hotspot
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      A DESCRIPTION OF THE REQUEST :

      Compile
        a <= 0x50FF
      as
        a < 0x5100

      Additionally may be there could be some pre-optimization from java compiler side.
      .


      JUSTIFICATION :

      - allows merging of consecutive comparisons against same borders
      - allows optimization on consecutive comparisons by comparison against small 8-bit immediant operand after right shift
      - if char, allows optimization by 8-bit comparison on high byte, if low byte == 0
      - saves memory footprint and should be faster



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -

        0x00b86cc7: cmp $0xd800,%ecx
        0x00b86ccd: jl 0x00b86cde ;*if_icmplt
                                              ; - java.lang.Benchmark::isHighSurrogate1@3 (line 7)
                                              ; - java.lang.Benchmark::isSurrogate1@1 (line 35)
        0x00b86ccf: cmp $0xdc00,%ecx
        0x00b86cd5: jge 0x00b86cde ;*if_icmpge
                                              ; - java.lang.Benchmark::isHighSurrogate1@9 (line 7)
                                              ; - java.lang.Benchmark::isSurrogate1@1 (line 35)
        0x00b86cd7: mov $0x2,%eax
        0x00b86cdc: jmp 0x00b86cf7 ;*if_icmplt
                                              ; - java.lang.Benchmark::isHighSurrogate1@3 (line 7)
                                              ; - java.lang.Benchmark::isSurrogate1@1 (line 35)
      // Could be omitted:
      // 0x00b86cde: cmp $0xdc00,%ecx
      // 0x00b86ce4: jl 0x00b86cf5 ;*if_icmplt
      // ; - java.lang.Benchmark::isLowSurrogate1@3 (line 11)
      // ; - java.lang.Benchmark::isSurrogate1@13 (line 37)
        0x00b86ce6: cmp $0xe000,%ecx
        0x00b86cec: jge 0x00b86cf5 ;*if_icmpge
                                              ; - java.lang.Benchmark::isLowSurrogate1@9 (line 11)
                                              ; - java.lang.Benchmark::isSurrogate1@13 (line 37)
        0x00b86cee: mov $0x1,%eax
        0x00b86cf3: jmp 0x00b86cf7 ;*if_icmplt
                                              ; - java.lang.Benchmark::isLowSurrogate1@3 (line 11)
                                              ; - java.lang.Benchmark::isSurrogate1@13 (line 37)
        0x00b86cf5: xor %eax,%eax ;*goto
                                              ; - java.lang.Benchmark::isSurrogate1@21 (line 38)

      ==============================

        0x00b85007: shr $0x8,%eax ;*iushr
                                              ; - java.lang.Benchmark::isHighSurrogate2@3 (line 15)
                                              ; - java.lang.Benchmark::isSurrogate2@1 (line 45)
        0x00b8500a: cmp $0xd8,%al
        0x00b8500c: jl 0x00______ ;*if_icmplt
                                              ; - java.lang.Benchmark::isHighSurrogate2@7 (line 15)
                                              ; - java.lang.Benchmark::isSurrogate2@1 (line 45)
        0x00b8500e: cmp $0xdc,%al
        0x00b85010: jge 0x00______ ;*if_icmpge
                                              ; - java.lang.Benchmark::isHighSurrogate2@17 (line 15)
                                              ; - java.lang.Benchmark::isSurrogate2@1 (line 45)
        ...

      ==============================

        0x00b85007: cmp $0xd8,%ch
        0x00b8500a: jl 0x00______ ;*if_icmplt
                                              ; - java.lang.Benchmark::isHighSurrogate2@7 (line 15)
                                              ; - java.lang.Benchmark::isSurrogate2@1 (line 45)
        0x00b8500c: cmp $0xdc,%ch
        0x00b8500f: jge 0x00______ ;*if_icmpge
                                              ; - java.lang.Benchmark::isHighSurrogate2@17 (line 15)
                                              ; - java.lang.Benchmark::isSurrogate2@1 (line 45)
        ...


      ACTUAL -

        0x00b84dc7: cmp $0xd800,%ecx
        0x00b84dcd: jl 0x00b84dd7
        0x00b84dcf: cmp $0xdbff,%ecx
        0x00b84dd5: jle 0x00b84df2 ;*if_icmplt
                                              ; - java.lang.Character::isHighSurrogate@3 (line 2794)
                                              ; - java.lang.Benchmark::isSurrogate@1 (line 25)
        0x00b84dd7: cmp $0xdc00,%ecx
        0x00b84ddd: jl 0x00b84dee ;*if_icmplt
                                              ; - java.lang.Character::isLowSurrogate@3 (line 2818)
                                              ; - java.lang.Benchmark::isSurrogate@13 (line 27)
        0x00b84ddf: cmp $0xdfff,%ecx
        0x00b84de5: jg 0x00b84dee ;*if_icmpgt
                                              ; - java.lang.Character::isLowSurrogate@9 (line 2818)
                                              ; - java.lang.Benchmark::isSurrogate@13 (line 27)
        0x00b84de7: mov $0x1,%eax
        0x00b84dec: jmp 0x00b84df7 ;*if_icmplt
                                              ; - java.lang.Character::isLowSurrogate@3 (line 2818)
                                              ; - java.lang.Benchmark::isSurrogate@13 (line 27)
        0x00b84dee: xor %eax,%eax
        0x00b84df0: jmp 0x00b84df7
        0x00b84df2: mov $0x2,%eax ;*goto
                                              ; - java.lang.Benchmark::isSurrogate@21 (line 28)

      ==============================

        0x00b85007: shr $0x8,%ecx ;*iushr
                                              ; - java.lang.Benchmark::isHighSurrogate2@3 (line 15)
                                              ; - java.lang.Benchmark::isSurrogate2@1 (line 45)
        0x00b8500a: cmp $0xd8,%ecx
        0x00b85010: jl 0x00b85021 ;*if_icmplt
                                              ; - java.lang.Benchmark::isHighSurrogate2@7 (line 15)
                                              ; - java.lang.Benchmark::isSurrogate2@1 (line 45)
        0x00b85012: cmp $0xdc,%ecx
        0x00b85018: jge 0x00b85021 ;*if_icmpge
                                              ; - java.lang.Benchmark::isHighSurrogate2@17 (line 15)
                                              ; - java.lang.Benchmark::isSurrogate2@1 (line 45)
        0x00b8501a: mov $0x2,%eax
        0x00b8501f: jmp 0x00b8503a ;*if_icmplt
                                              ; - java.lang.Benchmark::isHighSurrogate2@7 (line 15)
                                              ; - java.lang.Benchmark::isSurrogate2@1 (line 45)
        0x00b85021: cmp $0xdc,%ecx
        0x00b85027: jl 0x00b85038 ;*if_icmplt
                                              ; - java.lang.Benchmark::isLowSurrogate2@7 (line 19)
                                              ; - java.lang.Benchmark::isSurrogate2@13 (line 47)
        0x00b85029: cmp $0xe0,%ecx
        0x00b8502f: jge 0x00b85038 ;*if_icmpge
                                              ; - java.lang.Benchmark::isLowSurrogate2@17 (line 19)
                                              ; - java.lang.Benchmark::isSurrogate2@13 (line 47)



      ---------- BEGIN SOURCE ----------

      public class Benchmark {

          static boolean isHighSurrogate1(char ch) {
      // return ch >= Character.MIN_HIGH_SURROGATE && ch <= Character.MAX_HIGH_SURROGATE;
              return ch >= Character.MIN_HIGH_SURROGATE && ch < Character.MAX_HIGH_SURROGATE + 1;
          }
          static boolean isLowSurrogate1(char ch) {
      // return ch >= Character.MIN_LOW_SURROGATE && ch <= Character.MAX_LOW_SURROGATE;
              return ch >= Character.MIN_LOW_SURROGATE && ch < Character.MAX_LOW_SURROGATE + 1;
          }

          static boolean isHighSurrogate2(char ch) {
              return ch >>> 8 >= Character.MIN_HIGH_SURROGATE >>> 8
      && ch >>> 8 < Character.MAX_HIGH_SURROGATE + 1 >>> 8;
          }
          static boolean isLowSurrogate2(char ch) {
              return ch >>> 8 >= Character.MIN_LOW_SURROGATE >>> 8
      && ch >>> 8 < Character.MAX_LOW_SURROGATE + 1 >>> 8;
          }

          static int isSurrogate(char c) {
              int n;
              if (Character.isHighSurrogate(c))
                  n = 2;
              else if (Character.isLowSurrogate(c))
                  n = 1;
              else
                  n = 0;
              return n;
          }
          static int isSurrogate1(char c) {
              int n;
              if (isHighSurrogate1(c))
                  n = 2;
              else if (isLowSurrogate1(c))
                  n = 1;
              else
                  n = 0;
              return n;
          }
          static int isSurrogate2(char c) {
              int n;
              if (isHighSurrogate2(c))
                  n = 2;
              else if (isLowSurrogate2(c))
                  n = 1;
              else
                  n = 0;
              return n;
          }

          static int bmIsSurrogate() {
              int n = 0;
              for (int i=0; i<10000; i++)
                  for (char c='\uD000'; c<'\uE000'; c++) {
                      n += isSurrogate(c);
                      n += isSurrogate1(c);
                      n += isSurrogate2(c);
                  }
              return n;
          }

          public static void main(String... args) {
              System.out.println(bmIsSurrogate());
          }
      }


      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            • Assignee:
              rbackman Rickard Backman
              Reporter:
              ndcosta Nelson Dcosta
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported:
                Indexed: