Changeset 2869


Ignore:
Timestamp:
2001-11-28T15:14:56+13:00 (22 years ago)
Author:
paynter
Message:

Eliminate looping, use more memset and better bitmasks instead.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/phind/generate/check.h

    r2867 r2869  
    1515
    1616#include "suffix.h"
     17#include <inttypes.h>
    1718
    1819// The suffixCheck array
    19 typedef unsigned char check;
     20typedef uint8_t check;
    2021check *suffixCheck;
    2122
     
    2425
    2526// Some useful bitmask constants
    26 const check ALLBITS = 255;
    27 const check LEFTMOSTBIT = (ALLBITS << 7);
    28 const check LEFTMOSTBITS[] = {0,
    29                   (ALLBITS << 7), (ALLBITS << 6), (ALLBITS << 5), (ALLBITS << 4),
    30                   (ALLBITS << 3), (ALLBITS << 2), (ALLBITS << 1),  ALLBITS};
    31 //const check LEFTMOSTBIT = 128;
    32 //const check LEFTMOSTBITS[] = {0, 128, 192, 224, 240, 248, 252, 254, 255};
     27const check ALLBITS        = 255;
     28const check LEFTMOSTBIT    = static_cast<check>(ALLBITS << 7);
     29const check LEFTMOSTBITS[] = {static_cast<check>(ALLBITS << 8),
     30                  static_cast<check>(ALLBITS << 7),
     31                  static_cast<check>(ALLBITS << 6),
     32                  static_cast<check>(ALLBITS << 5),
     33                  static_cast<check>(ALLBITS << 4),
     34                  static_cast<check>(ALLBITS << 3),
     35                  static_cast<check>(ALLBITS << 2),
     36                  static_cast<check>(ALLBITS << 1), 
     37                  static_cast<check>(ALLBITS << 0)};
    3338
    3439
     
    5459
    5560// Get the value of a particular bit in suffixCheck
    56 inline int getSuffixCheck(cellindex suff)
     61inline int getSuffixCheck(cellindex position)
    5762{
    58   cellindex cell = suff >> 3;
    59   check remainder = suff & 0x07; // the last 3 bits
     63  cellindex cell = position >> 3;
     64  check remainder = position & 0x07; // the last 3 bits
    6065  if (suffixCheck[cell] & (LEFTMOSTBIT >> remainder)) {
    6166    return 1;
     
    6974{
    7075  cellindex cell = suff >> 3;
    71   check remainder = suff & 0x07; // the last 3 bits
     76  check remainder = suff & 0x07u; // the last 3 bits
    7277  suffixCheck[cell] |= (LEFTMOSTBIT >> remainder);
    7378
    74 
    75 
    76 // Set the value of a range of bits in suffixCheck to 1
    77 void setSuffixCheck(cellindex first, cellindex last)
    78 {
    79   for (cellcount i = first; i <= last; ++i)
    80     setSuffixCheck(i);
    81 }
    8279
    8380
     
    9289
    9390
    94 inline void setSuffixCheck_new(cellindex first, cellindex last)
     91inline void setSuffixCheck(cellindex first, cellindex last)
    9592{
    9693  // If only one bit is set, use simpler function
    97   // We should be able to remove this case.
    9894  if (first == last) {
    9995    setSuffixCheck(first);
     
    107103  // If all the values are in the same cell, set them
    108104  if (first_cell == last_cell) {
    109     setCellBits(first_cell, (first & 0x07), (last & 0x07));
     105    setCellBits(first_cell, (first & 0x07u), (last & 0x07u));
    110106    return;
    111107  }
    112108
    113109  // Set the bits in the first and last cells
    114   setCellBits(first_cell, (first & 0x07), 7);
    115   setCellBits(last_cell, 0, (last & 0x07));
     110  setCellBits(first_cell, (first & 0x07u), 7);
     111  setCellBits(last_cell, 0, (last & 0x07u));
    116112
    117113  // Set the bits in the intermediate cells
     
    129125    cout << "cell " << i << "  \t";
    130126    cout << "(" << (i * 8) << "-" << (i * 8 + 7) << ")    \t";
    131     for (cellindex j = 0; j < 8; ++j) {
     127    for (cellindex j = 0; j < 8; ++j)
    132128      cout << getSuffixCheck(i * 8 + j);
    133       // cout << " (" << (i * 8 + j) << ") ";
    134     }
    135129    cout << " (" << (unsigned int) suffixCheck[i] << ")\n";
    136130  }
    137131}
    138132
     133// To test, insert at start of main:
    139134
    140 //  To test, put this at the start of main
     135//    allocateSuffixCheck(300);
     136//    clearSuffixCheck();
    141137
    142 //  allocateSuffixCheck(300);
    143 //  clearSuffixCheck();
    144 //  setSuffixCheck(20);
    145 //  setSuffixCheck(35,50);
    146 //  setSuffixCheck(68,150);
    147 //  setSuffixCheck(170,174);
    148 //  setSuffixCheck(220,230);
    149 //  setSuffixCheck(247);
    150 //  setSuffixCheck(256);
    151 //  printSuffixCheck();
    152 //  exit(0);
     138//    setSuffixCheck(20);
     139//    setSuffixCheck(35,50);
     140//    setSuffixCheck(68,150);
     141//    setSuffixCheck(170,174);
     142//    setSuffixCheck(220,230);
     143//    setSuffixCheck(247);
     144//    setSuffixCheck(256);
    153145
     146//    printSuffixCheck();
     147//    exit(0);
     148
Note: See TracChangeset for help on using the changeset viewer.