source: trunk/lib/carryQ.h @ 764

Last change on this file since 764 was 764, checked in by cameron, 9 years ago

Use carry ADT abstractions.

File size: 2.6 KB
Line 
1//
2// carryQ.h
3// Robert D. Cameron
4// November 29, 2010 - first version without actual queueing.
5//
6
7#include "block_carry.h"
8
9#define CarryQtype CarryType *
10
11#define CarryDeclare(name, count)\
12CarryType name[count];\
13for (int j=0; j < count; j++) name[j] = Carry0
14
15static inline BitBlock BitBlock_advance_ci_co(BitBlock strm, CarryQtype cq, int carryno) {
16 BitBlock rslt;
17 advance_with_carry(strm, cq[carryno], rslt);
18 return rslt;
19}
20
21static inline BitBlock BitBlock_advance_co(BitBlock strm, CarryQtype cq, int carryno) {
22 BitBlock rslt;
23 cq[carryno] = Carry0;
24 advance_with_carry(strm, cq[carryno], rslt);
25 return rslt;
26}
27
28static inline BitBlock BitBlock_add_ci_co(BitBlock strm1, BitBlock strm2, CarryQtype cq, int carryno) {
29 BitBlock sum;
30 adc128(strm1, strm2, cq[carryno], sum);
31 return sum;
32}
33
34static inline BitBlock BitBlock_add_co(BitBlock strm1, BitBlock strm2, CarryQtype cq, int carryno) {
35 BitBlock sum;
36 cq[carryno] = Carry0;
37 adc128(strm1, strm2, cq[carryno], sum);
38 return sum;
39}
40
41static inline BitBlock BitBlock_sub_ci_co(BitBlock strm1, BitBlock strm2, CarryQtype cq, int carryno) {
42 BitBlock diff;
43 sbb128(strm1, strm2, cq[carryno], diff);
44 return diff;
45}
46
47static inline BitBlock BitBlock_sub_co(BitBlock strm1, BitBlock strm2, CarryQtype cq, int carryno) {
48 BitBlock diff;
49 cq[carryno] = Carry0;
50 sbb128(strm1, strm2, cq[carryno], diff);
51 return diff;
52}
53
54static inline BitBlock BitBlock_scanthru_ci_co(BitBlock markers0, BitBlock charclass, CarryQtype cq, int carryno) {
55 BitBlock markers1;
56 adc128(markers0, charclass, cq[carryno], markers1);
57 return simd_andc(markers1, charclass);
58}
59
60static inline BitBlock BitBlock_scanthru_co(BitBlock markers0, BitBlock charclass, CarryQtype cq, int carryno) {
61 BitBlock markers1;
62 cq[carryno] = Carry0;
63 adc128(markers0, charclass, cq[carryno], markers1);
64 return simd_andc(markers1, charclass);
65}
66
67static inline bool CarryTest(CarryQtype cq, int carryno, int carry_count) {
68  CarryType c1 = cq[carryno];
69  int i;
70  for (i = carryno + 1; i < carryno + carry_count; i++) {
71    c1 = carry_or(c1, cq[i]);
72  }
73  return test_carry(c1);
74}
75
76static inline void CarryDequeueEnqueue(CarryQtype cq, int carryno, int carry_count) {
77  // Given carryin queue with carry_count carries starting from carryno are 0,
78  // ensure that the carryout queue has carry_count carries starting from carryno set to 0.
79  // Nothing to do when the queues are the same!
80  return;
81}
82
83static inline void CarryCombine(CarryQtype cq, CarryQtype local_cq, int carryno, int carry_count) {
84  int i;
85  for (i = 0; i < carry_count; i++) {
86    cq[carryno+i] = carry_or(cq[carryno+i], local_cq[i]);
87  }
88}
89
Note: See TracBrowser for help on using the repository browser.