mp3decoder finally passes the flow-down rule checking.
[IRC.git] / Robust / src / Tests / ssJava / mp3decoder / BitReserve.java
index 24794c1aecfeee440410a1a4639469ede4c62af4..e4167f00b0048a7c334801c46521dfba40f69068 100644 (file)
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
  *----------------------------------------------------------------------\r
  */\r
-       \r
+\r
 /**\r
  * Implementation of Bit Reservoir for Layer III.\r
  * <p>\r
- * The implementation stores single bits as a word in the buffer. If\r
- * a bit is set, the corresponding word in the buffer will be non-zero.\r
- * If a bit is clear, the corresponding word is zero. Although this\r
- * may seem waseful, this can be a factor of two quicker than \r
- * packing 8 bits to a byte and extracting. \r
- * <p> \r
+ * The implementation stores single bits as a word in the buffer. If a bit is\r
+ * set, the corresponding word in the buffer will be non-zero. If a bit is\r
+ * clear, the corresponding word is zero. Although this may seem waseful, this\r
+ * can be a factor of two quicker than packing 8 bits to a byte and extracting.\r
+ * <p>\r
  */\r
 \r
 // REVIEW: there is no range checking, so buffer underflow or overflow\r
 // can silently occur.\r
-final class BitReserve\r
-{\r
-   /**\r
-    * Size of the internal buffer to store the reserved bits.\r
-    * Must be a power of 2. And x8, as each bit is stored as a single\r
-    * entry.\r
-    */\r
-       private static final int                BUFSIZE = 4096*8;\r
-       \r
-       /**\r
-        * Mask that can be used to quickly implement the\r
-        * modulus operation on BUFSIZE.\r
-        */\r
-       private static final int                BUFSIZE_MASK = BUFSIZE-1;\r
-       \r
-       private int                                     offset, totbit, buf_byte_idx;\r
-       private final int[]                     buf = new int[BUFSIZE];\r
-       private int                                     buf_bit_idx;\r
-       \r
-   BitReserve()\r
-   {\r
-         \r
-         offset = 0;\r
-      totbit = 0;\r
-      buf_byte_idx = 0;          \r
-   }\r
-      \r
-   \r
-   /**\r
-    * Return totbit Field.\r
-       */\r
-   public int hsstell() \r
-   { \r
-          return(totbit); \r
-   }\r
-\r
-   /**\r
-    * Read a number bits from the bit stream.\r
-    * @param N the number of\r
-       */\r
-   public int hgetbits(int N)\r
-   {\r
-        totbit += N;\r
-        \r
-        int val = 0;\r
-        \r
-        int pos = buf_byte_idx;\r
-        if (pos+N < BUFSIZE)\r
-        {\r
-               while (N-- > 0)\r
-               {\r
-                       val <<= 1;\r
-                       val |= ((buf[pos++]!=0) ? 1 : 0);                \r
-               }\r
-       }\r
-        else\r
-        {       \r
-                while (N-- > 0)\r
-               {\r
-                        val <<= 1;                      \r
-                        val |= ((buf[pos]!=0) ? 1 : 0);\r
-                        pos = (pos+1) & BUFSIZE_MASK;\r
-               }                \r
-        }      \r
-        buf_byte_idx = pos;\r
-        return val;\r
-   }\r
-   \r
-        \r
-   \r
-   /**\r
-    * Read 1 bit from the bit stream.\r
-       */\r
-/*\r
-   public int hget1bit_old()\r
-   {\r
-         int val;\r
-         totbit++;\r
-         if (buf_bit_idx == 0)\r
-         {\r
-         buf_bit_idx = 8;\r
-            buf_byte_idx++;             \r
-         }\r
-      // BUFSIZE = 4096 = 2^12, so\r
-      // buf_byte_idx%BUFSIZE == buf_byte_idx & 0xfff\r
-      val = buf[buf_byte_idx & BUFSIZE_MASK] & putmask[buf_bit_idx];\r
-      buf_bit_idx--;\r
-         val = val >>> buf_bit_idx;\r
-      return val;   \r
-   }\r
- */\r
-   /**\r
-    * Returns next bit from reserve.\r
-    * @returns 0 if next bit is reset, or 1 if next bit is set.\r
-    */\r
-   public int hget1bit()\r
-   {             \r
-         totbit++;       \r
-         int val = buf[buf_byte_idx];\r
-         buf_byte_idx = (buf_byte_idx+1) & BUFSIZE_MASK;\r
-      return val;\r
-   }\r
-   \r
-   /**\r
-    * Retrieves bits from the reserve.     \r
-    */\r
-/*   \r
-   public int readBits(int[] out, int len)\r
-   {\r
-               if (buf_bit_idx == 0)\r
-               {\r
-                  buf_bit_idx = 8;\r
-                  buf_byte_idx++;\r
-                  current = buf[buf_byte_idx & BUFSIZE_MASK];\r
-               }      \r
-               \r
-               \r
-               \r
-               // save total number of bits returned\r
-               len = buf_bit_idx;\r
-               buf_bit_idx = 0;\r
-                 \r
-               int b = current;\r
-               int count = len-1;\r
-                 \r
-               while (count >= 0)\r
-               {\r
-                   out[count--] = (b & 0x1);\r
-                   b >>>= 1;\r
-               }\r
-         \r
-               totbit += len;\r
-               return len;\r
-   }\r
-  */\r
-   \r
-   /**\r
-    * Write 8 bits into the bit stream.\r
-       */\r
-   public void hputbuf(int val)\r
-   {             \r
-          int ofs = offset;\r
-          buf[ofs++] = val & 0x80;\r
-          buf[ofs++] = val & 0x40;\r
-          buf[ofs++] = val & 0x20;\r
-          buf[ofs++] = val & 0x10;\r
-          buf[ofs++] = val & 0x08;\r
-          buf[ofs++] = val & 0x04;\r
-          buf[ofs++] = val & 0x02;\r
-          buf[ofs++] = val & 0x01;\r
-          \r
-          if (ofs==BUFSIZE)\r
-                       offset = 0;\r
-          else\r
-                       offset = ofs;\r
-          \r
-   }\r
\r
-   /**\r
-    * Rewind N bits in Stream.\r
-       */\r
-   public void rewindNbits(int N)\r
-   {\r
-         totbit -= N;            \r
-         buf_byte_idx -= N;\r
-         if (buf_byte_idx<0)\r
-                 buf_byte_idx += BUFSIZE;\r
-   }\r
-       \r
-   /**\r
-    * Rewind N bytes in Stream.\r
-       */\r
-   public void rewindNbytes(int N)\r
-   {\r
-      int bits = (N << 3);\r
-         totbit -= bits;\r
-         buf_byte_idx -= bits;   \r
-         if (buf_byte_idx<0)\r
-                 buf_byte_idx += BUFSIZE;\r
-   }\r
+@LATTICE("BUF<OFF,BUF<BIT,BIT*,OFF*")\r
+@METHODDEFAULT("OUT<THIS,THIS<IN,IN*,THISLOC=THIS,RETURNLOC=OUT")\r
+final class BitReserve {\r
+  /**\r
+   * Size of the internal buffer to store the reserved bits. Must be a power of\r
+   * 2. And x8, as each bit is stored as a single entry.\r
+   */\r
+  private static final int BUFSIZE = 4096 * 8;\r
+\r
+  /**\r
+   * Mask that can be used to quickly implement the modulus operation on\r
+   * BUFSIZE.\r
+   */\r
+  private static final int BUFSIZE_MASK = BUFSIZE - 1;\r
+\r
+  @LOC("BIT")\r
+  private int offset;\r
+\r
+  @LOC("BIT")\r
+  private int totbit;\r
+\r
+  @LOC("BIT")\r
+  private int buf_byte_idx;\r
+\r
+  @LOC("BIT")\r
+  private final int[] buf;\r
+\r
+  BitReserve() {\r
+    offset = 0;\r
+    totbit = 0;\r
+    buf_byte_idx = 0;\r
+    buf = new int[BUFSIZE];\r
+  }\r
+\r
+  /**\r
+   * Return totbit Field.\r
+   */\r
+  @RETURNLOC("THIS,BitReserve.BIT")\r
+  public int hsstell() {\r
+    return (totbit);\r
+  }\r
+\r
+  /**\r
+   * Read a number bits from the bit stream.\r
+   * \r
+   * @param N\r
+   *          the number of\r
+   */\r
+  public int hgetbits(@LOC("THIS,BitReserve.BIT") int N) {\r
+\r
+    totbit += N;\r
+\r
+    @LOC("OUT") int val = 0;\r
+\r
+    @LOC("THIS,BitReserve.BIT") int pos = buf_byte_idx;\r
+    if (pos + N < BUFSIZE) {\r
+      while (N-- > 0) {\r
+        val <<= 1;\r
+        val |= ((buf[pos++] != 0) ? 1 : 0);\r
+      }\r
+    } else {\r
+      while (N-- > 0) {\r
+        val <<= 1;\r
+        val |= ((buf[pos] != 0) ? 1 : 0);\r
+        pos = (pos + 1) & BUFSIZE_MASK;\r
+      }\r
+    }\r
+\r
+    buf_byte_idx = pos;\r
+\r
+    return val;\r
+\r
+  }\r
+\r
+  /**\r
+   * Returns next bit from reserve.\r
+   * \r
+   * @returns 0 if next bit is reset, or 1 if next bit is set.\r
+   */\r
+  @RETURNLOC("THIS,BitReserve.BIT")\r
+  public int hget1bit() {\r
+    totbit++;\r
+    @LOC("THIS,BitReserve.BIT") int val = buf[buf_byte_idx];\r
+    buf_byte_idx = (buf_byte_idx + 1) & BUFSIZE_MASK;\r
+    return val;\r
+  }\r
+\r
+  /**\r
+   * Write 8 bits into the bit stream.\r
+   */\r
+  @LATTICE("OUT<THIS,THIS<IN,THISLOC=THIS,GLOBALLOC=IN")\r
+  public void hputbuf(@LOC("IN") int val) {\r
+    @LOC("THIS,BitReserve.OFF") int ofs = offset;\r
+    buf[ofs++] = val & 0x80;\r
+    buf[ofs++] = val & 0x40;\r
+    buf[ofs++] = val & 0x20;\r
+    buf[ofs++] = val & 0x10;\r
+    buf[ofs++] = val & 0x08;\r
+    buf[ofs++] = val & 0x04;\r
+    buf[ofs++] = val & 0x02;\r
+    buf[ofs++] = val & 0x01;\r
+\r
+    if (ofs == BUFSIZE)\r
+      offset = 0;\r
+    else\r
+      offset = ofs;\r
+\r
+  }\r
+\r
+  /**\r
+   * Rewind N bits in Stream.\r
+   */\r
+  public void rewindNbits(@LOC("THIS,BitReserve.BIT") int N) {\r
+    totbit -= N;\r
+    buf_byte_idx -= N;\r
+    if (buf_byte_idx < 0)\r
+      buf_byte_idx += BUFSIZE;\r
+  }\r
+\r
+  /**\r
+   * Rewind N bytes in Stream.\r
+   */\r
+  @LATTICE("THIS<BIT,BIT<N,THISLOC=THIS,GLOBALLOC=N")\r
+  public void rewindNbytes(@LOC("N") int N) {\r
+    @LOC("BIT") int bits = (N << 3);\r
+    totbit -= bits;\r
+    buf_byte_idx -= bits;\r
+    if (buf_byte_idx < 0)\r
+      buf_byte_idx += BUFSIZE;\r
+  }\r
 }\r