Changeset 3519 for trunk


Ignore:
Timestamp:
Sep 18, 2013, 9:49:50 AM (5 years ago)
Author:
cameron
Message:

Updates for carry_t = uint64_t support

Location:
trunk/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/bitblock256.hpp

    r3453 r3519  
    2626
    2727/* The type used to store a carry bit. */
     28#ifndef CARRY64
    2829typedef bitblock256_t carry_t;
     30#endif
     31#ifdef CARRY64
     32typedef uint64_t carry_t;
     33#endif
    2934
    3035static IDISA_ALWAYS_INLINE void add_ci_co(bitblock256_t x, bitblock256_t y, carry_t carry_in, carry_t & carry_out, bitblock256_t & sum);
    3136static IDISA_ALWAYS_INLINE void sub_bi_bo(bitblock256_t x, bitblock256_t y, carry_t borrow_in, carry_t & borrow_out, bitblock256_t & difference);
    32 static IDISA_ALWAYS_INLINE void adv_ci_co(bitblock256_t cursor, bitblock256_t carry_in, bitblock256_t & carry_out, bitblock256_t & rslt);
     37static IDISA_ALWAYS_INLINE void adv_ci_co(bitblock256_t cursor, carry_t carry_in, carry_t & carry_out, bitblock256_t & rslt);
    3338
    3439
     
    3944static IDISA_ALWAYS_INLINE carry_t carryout2carry(bitblock256_t carryout);
    4045
     46
    4147static IDISA_ALWAYS_INLINE void adc(bitblock256_t x, bitblock256_t y, carry_t & carry, bitblock256_t & sum);
    4248static IDISA_ALWAYS_INLINE void sbb(bitblock256_t x, bitblock256_t y, carry_t & borrow, bitblock256_t & difference);
     
    5157static IDISA_ALWAYS_INLINE uint64_t convert (bitblock256_t v);
    5258
     59#ifndef CARRY64
    5360static IDISA_ALWAYS_INLINE bitblock256_t carry2bitblock(carry_t carry) {  return carry;}
    5461static IDISA_ALWAYS_INLINE carry_t bitblock2carry(bitblock256_t carry) {  return carry;}
    55 
    56 static IDISA_ALWAYS_INLINE carry_t carryout2carry(bitblock256_t carryout) {
     62static IDISA_ALWAYS_INLINE uint64_t carry2uint64(carry_t carry) {  return convert(carry);}
     63static IDISA_ALWAYS_INLINE carry_t uint2carry(uint64_t carry) {  return convert(carry);}
     64#endif
     65#ifdef CARRY64
     66static IDISA_ALWAYS_INLINE bitblock256_t carry2bitblock(carry_t carry) {  return convert(carry);}
     67static IDISA_ALWAYS_INLINE carry_t bitblock2carry(bitblock256_t carry) {  return convert(carry);}
     68static IDISA_ALWAYS_INLINE uint64_t carry2uint64(carry_t carry) {  return carry;}
     69static IDISA_ALWAYS_INLINE carry_t uint2carry(uint64_t carry) {  return carry;}
     70#endif
     71
     72static IDISA_ALWAYS_INLINE carry_t carryout2carry(carry_t carryout) {
    5773  return carryout;
    5874}
     
    6581  bitblock256_t carry = simd_or(gen, simd_andc(prop, partial_sum));
    6682  bitblock256_t bubble = simd256<64>::eq(partial_sum, all_ones);
    67   uint64_t carry_mask = hsimd256<64>::signmask(carry) * 2 + convert(carry_in);
     83  uint64_t carry_mask = hsimd256<64>::signmask(carry) * 2 + carry2uint64(carry_in);
    6884  uint64_t bubble_mask = hsimd256<64>::signmask(bubble);
    6985  uint64_t carry_scan_thru_bubbles = (carry_mask + bubble_mask) &~ bubble_mask;
    7086  uint64_t increments = carry_scan_thru_bubbles | (carry_scan_thru_bubbles - carry_mask);
    71   carry_out = convert(increments >> 4);
     87  carry_out = uint2carry(increments >> 4);
    7288  uint64_t spread = 0x0000200040008001 * increments & 0x0001000100010001;
    7389  sum = simd256<64>::add(partial_sum, _mm256_cvtepu16_epi64(avx_select_lo128(convert(spread))));
     
    8096  bitblock256_t borrow = simd_or(gen, simd_and(prop, partial_diff));
    8197  bitblock256_t bubble = simd256<64>::eq(partial_diff, simd<1>::constant<0>());
    82   uint64_t borrow_mask = hsimd256<64>::signmask(borrow) * 2 + convert(borrow_in);
     98  uint64_t borrow_mask = hsimd256<64>::signmask(borrow) * 2 + carry2uint64(borrow_in);
    8399  uint64_t bubble_mask = hsimd256<64>::signmask(bubble);
    84100  uint64_t borrow_scan_thru_bubbles = (borrow_mask + bubble_mask) &~ bubble_mask;
    85101  uint64_t decrements = borrow_scan_thru_bubbles | (borrow_scan_thru_bubbles - borrow_mask);
    86   borrow_out = convert(decrements >> 4);
     102  borrow_out = uint2carry(decrements >> 4);
    87103  uint64_t spread = 0x0000200040008001 * decrements & 0x0001000100010001;
    88104  difference = simd256<64>::sub(partial_diff, _mm256_cvtepu16_epi64(avx_select_lo128(convert(spread))));
    89105}
    90106
    91 static IDISA_ALWAYS_INLINE void adv_ci_co(bitblock256_t cursor, bitblock256_t carry_in, bitblock256_t & carry_out, bitblock256_t & rslt){
     107static IDISA_ALWAYS_INLINE void adv_ci_co(bitblock256_t cursor, carry_t carry_in, carry_t & carry_out, bitblock256_t & rslt){
    92108        bitblock256_t shift_out = simd256<64>::srli<63>(cursor);
    93         bitblock256_t low_bits = simd_or(mvmd256<64>::slli<1>(shift_out), carry_in);
    94         carry_out = mvmd256<64>::srli<3>(shift_out);
     109        bitblock256_t low_bits = simd_or(mvmd256<64>::slli<1>(shift_out), carry2bitblock(carry_in));
     110        carry_out = bitblock2carry(mvmd256<64>::srli<3>(shift_out));
    95111        rslt = simd_or(simd256<64>::add(cursor, cursor), low_bits);
    96112}
  • trunk/lib/carryQ.hpp

    r3457 r3519  
    5858public:
    5959
     60#ifndef CARRY64
    6061    #define Carry0 simd<BLOCK_SIZE>::constant<0>()
    6162    #define Carry1 simd<BLOCK_SIZE>::constant<1>()
    62  
     63#endif
     64#ifdef CARRY64
     65    #define Carry0 0
     66    #define Carry1 1
     67#endif
     68
    6369        carry_t cq[CarryCount + AdvanceNCount];
    6470        //BitBlock pending64[AdvanceNCount];
    6571        CarryArray()
    6672        {
    67             memset (cq, 0, sizeof(BitBlock) * (CarryCount + AdvanceNCount));
     73            memset (cq, 0, sizeof(carry_t) * (CarryCount + AdvanceNCount));
    6874            //memset(pending64, 0, sizeof(BitBlock) * AdvanceNCount);
    6975        }
    7076        ~CarryArray() {}
    7177
    72         IDISA_ALWAYS_INLINE BitBlock BitBlock_advance_ci_co(BitBlock strm, BitBlock carryin, uint16_t carryno)
     78        IDISA_ALWAYS_INLINE BitBlock BitBlock_advance_ci_co(BitBlock strm, carry_t carryin, uint16_t carryno)
    7379        {
    7480                BitBlock rslt;
     
    7783        }
    7884
    79         IDISA_ALWAYS_INLINE BitBlock BitBlock_add_ci_co(BitBlock strm1, BitBlock strm2, BitBlock carryin, const uint16_t carryno)
     85        IDISA_ALWAYS_INLINE BitBlock BitBlock_add_ci_co(BitBlock strm1, BitBlock strm2, carry_t carryin, const uint16_t carryno)
    8086        {
    8187                BitBlock sum;
     
    8490        }
    8591
    86         IDISA_ALWAYS_INLINE BitBlock BitBlock_sub_ci_co(BitBlock strm1, BitBlock strm2, BitBlock carryin, uint16_t carryno)
     92        IDISA_ALWAYS_INLINE BitBlock BitBlock_sub_ci_co(BitBlock strm1, BitBlock strm2, carry_t carryin, uint16_t carryno)
    8793        {
    8894                BitBlock diff;
     
    9197        }
    9298
    93         IDISA_ALWAYS_INLINE BitBlock BitBlock_scantofirst(BitBlock charclass, BitBlock carryin, uint16_t carryno)
     99        IDISA_ALWAYS_INLINE BitBlock BitBlock_scantofirst(BitBlock charclass, carry_t carryin, uint16_t carryno)
    94100        {
    95101                BitBlock marker;
     
    100106        }
    101107
    102         IDISA_ALWAYS_INLINE BitBlock BitBlock_scanthru_ci_co(BitBlock markers0, BitBlock charclass, BitBlock carryin, uint16_t carryno)
     108        IDISA_ALWAYS_INLINE BitBlock BitBlock_scanthru_ci_co(BitBlock markers0, BitBlock charclass, carry_t carryin, uint16_t carryno)
    103109        {
    104110                BitBlock markers1;
     
    107113        }
    108114
    109         IDISA_ALWAYS_INLINE BitBlock BitBlock_advance_then_scanthru(BitBlock markers0, BitBlock charclass, BitBlock carryin, uint16_t carryno)
     115        IDISA_ALWAYS_INLINE BitBlock BitBlock_advance_then_scanthru(BitBlock markers0, BitBlock charclass, carry_t carryin, uint16_t carryno)
    110116        {
    111117                BitBlock markers1;
     
    115121        }
    116122
    117         IDISA_ALWAYS_INLINE BitBlock BitBlock_span_upto(BitBlock starts, BitBlock follows, BitBlock carryin, uint16_t carryno)
     123        IDISA_ALWAYS_INLINE BitBlock BitBlock_span_upto(BitBlock starts, BitBlock follows, carry_t carryin, uint16_t carryno)
    118124        {
    119125                BitBlock span;
     
    122128        }
    123129
    124         IDISA_ALWAYS_INLINE BitBlock BitBlock_inclusive_span(BitBlock starts, BitBlock ends, BitBlock carryin, uint16_t carryno)
     130        IDISA_ALWAYS_INLINE BitBlock BitBlock_inclusive_span(BitBlock starts, BitBlock ends, carry_t carryin, uint16_t carryno)
    125131        {
    126132                BitBlock span;
     
    129135        }
    130136
    131         IDISA_ALWAYS_INLINE BitBlock BitBlock_exclusive_span(BitBlock starts, BitBlock ends, BitBlock carryin, uint16_t carryno)
     137        IDISA_ALWAYS_INLINE BitBlock BitBlock_exclusive_span(BitBlock starts, BitBlock ends, carry_t carryin, uint16_t carryno)
    132138        {
    133139                BitBlock span;
     
    136142        }
    137143
    138 
     144/*
    139145        IDISA_ALWAYS_INLINE BitBlock BitBlock_advance32_ci_co(BitBlock strm, uint32_t pending_in, uint32_t & pending_out)
    140146        {
     
    142148                return simd_or(simd<BLOCK_SIZE>::slli<32>(strm), mvmd<BLOCK_SIZE>::fill((uint64_t)pending_in));
    143149        }
    144 
    145         template <int n> IDISA_ALWAYS_INLINE BitBlock BitBlock_advance_n_(BitBlock strm, BitBlock pending_in, uint16_t pendingno)
     150*/
     151
     152/*
     153        template <int n> IDISA_ALWAYS_INLINE BitBlock BitBlock_advance_n_(BitBlock strm, carry_t pending_in, uint16_t pendingno)
    146154        {
    147155                BitBlock half_block_shifted = esimd<BLOCK_SIZE/2>::mergel(strm, pending_in);
     
    152160                return result;
    153161        }
     162*/
    154163
    155164        IDISA_ALWAYS_INLINE bool CarryTest(uint16_t carryno, uint16_t carry_count)
    156165        {
    157                   BitBlock c1 = cq[carryno];
     166                  carry_t c1 = cq[carryno];
    158167                  int ubound = carryno + carry_count;
    159168                  for (int i = carryno + 1; i < ubound ; i++) {
     
    163172        }
    164173
    165         IDISA_ALWAYS_INLINE BitBlock CarryRange(uint16_t carryno, uint16_t carry_count)
    166         {
    167                   BitBlock c1 = cq[carryno];
     174        IDISA_ALWAYS_INLINE carry_t CarryRange(uint16_t carryno, uint16_t carry_count)
     175        {
     176                  carry_t c1 = cq[carryno];
    168177                  int ubound = carryno + carry_count;
    169178                  for (int i = carryno + 1; i < ubound ; i++) {
     
    189198        }
    190199
    191         IDISA_ALWAYS_INLINE void CarryCombine(BitBlock local_cq[], uint16_t carryno, uint16_t carry_count)
     200        IDISA_ALWAYS_INLINE void CarryCombine(carry_t local_cq[], uint16_t carryno, uint16_t carry_count)
    192201        {
    193202                  for (int i = 0; i < carry_count; i++) {
     
    202211        }
    203212
    204         IDISA_ALWAYS_INLINE BitBlock get_carry_in(uint16_t carryno) const
    205         {
    206                 return carry2bitblock(cq[carryno]);
    207         }
    208 
    209         // Deprecated (renamed)
    210         IDISA_ALWAYS_INLINE BitBlock GetCarry(uint16_t carryno) const
    211         {
    212                 return carry2bitblock(cq[carryno]);
    213         }
    214 
    215         IDISA_ALWAYS_INLINE void SetCarry(BitBlock carryVal, uint16_t carryno)
     213        IDISA_ALWAYS_INLINE carry_t get_carry_in(uint16_t carryno) const
     214        {
     215                return cq[carryno];
     216        }
     217
     218        // Deprecated (renamed)
     219        IDISA_ALWAYS_INLINE carry_t GetCarry(uint16_t carryno) const
     220        {
     221                return cq[carryno];
     222        }
     223
     224        IDISA_ALWAYS_INLINE void SetCarry(carry_t carryVal, uint16_t carryno)
    216225        {
    217226                cq[carryno] = carryVal;
     
    220229
    221230        // Deprecated in PabloJ, retained for legacy compiler.
    222         IDISA_ALWAYS_INLINE BitBlock get_pending64(uint16_t advance_n_blkno) const
     231        IDISA_ALWAYS_INLINE carry_t get_pending64(uint16_t advance_n_blkno) const
    223232        {
    224233                return cq[CarryCount + advance_n_blkno];
    225234        }
    226235
    227         IDISA_ALWAYS_INLINE BitBlock Pending64(uint16_t advance_n_blkno) const
     236        IDISA_ALWAYS_INLINE carry_t Pending64(uint16_t advance_n_blkno) const
    228237        {
    229238                return cq[CarryCount + advance_n_blkno];
     
    232241//private:
    233242        // helpers
    234 
    235         // Deprecated (renamed)
    236         IDISA_ALWAYS_INLINE BitBlock carry_flip(BitBlock carry) const
     243#ifndef  CARRY64
     244        // Deprecated (renamed)
     245        IDISA_ALWAYS_INLINE carry_t carry_flip(carry_t carry) const
    237246        {
    238247                return simd_xor(carry, Carry1);
    239248        }
    240249
    241         IDISA_ALWAYS_INLINE BitBlock CarryFlip(BitBlock carry) const
     250        IDISA_ALWAYS_INLINE BitBlock CarryFlip(carry_t carry) const
    242251        {
    243252                return simd_xor(carry, Carry1);
    244253        }
    245254
    246         IDISA_ALWAYS_INLINE bool test_carry(BitBlock carry) const
     255        IDISA_ALWAYS_INLINE bool test_carry(carry_t carry) const
    247256        {
    248257                return bitblock::any(carry);
    249258        }
    250259
    251         IDISA_ALWAYS_INLINE BitBlock carry_or(BitBlock carry1, BitBlock carry2) const
     260        IDISA_ALWAYS_INLINE carry_t carry_or(carry_t carry1, carry_t carry2) const
    252261        {
    253262                return simd_or(carry1, carry2);
    254263        }
    255        
    256 #undef Carry0
    257 #undef Carry1
     264#endif
     265#ifdef  CARRY64
     266        // Deprecated (renamed)
     267        IDISA_ALWAYS_INLINE carry_t carry_flip(carry_t carry) const
     268        {
     269                return carry ^ 1;
     270        }
     271
     272        IDISA_ALWAYS_INLINE BitBlock CarryFlip(carry_t carry) const
     273        {
     274                return carry ^ 1;
     275        }
     276
     277        IDISA_ALWAYS_INLINE bool test_carry(carry_t carry) const
     278        {
     279                return carry != 0;
     280        }
     281
     282        IDISA_ALWAYS_INLINE carry_t carry_or(carry_t carry1, carry_t carry2) const
     283        {
     284                return carry1 | carry2;
     285        }
     286#endif
    258287
    259288};
  • trunk/lib/pabloSupport.hpp

    r3457 r3519  
    125125}
    126126
    127 template <typename T> IDISA_ALWAYS_INLINE carry_t pablo_blk_match(T bytedata[], const T match_str[], BitBlock v, int len) {
     127
     128template <typename T> IDISA_ALWAYS_INLINE BitBlock pablo_blk_match(T bytedata[], const T match_str[], BitBlock v, int len) {
    128129        union {BitBlock bitblock; ScanWord elems[sizeof(BitBlock)/sizeof(ScanWord)];} u;
    129130        u.bitblock = v;
Note: See TracChangeset for help on using the changeset viewer.