lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1049667 [3/3] - /lucene/dev/branches/bulkpostings/lucene/src/java/org/apache/lucene/util/pfor/
Date Wed, 15 Dec 2010 18:59:03 GMT
Modified: lucene/dev/branches/bulkpostings/lucene/src/java/org/apache/lucene/util/pfor/FrameOfRef.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/bulkpostings/lucene/src/java/org/apache/lucene/util/pfor/FrameOfRef.java?rev=1049667&r1=1049666&r2=1049667&view=diff
==============================================================================
--- lucene/dev/branches/bulkpostings/lucene/src/java/org/apache/lucene/util/pfor/FrameOfRef.java
(original)
+++ lucene/dev/branches/bulkpostings/lucene/src/java/org/apache/lucene/util/pfor/FrameOfRef.java
Wed Dec 15 18:59:02 2010
@@ -272,38 +272,37 @@ public class FrameOfRef {
       // CHECKME: two other implementations might be faster:
       // - array of static methods: Method[numFrameBits].invoke(null, [this]), 
       // - array of non static decompressors: ForDecompressor[numFrameBits].decompressFrame(this)
.
-      case 1: For1Decompress.decompressFrame(this); break;
-      case 2: For2Decompress.decompressFrame(this); break;
-      case 3: For3Decompress.decompressFrame(this); break;
-      case 4: For4Decompress.decompressFrame(this); break;
-      case 5: For5Decompress.decompressFrame(this); break;
-      case 6: For6Decompress.decompressFrame(this); break;
-      case 7: For7Decompress.decompressFrame(this); break;
-      case 8: For8Decompress.decompressFrame(this); break;
-      case 9: For9Decompress.decompressFrame(this); break;
-      case 10: For10Decompress.decompressFrame(this); break;
-      case 11: For11Decompress.decompressFrame(this); break;
-      case 12: For12Decompress.decompressFrame(this); break;
-      case 13: For13Decompress.decompressFrame(this); break;
-      case 14: For14Decompress.decompressFrame(this); break;
-      case 15: For15Decompress.decompressFrame(this); break;
-      case 16: For16Decompress.decompressFrame(this); break;
-      case 17: For17Decompress.decompressFrame(this); break;
-      case 18: For18Decompress.decompressFrame(this); break;
-      case 19: For19Decompress.decompressFrame(this); break;
-      case 20: For20Decompress.decompressFrame(this); break;
-      case 21: For21Decompress.decompressFrame(this); break;
-      case 22: For22Decompress.decompressFrame(this); break;
-      case 23: For23Decompress.decompressFrame(this); break;
-      case 24: For24Decompress.decompressFrame(this); break;
-      case 25: For25Decompress.decompressFrame(this); break;
-      case 26: For26Decompress.decompressFrame(this); break;
-      case 27: For27Decompress.decompressFrame(this); break;
-      case 28: For28Decompress.decompressFrame(this); break;
-      case 29: For29Decompress.decompressFrame(this); break;
-      case 30: For30Decompress.decompressFrame(this); break;
-      case 31: For31Decompress.decompressFrame(this); break;
-      case 32: For32Decompress.decompressFrame(this); break;
+      case 1: ForDecompress.decode1(compressedBuffer, unCompressedData); break;
+      case 2: ForDecompress.decode2(compressedBuffer, unCompressedData); break;
+      case 3: ForDecompress.decode3(compressedBuffer, unCompressedData); break;
+      case 4: ForDecompress.decode4(compressedBuffer, unCompressedData); break;
+      case 5: ForDecompress.decode5(compressedBuffer, unCompressedData); break;
+      case 6: ForDecompress.decode6(compressedBuffer, unCompressedData); break;
+      case 7: ForDecompress.decode7(compressedBuffer, unCompressedData); break;
+      case 8: ForDecompress.decode8(compressedBuffer, unCompressedData); break;
+      case 9: ForDecompress.decode9(compressedBuffer, unCompressedData); break;
+      case 10: ForDecompress.decode10(compressedBuffer, unCompressedData); break;
+      case 11: ForDecompress.decode11(compressedBuffer, unCompressedData); break;
+      case 12: ForDecompress.decode12(compressedBuffer, unCompressedData); break;
+      case 13: ForDecompress.decode13(compressedBuffer, unCompressedData); break;
+      case 14: ForDecompress.decode14(compressedBuffer, unCompressedData); break;
+      case 15: ForDecompress.decode15(compressedBuffer, unCompressedData); break;
+      case 16: ForDecompress.decode16(compressedBuffer, unCompressedData); break;
+      case 17: ForDecompress.decode17(compressedBuffer, unCompressedData); break;
+      case 18: ForDecompress.decode18(compressedBuffer, unCompressedData); break;
+      case 19: ForDecompress.decode19(compressedBuffer, unCompressedData); break;
+      case 20: ForDecompress.decode20(compressedBuffer, unCompressedData); break;
+      case 21: ForDecompress.decode21(compressedBuffer, unCompressedData); break;
+      case 22: ForDecompress.decode22(compressedBuffer, unCompressedData); break;
+      case 23: ForDecompress.decode23(compressedBuffer, unCompressedData); break;
+      case 24: ForDecompress.decode24(compressedBuffer, unCompressedData); break;
+      case 25: ForDecompress.decode25(compressedBuffer, unCompressedData); break;
+      case 26: ForDecompress.decode26(compressedBuffer, unCompressedData); break;
+      case 27: ForDecompress.decode27(compressedBuffer, unCompressedData); break;
+      case 28: ForDecompress.decode28(compressedBuffer, unCompressedData); break;
+      case 29: ForDecompress.decode29(compressedBuffer, unCompressedData); break;
+      case 30: ForDecompress.decode30(compressedBuffer, unCompressedData); break;
+      case 31: ForDecompress.decode31(compressedBuffer, unCompressedData); break;
       default:
         throw new IllegalStateException("Unknown number of frame bits " + numFrameBits);
     }

