small code changes...didn't make up much of the difference with the C version
authorbdemsky <bdemsky>
Fri, 26 Jun 2009 10:29:18 +0000 (10:29 +0000)
committerbdemsky <bdemsky>
Fri, 26 Jun 2009 10:29:18 +0000 (10:29 +0000)
Robust/src/Benchmarks/SingleTM/Bayes/Data.java
Robust/src/Benchmarks/SingleTM/Bayes/Sort.java

index 8ffbde1b1ea17a7bcf3acf0dc0a414cb49d4c90c..7a9b3a9784bcc3cb8ba0943747eecf0db1b561fa 100644 (file)
@@ -58,7 +58,7 @@
 public class Data {
   int numVar;
   int numRecord;
-  char[] records; /* coordination of all records */
+  byte[] records; /* coordination of all records */
   Random randomPtr;
 
   public Data() {
@@ -74,9 +74,9 @@ public class Data {
 
     if (dataPtr != null) {
       int numDatum = numVar * numRecord;
-      dataPtr.records = new char[numDatum];
+      dataPtr.records = new byte[numDatum];
       for(int i = 0; i<numDatum; i++)
-        dataPtr.records[i] = (char)DATA_INIT;
+        dataPtr.records[i] = (byte)DATA_INIT;
 
       dataPtr.numVar = numVar;
       dataPtr.numRecord = numRecord;
@@ -241,7 +241,7 @@ public class Data {
         }
         int rnd = (int) (randomPtr.random_generate() % DATA_PRECISION);
         int threshold = thresholdsTable[v][index];
-        records[startindex + v] = (char) ((rnd < threshold) ? 1 : 0);
+        records[startindex + v] = (byte) ((rnd < threshold) ? 1 : 0);
       }
       startindex += numVar;
       if(startindex > numRecord * numVar) {
@@ -282,7 +282,7 @@ public class Data {
       int numSrcDatum = srcPtr.numVar * srcPtr.numRecord;
       if (numDstDatum != numSrcDatum) {
         dstPtr.records = null;
-        dstPtr.records = new char[numSrcDatum];
+        dstPtr.records = new byte[numSrcDatum];
         if (dstPtr.records == null) {
           return false;
         }
index 1f5f0c4413982b479f3f40c481df1f4c886eaf3d..572859dec3e4c78a22ab235f4abcc2934cbe0a72 100644 (file)
@@ -94,11 +94,11 @@ public class Sort {
    * =============================================================================
    */
   public static void
-    swap (char[] base, int a, int b, int width)
+    swap (byte[] base, int a, int b, int width)
     {
       if (a != b ) {
         while (width--) {
-          char tmp = base[a];
+          byte tmp = base[a];
           base[a++] = base[b];
           base[b++] = tmp;
         }
@@ -111,7 +111,7 @@ public class Sort {
    * =============================================================================
    */
 
-  public static void shortsort(char[] base,
+  public static void shortsort(byte[] base,
       int lo,
       int hi,
       int width,
@@ -134,21 +134,14 @@ public class Sort {
    * sort
    * =============================================================================
    */
-  public void
-    sort (char[] base,
+  public static void
+    sort (byte[] base,
         int start,
         int num,
         int width,
         int n,
         int offset)
     {
-      /**
-       * debug
-       **/
-      /*
-      for(int o = 0; o< (width * (num - 1)); o++)
-        System.out.println("base["+ o +"]=" + (int)base[o]);
-      */
       if (num < 2 || width == 0) {
         return;
       }
@@ -168,71 +161,65 @@ public class Sort {
 
       int size = 0;
 
-      boolean cont = true;
-
-      ptrVal pv = new ptrVal();
-      pv.lo = lo;
-      pv.hi = hi;
-      pv.width = width;
-      pv.n = n;
-
+      int pvlo = lo;
+      int pvhi = hi;
+      int pvwidth = width;
+      int pvn = n;
+      int pvmid;
+      int pvloguy;
+      int pvhiguy;
       int typeflag;
 
-      while(cont) {
+      while(true) {
 
-        size = (pv.hi - pv.lo) / pv.width + 1;
+        size = (pvhi - pvlo) / pvwidth + 1;
  
-        /**
-         * debug
-         **/
-        //System.out.println("DEBUG: lo= "+ pv.lo + " hi= " + pv.hi + " width= " + pv.width+ " offset= " + offset + " n= " + pv.n + " size= " + size);
-
         if (size <= CUTOFF) {
 
-          shortsort(base, pv.lo, pv.hi, pv.width, pv.n, offset);
+          shortsort(base, pvlo, pvhi, pvwidth, pvn, offset);
 
         } else {
 
-          pv.mid = pv.lo + (size / 2) * pv.width;
-          swap(base, pv.mid, pv.lo, pv.width);
+          pvmid = pvlo + (size / 2) * pvwidth;
+          swap(base, pvmid, pvlo, pvwidth);
 
-          pv.loguy = pv.lo;
-          pv.higuy = pv.hi + pv.width;
+          pvloguy = pvlo;
+          pvhiguy = pvhi + pvwidth;
 
           while(true) {
             do {
-              pv.loguy += pv.width;
-            } while (pv.loguy <= pv.hi && cmp(base, pv.loguy, pv.lo, pv.n, offset) <= 0);
+              pvloguy += pvwidth;
+            } while (pvloguy <= pvhi && cmp(base, pvloguy, pvlo, pvn, offset) <= 0);
             do {
-              pv.higuy -= pv.width;
-            } while (pv.higuy > pv.lo && cmp(base, pv.higuy, pv.lo, pv.n, offset) >= 0);
-            if (pv.higuy < pv.loguy) {
+              pvhiguy -= pvwidth;
+            } while (pvhiguy > pvlo && cmp(base, pvhiguy, pvlo, pvn, offset) >= 0);
+            if (pvhiguy < pvloguy) {
               break;
             }
-            swap(base, pv.loguy, pv.higuy, pv.width);
+            swap(base, pvloguy, pvhiguy, pvwidth);
           }
 
-          swap(base, pv.lo, pv.higuy, pv.width);
+          swap(base, pvlo, pvhiguy, pvwidth);
 
-          if ((pv.higuy - 1 - pv.lo) >= (pv.hi - pv.loguy)) {
-            if (pv.lo + pv.width < pv.higuy) {
-              lostk[stkptr] = pv.lo;
-              histk[stkptr] = pv.higuy - pv.width;
+          if ((pvhiguy - 1 - pvlo) >= (pvhi - pvloguy)) {
+            if (pvlo + pvwidth < pvhiguy) {
+              lostk[stkptr] = pvlo;
+              histk[stkptr] = pvhiguy - pvwidth;
               ++stkptr;
             }
 
-            if (pv.loguy < pv.hi) {
-              pv.lo = pv.loguy;
+            if (pvloguy < pvhi) {
+              pvlo = pvloguy;
               continue;
             }
           } else {
-            if (pv.loguy < pv.hi) {
-              lostk[stkptr] = pv.loguy;
-              histk[stkptr] = pv.hi;
+            if (pvloguy < pvhi) {
+              lostk[stkptr] = pvloguy;
+              histk[stkptr] = pvhi;
               ++stkptr;
             }
-            if (pv.lo + pv.width < pv.higuy) {
-              pv.hi = pv.higuy - pv.width;
+            if (pvlo + pvwidth < pvhiguy) {
+              pvhi = pvhiguy - pvwidth;
               continue;
             }
           }
@@ -240,11 +227,11 @@ public class Sort {
 
         --stkptr;
         if (stkptr >= 0) {
-          pv.lo = lostk[stkptr];
-          pv.hi = histk[stkptr];
+          pvlo = lostk[stkptr];
+          pvhi = histk[stkptr];
           continue;
         }
-        cont = false;
+       break;
       }
     }
 
@@ -254,15 +241,15 @@ public class Sort {
    */
 
   public static int
-    cmp(char[] base, int p1, int  p2, int n, int offset)
+    cmp(byte[] base, int p1, int  p2, int n, int offset)
     {
       int i = n - offset;
       int s1 = p1 + offset;
       int s2 = p2 + offset;
 
       while (i-- > 0) {
-        char u1 = base[s1];
-        char u2 = base[s2];
+        byte u1 = base[s1];
+        byte u2 = base[s2];
         if (u1 != u2) {
           return (u1 - u2); 
         }
@@ -273,29 +260,6 @@ public class Sort {
     }
 }
 
-public class ptrVal {
-  int lo;
-  int hi;
-  int width;
-  int n;
-  int loguy;
-  int higuy;
-  int max;
-  int p;
-  int mid;
-
-  public ptrVal() {
-    lo = 0;
-    hi = 0;
-    width = 0;
-    n = 0;
-    loguy = 0;
-    higuy = 0;
-    max = 0;
-    p = 0;
-    mid = 0;
-  }
-}
 
 /* =============================================================================
  *