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

Updates for carry_t = uint64_t support

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.