Modified: lucene/dev/branches/bulkpostings/lucene/src/java/org/apache/lucene/util/pfor/gendecompress.py
URL: http://svn.apache.org/viewvc/lucene/dev/branches/bulkpostings/lucene/src/java/org/apache/lucene/util/pfor/gendecompress.py?rev=1049667&r1=1049666&r2=1049667&view=diff
==============================================================================
--- lucene/dev/branches/bulkpostings/lucene/src/java/org/apache/lucene/util/pfor/gendecompress.py
(original)
+++ lucene/dev/branches/bulkpostings/lucene/src/java/org/apache/lucene/util/pfor/gendecompress.py
Wed Dec 15 18:59:02 2010
@@ -47,9 +47,42 @@ def bitsExpr(i, numFrameBits):
     bitsInInt += " & mask"
   return bitsInInt
 
+decodeAnyMethod = '''  static void decodeAnyFrame(
+        final IntBuffer compressedBuffer, int inputSize, int numFrameBits,
+        int[] output) {
+
+    assert numFrameBits > 0 : numFrameBits;
+    assert numFrameBits <= 31 : numFrameBits;
+    final int mask = (int) ((1L<<numFrameBits) - 1);
+    int intValue1 = compressedBuffer.get();
+    output[outputOffset] = intValue1 & mask;
+    if (--inputSize == 0) return;
+    int bitPos = numFrameBits;
+
+    do {
+      while (bitPos <= (32 - numFrameBits)) {
+        // No mask needed when bitPos == (32 - numFrameBits), but prefer to avoid testing
for this:
+        output[++outputOffset] = (intValue1 >>> bitPos) & mask;
+        if (--inputSize == 0) return;
+        bitPos += numFrameBits;
+      }
+      
+      int intValue2 = compressedBuffer.get();
+      output[++outputOffset] = ( (bitPos == 32)
+                                  ? intValue2
+                                  : ((intValue1 >>> bitPos) | (intValue2 <<
(32 - bitPos)))
+                               ) & mask;
+        
+      if (--inputSize == 0) return;
+      
+      intValue1 = intValue2;
+      bitPos += numFrameBits - 32;
+    } while (true);
+  }
+'''
 
-def genDecompressClass(numFrameBits):
-  className = "For" + str(numFrameBits) + "Decompress"
+def genDecompress():
+  className = "ForDecompress"
   fileName = className + ".java"
   imports = "import java.nio.IntBuffer;\n"
   f = open(fileName, 'w')
@@ -71,51 +104,57 @@ def genDecompressClass(numFrameBits):
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- */""")
-    w("\n/* This program is generated, do not modify. See gendecompress.py */\n\n")
-    w("import java.nio.IntBuffer;\n")
-    w("class " + className + " extends ForDecompress {\n")
-    w("  static final int numFrameBits = " + str(numFrameBits) + ";\n")
-    w("  static final int mask = (int) ((1L<<numFrameBits) - 1);\n")
-    w("\n")
-    w("""  static void decompressFrame(FrameOfRef frameOfRef) {
-    int[] output = frameOfRef.unCompressedData;
-    IntBuffer compressedBuffer = frameOfRef.compressedBuffer;
-    int outputOffset = frameOfRef.offset;
-    //int inputSize = frameOfRef.unComprSize;\n""")
-    if USE_SCRATCH:
-      w('    final int[] inputInts = frameOfRef.scratch;\n')
-    #w("    while (inputSize >= 32) {\n")
-    w('    for(int step=0;step<4;step++) {\n')
-    if USE_SCRATCH:
-      w('      compressedBuffer.get(inputInts, 0, %d);\n' % numFrameBits)
-    else:
-      for i in range(numFrameBits): # declare int vars and init from buffer
-        w("      int intValue" + str(i) + " = compressedBuffer.get();\n")
-
-    for i in range(32): # set output from int vars
-      w("      output[" + str(i) + " + outputOffset] = " + bitsExpr(i, numFrameBits) + ";\n")
-    w("""      // inputSize -= 32;
-      outputOffset += 32;
-    }
-    
-    //if (inputSize > 0) {
-    //  decodeAnyFrame(compressedBuffer, bufIndex, inputSize, numFrameBits, output, outputOffset);
-    //}
-  }
-}
-""")
-  finally: f.close()
-  
-  
-
-def genDecompressClasses():
-  numFrameBits = 1
-  while numFrameBits <= 31: # 32 special case, not generated.
-    genDecompressClass(numFrameBits)
-    numFrameBits += 1
+ */
+ """)
+
+    w("/* This code is generated, do not modify. See gendecompress.py */\n\n")
+
+    w("import java.nio.IntBuffer;\n\n")
 
+    w("final class ForDecompress {\n")
 
+    w('\n  // nocommit: assess perf of this to see if specializing is really needed\n')
+
+    w('  /*\n')
+    w(decodeAnyMethod)
+    w('  */\n\n')
+
+    # We don't need the 32 bit case -- unused since java ints are
+    # signed and we only use the unsigned range (31 bits):
+    for numFrameBits in xrange(1, 32):
+
+      w('\n  // NOTE: hardwired to blockSize == 128\n')
+      if USE_SCRATCH:
+        w('  public static void decode%d(final IntBuffer compressedBuffer, final int[] output,
final int[] scratch) {\n' % numFrameBits)
+      else:
+        w('  public static void decode%d(final IntBuffer compressedBuffer, final int[] output)
{\n' % numFrameBits)
+
+      w('    final int numFrameBits = %d;\n' % numFrameBits)
+      w('    final int mask = (int) ((1L<<numFrameBits) - 1);\n')
+      w('    int outputOffset = 0;\n')
+      
+      w('    for(int step=0;step<4;step++) {\n')
+
+      if USE_SCRATCH:
+        w('      compressedBuffer.get(scratch, 0, %d);\n' % numFrameBits)
+      else:
+        for i in range(numFrameBits): # declare int vars and init from buffer
+          w("      int intValue" + str(i) + " = compressedBuffer.get();\n")
+
+      for i in range(32): # set output from int vars
+        w("      output[" + str(i) + " + outputOffset] = " + bitsExpr(i, numFrameBits) +
";\n")
+      w('      outputOffset += 32;\n')
+      w('    }\n')
+      w('  }\n')
+    w('}\n')
+      
+  finally:
+    f.close()
+
+def genSwitch():
+  for numFrameBits in xrange(1, 32):
+    print '      case %d: ForDecompress.decode%d(compressedBuffer, unCompressedData); break;'
% (numFrameBits, numFrameBits)
 
 if __name__ == "__main__":
-  genDecompressClasses()
+  genDecompress()
+  #genSwitch()



Mime
View raw message