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

perf - on i486+ fold a "test reg, reg" after a "add reg, ..."

XMLWordPrintable

    • x86
    • generic

      A DESCRIPTION OF THE REQUEST :
      Hotspot generates the following machine code when using DirectFloatBuffer.put(pos+7, value)) (native byte order):

      0x00b4397b: mov edx, ebx
        0x00b4397d: add edx, 0x07 ;*iadd
        0x00b43980: test edx, edx
        0x00b43982: jl 0x00B44107 ;*iflt
                                              ; - java.nio.Buffer::checkIndex@1 (line 513)
                                              ; - java.nio.DirectFloatBufferU::put@6 (line 254)

      The "test edx, edx" is not neccessary because all flags are already set by the "add edx, 0x07" instruction.

      A rule should be added to the macro assembler (atleast for the server compiler) that removes the test instruction when the preceeding instruction is a add or sub on the same register.

      PS: The above disassembly was obtained with -XX+PrintAssembly and my own disassembler.dll based on libdisasm.


      JUSTIFICATION :
      Performance improvements in code that builds DirectXXBuffers (like OpenGL applications).


      ---------- BEGIN SOURCE ----------
      import java.nio.*;

      static class Test {
      void test(FloatBuffer buf, float x, float y) {
          int pos = buf.position();
          buf.position(pos + 8);
          buf.put(pos, x).put(pos+1, y).put(pos+2, x+1).put(pos+3, y);
          y++;
          buf.put(pos+4, x).put(pos+5, y).put(pos+6, x+1).put(pos+7, y);
      }

      public static void main(String[] args) {
         FloatBuffer buf = ByteBuffer.allocateDirect(4*8*1000000).order(ByteOrder.nativeByteOrder()).asFloatBuffer();
         for(int i=0 ; i<1000000 ; i++) {
             test(buf, i*17, i*5);
         }
      }

      }
      ---------- END SOURCE ----------

            Unassigned Unassigned
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: