Changeset 723


Ignore:
Timestamp:
Nov 28, 2010, 2:29:02 PM (8 years ago)
Author:
cameron
Message:

Make a single typedef for BitBlock?, uint64x2 union.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/block_carry.h

    r534 r723  
    2727
    2828
     29typedef union {SIMD_type bitblock; uint64_t int64[2];} BitBlock_int64;
    2930
    3031
     
    8081
    8182#define adc128(first, second, carry, sum) \
    82 do\
    83 {\
    84   union {__m128i bitblock;\
    85          uint64_t int64[2];} rslt;\
    86 \
    87   union {__m128i bitblock;\
    88          uint64_t int64[2];} x;\
    89 \
    90   union {__m128i bitblock;\
    91          uint64_t int64[2];} y;\
    92 \
    93   x.bitblock = first;\
    94   y.bitblock = second;\
    95 \
     83do {\
     84  BitBlock_int64 rslt, x, y;\
     85  x.bitblock = first;\
     86  y.bitblock = second;\
     87  double_int64_adc(x.int64[0], x.int64[1], y.int64[0], y.int64[1], rslt.int64[0], rslt.int64[1], carry);\
     88  sum = rslt.bitblock;\
     89} while(0)
     90
     91
     92
     93#define advance_with_carry(cursor, carry, rslt)\
     94    adc128(cursor, cursor, carry, rslt)
     95
     96
     97#define double_int64_sbb(x1, x2, y1, y2, rslt1, rslt2, carry) \
     98  __asm__  ("sahf\n\t" \
     99        "sbb %[e1], %[z1]\n\t" \
     100        "sbb %[e2], %[z2]\n\t" \
     101        "lahf\n\t" \
     102     : [z1] "=r" (rslt1), [z2] "=r" (rslt2), [carryflag] "=a" (carry) \
     103         : "[z1]" (x1), "[z2]" (x2), \
     104           [e1] "r" (y1), [e2] "r" (y2), \
     105           "[carryflag]" (carry) \
     106         : "cc")
     107
     108#define sbb128(first, second, borrow, diff) \
     109do {\
     110  BitBlock_int64 rslt, x, y;\
     111  x.bitblock = first;\
     112  y.bitblock = second;\
     113  double_int64_sbb(x.int64[0], x.int64[1], y.int64[0], y.int64[1], \
     114                   rslt.int64[0], rslt.int64[1], borrow);\
     115  diff = rslt.bitblock;\
     116} while(0)
     117
     118#endif
     119
     120#if (CARRY_STRATEGY == ADC64_SAHF_STRATEGY)
     121typedef uint64_t CarryType;
     122
     123#define Carry0 0
     124
     125#define test_carry(x) (((x)&256) > 0)
     126
     127#define carry_or(carry1, carry2) (carry1 | carry2)
     128
     129#define double_int64_adc(x1, x2, y1, y2, rslt1, rslt2, carry) \
     130  __asm__  ("sahf\n\t" \
     131        "adc %[e1], %[z1]\n\t" \
     132        "adc %[e2], %[z2]\n\t" \
     133        "lahf\n\t" \
     134     : [z1] "=r" (rslt1), [z2] "=r" (rslt2), [carryflag] "=a" (carry) \
     135         : "[z1]" (x1), "[z2]" (x2), \
     136           [e1] "r" (y1), [e2] "r" (y2), \
     137           "[carryflag]" (carry) \
     138         : "cc")
     139
     140#define adc128(first, second, carry, sum) \
     141do {\
     142  BitBlock_int64 rslt, x, y;\
     143  x.bitblock = first;\
     144  y.bitblock = second;\
    96145  double_int64_adc(x.int64[0], x.int64[1], y.int64[0], y.int64[1], rslt.int64[0], rslt.int64[1], carry);\
    97146  sum = rslt.bitblock;\
     
    100149
    101150
     151#define double_int64_advance(x1, x2, rslt1, rslt2, carry) \
     152  __asm__  ("sahf\n\t" \
     153        "adc %[z1], %[z1]\n\t" \
     154        "adc %[z2], %[z2]\n\t" \
     155        "lahf\n\t" \
     156     : [z1] "=r" (rslt1), [z2] "=r" (rslt2), [carryflag] "=a" (carry) \
     157         : "[z1]" (x1), "[z2]" (x2), \
     158           "[carryflag]" (carry) \
     159         : "cc")
     160
     161
    102162#define advance_with_carry(cursor, carry, rslt)\
    103     adc128(cursor, cursor, carry, rslt)
     163do {\
     164  BitBlock_int64 x, z;\
     165  x.bitblock = cursor;\
     166  double_int64_advance(x.int64[0], x.int64[1], z.int64[0], z.int64[1], carry);\
     167  rslt = z.bitblock;\
     168} while(0)
     169
     170
    104171
    105172
     
    116183
    117184#define sbb128(first, second, borrow, diff) \
    118 do\
    119 { union {__m128i bitblock;\
    120          uint64_t int64[2];} rslt;\
    121 \
    122   union {__m128i bitblock;\
    123          uint64_t int64[2];} x;\
    124 \
    125   union {__m128i bitblock;\
    126          uint64_t int64[2];} y;\
    127 \
    128   x.bitblock = first;\
    129   y.bitblock = second;\
    130 \
    131   double_int64_sbb(x.int64[0], x.int64[1], y.int64[0], y.int64[1], \
    132                    rslt.int64[0], rslt.int64[1], borrow);\
    133   diff = rslt.bitblock;\
    134 }while(0)
    135 
    136 #endif
    137 
    138 #if (CARRY_STRATEGY == ADC64_SAHF_STRATEGY)
    139 typedef uint64_t CarryType;
    140 
    141 #define Carry0 0
    142 
    143 #define test_carry(x) (((x)&256) > 0)
    144 
    145 #define carry_or(carry1, carry2) (carry1 | carry2)
    146 
    147 #define double_int64_adc(x1, x2, y1, y2, rslt1, rslt2, carry) \
    148   __asm__  ("sahf\n\t" \
    149         "adc %[e1], %[z1]\n\t" \
    150         "adc %[e2], %[z2]\n\t" \
    151         "lahf\n\t" \
    152      : [z1] "=r" (rslt1), [z2] "=r" (rslt2), [carryflag] "=a" (carry) \
    153          : "[z1]" (x1), "[z2]" (x2), \
    154            [e1] "r" (y1), [e2] "r" (y2), \
    155            "[carryflag]" (carry) \
    156          : "cc")
    157 
    158 #define adc128(first, second, carry, sum) \
    159 do\
    160 {\
    161   union {__m128i bitblock;\
    162          uint64_t int64[2];} rslt;\
    163 \
    164   union {__m128i bitblock;\
    165          uint64_t int64[2];} x;\
    166 \
    167   union {__m128i bitblock;\
    168          uint64_t int64[2];} y;\
    169 \
    170   x.bitblock = first;\
    171   y.bitblock = second;\
    172 \
    173   double_int64_adc(x.int64[0], x.int64[1], y.int64[0], y.int64[1], rslt.int64[0], rslt.int64[1], carry);\
    174   sum = rslt.bitblock;\
    175 }while(0)
    176 
    177 
    178 
    179 #define double_int64_advance(x1, x2, rslt1, rslt2, carry) \
    180   __asm__  ("sahf\n\t" \
    181         "adc %[z1], %[z1]\n\t" \
    182         "adc %[z2], %[z2]\n\t" \
    183         "lahf\n\t" \
    184      : [z1] "=r" (rslt1), [z2] "=r" (rslt2), [carryflag] "=a" (carry) \
    185          : "[z1]" (x1), "[z2]" (x2), \
    186            "[carryflag]" (carry) \
    187          : "cc")
    188 
    189 
    190 #define advance_with_carry(cursor, carry, rslt)\
    191 do\
    192 {\
    193   union {__m128i bitblock;\
    194          uint64_t int64[2];} z;\
    195 \
    196   union {__m128i bitblock;\
    197          uint64_t int64[2];} x;\
    198 \
    199   x.bitblock = cursor;\
    200 \
    201   double_int64_advance(x.int64[0], x.int64[1], z.int64[0], z.int64[1], carry);\
    202   rslt = z.bitblock;\
    203 }while(0)
    204 
    205 
    206 
    207 
    208 #define double_int64_sbb(x1, x2, y1, y2, rslt1, rslt2, carry) \
    209   __asm__  ("sahf\n\t" \
    210         "sbb %[e1], %[z1]\n\t" \
    211         "sbb %[e2], %[z2]\n\t" \
    212         "lahf\n\t" \
    213      : [z1] "=r" (rslt1), [z2] "=r" (rslt2), [carryflag] "=a" (carry) \
    214          : "[z1]" (x1), "[z2]" (x2), \
    215            [e1] "r" (y1), [e2] "r" (y2), \
    216            "[carryflag]" (carry) \
    217          : "cc")
    218 
    219 #define sbb128(first, second, borrow, diff) \
    220 do\
    221 { union {__m128i bitblock;\
    222          uint64_t int64[2];} rslt;\
    223 \
    224   union {__m128i bitblock;\
    225          uint64_t int64[2];} x;\
    226 \
    227   union {__m128i bitblock;\
    228          uint64_t int64[2];} y;\
    229 \
    230   x.bitblock = first;\
    231   y.bitblock = second;\
    232 \
     185do {\
     186  BitBlock_int64 rslt, x, y;\
     187  x.bitblock = first;\
     188  y.bitblock = second;\
    233189  double_int64_sbb(x.int64[0], x.int64[1], y.int64[0], y.int64[1], \
    234190                   rslt.int64[0], rslt.int64[1], borrow);\
     
    273229
    274230#define advance_with_carry(cursor, carry, rslt)\
    275 do{\
     231do {\
    276232  SIMD_type shift_out = simd_srli_64(cursor, 63);\
    277233  SIMD_type low_bits = simd_mergel_64(shift_out, carry);\
    278234  carry = sisd_srli(shift_out, 64);\
    279235  rslt = simd_or(simd_add_64(cursor, cursor), low_bits);\
    280 }while(0)
    281 
    282 #endif
    283 #endif
    284 
    285 
     236} while(0)
     237
     238#endif
     239#endif
     240
     241
Note: See TracChangeset for help on using the changeset viewer.