Changeset 1975 for trunk


Ignore:
Timestamp:
Mar 25, 2012, 11:23:24 AM (7 years ago)
Author:
cameron
Message:

Defining carry_t; allows different storage represenations for carries.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/bitblock128.hpp

    r1950 r1975  
    2323};
    2424
    25 static IDISA_ALWAYS_INLINE void adc(bitblock128_t x, bitblock128_t y, bitblock128_t & carry, bitblock128_t & sum);
    26 static IDISA_ALWAYS_INLINE void sbb(bitblock128_t x, bitblock128_t y, bitblock128_t & borrow, bitblock128_t & difference);
    27 static IDISA_ALWAYS_INLINE void advance_with_carry(bitblock128_t cursor, bitblock128_t & carry, bitblock128_t & rslt);
    28 static IDISA_ALWAYS_INLINE bool bitblock_has_bit(bitblock128_t arg1);
    29 static IDISA_ALWAYS_INLINE void signbitmask(bitblock128_t & v);
     25/* The type used to store a carry bit. */
     26typedef bitblock128_t carry_t;
     27
     28static IDISA_ALWAYS_INLINE bitblock128_t carry2bitblock(carry_t carry);
     29static IDISA_ALWAYS_INLINE carry_t bitblock2carry(bitblock128_t carry);
     30
     31static IDISA_ALWAYS_INLINE void adc(bitblock128_t x, bitblock128_t y, carry_t & carry, bitblock128_t & sum);
     32static IDISA_ALWAYS_INLINE void sbb(bitblock128_t x, bitblock128_t y, carry_t & borrow, bitblock128_t & difference);
     33static IDISA_ALWAYS_INLINE void advance_with_carry(bitblock128_t cursor, carry_t & carry, bitblock128_t & rslt);
     34
    3035static IDISA_ALWAYS_INLINE bitblock128_t convert (uint64_t s);
    3136static IDISA_ALWAYS_INLINE uint64_t convert (bitblock128_t v);
    3237
    33 IDISA_ALWAYS_INLINE void adc(bitblock128_t x, bitblock128_t y, bitblock128_t & carry, bitblock128_t & sum)
     38static IDISA_ALWAYS_INLINE bitblock128_t carry2bitblock(carry_t carry) {  return carry;}
     39static IDISA_ALWAYS_INLINE carry_t bitblock2carry(bitblock128_t carry) {  return carry;}
     40
     41IDISA_ALWAYS_INLINE void adc(bitblock128_t x, bitblock128_t y, carry_t & carry, bitblock128_t & sum)
    3442{
    3543        bitblock128_t gen = simd_and(x, y);
    3644        bitblock128_t prop = simd_or(x, y);
    37         bitblock128_t partial = simd128<64>::add(simd128<64>::add(x, y), carry);
     45        bitblock128_t partial = simd128<64>::add(simd128<64>::add(x, y), carry2bitblock(carry));
    3846        bitblock128_t c1 = simd128<128>::slli<64>(simd128<64>::srli<63>(simd_or(gen, simd_andc(prop, partial))));
    3947        sum = simd128<64>::add(c1, partial);
    40         // carry = simd_and(hibitmask<bitblock128_t>(), simd_or(gen, simd_andc(prop, sum))); // TODO - set high bit carry via hibitmask
    41         carry = simd128<128>::srli<127>(simd_or(gen, simd_andc(prop, sum))); // TODO -
     48        carry = bitblock2carry(simd128<128>::srli<127>(simd_or(gen, simd_andc(prop, sum))));
    4249}
    4350
    44 IDISA_ALWAYS_INLINE void sbb(bitblock128_t x, bitblock128_t y, bitblock128_t & borrow, bitblock128_t & difference)
     51IDISA_ALWAYS_INLINE void sbb(bitblock128_t x, bitblock128_t y, carry_t & borrow, bitblock128_t & difference)
    4552{
    4653        bitblock128_t gen = simd_andc(y, x);
    4754        bitblock128_t prop = simd_not(simd_xor(x, y));
    48         bitblock128_t partial = simd128<64>::sub(simd128<64>::sub(x, y), borrow);
     55        bitblock128_t partial = simd128<64>::sub(simd128<64>::sub(x, y), carry2bitblock(borrow));
    4956        bitblock128_t b1 = simd128<128>::slli<64>(simd128<64>::srli<63>(simd_or(gen, simd_and(prop, partial))));
    5057        difference = simd128<64>::sub(partial, b1);
    51         // borrow = simd_and(hibitmask<bitblock128_t>, simd_or(gen, simd_and(prop, difference))); // TODO - set high bit carry via hibitmask
    52         borrow = simd128<128>::srli<127>(simd_or(gen, simd_and(prop, difference)));
     58        borrow = bitblock2carry(simd128<128>::srli<127>(simd_or(gen, simd_and(prop, difference))));
    5359}
    5460
    55 IDISA_ALWAYS_INLINE void advance_with_carry(bitblock128_t cursor, bitblock128_t & carry, bitblock128_t & rslt)
     61IDISA_ALWAYS_INLINE void advance_with_carry(bitblock128_t cursor, carry_t & carry, bitblock128_t & rslt)
    5662{
    5763bitblock128_t shift_out = simd128<64>::srli<63>(cursor);
    58 bitblock128_t low_bits = esimd128<64>::mergel(shift_out, carry);
    59 // carry = simd_and(hibitmask<bitblock128_t>, cursor);
    60 carry = simd128<128>::srli<64>(shift_out);                                              // carry - accumlated 127 shift right locical shift of cursor
     64bitblock128_t low_bits = esimd128<64>::mergel(shift_out, carry2bitblock(carry));
     65carry = bitblock2carry(simd128<128>::srli<64>(shift_out));
    6166rslt = simd_or(simd128<64>::add(cursor, cursor), low_bits);
    62 }
    63 
    64 IDISA_ALWAYS_INLINE void signbitmask(bitblock128_t & v)
    65 {
    66         v =  simd128<128>::slli<127>(simd128<128>::constant<1>());
    6767}
    6868
Note: See TracChangeset for help on using the changeset viewer.