source: trunk/lib/pabloSupport.hpp @ 3008

Last change on this file since 3008 was 3008, checked in by cameron, 6 years ago

Support for pablo.MatchStar?

File size: 4.4 KB
Line 
1/*=============================================================================
2  pabloSupport.hpp - Pablo compiler support for carry introduction.
3  Will replace deprecated carryQ.hpp
4  Copyright (C) 2012, Robert D. Cameron
5    Licensed to the public under the Open Software License 3.0.
6    Licensed to International Characters Inc.
7       under the Academic Free License version 3.0.
8  December 2012
9=============================================================================*/
10#ifndef PABLOSUPPORT_HPP_
11#define PABLOSUPPORT_HPP_
12
13#include "bitblock.hpp"
14
15#define BitBlock_declare(name)  BitBlock name
16
17#define ubitblock_declare(name, n) \
18  ubitblock name[n];\
19  do {int i;\
20      for (i = 0; i < n; i++) name[i]._128 = simd<1>::constant<0>();\
21     }\
22  while (0)
23     
24
25const BitBlock simd_const_1 = mvmd<BLOCK_SIZE/4>::fill4(0,0,0,1); 
26
27IDISA_ALWAYS_INLINE BitBlock pablo_blk_Advance(BitBlock strm, BitBlock carryin, BitBlock & rslt) {
28        BitBlock carryout;
29        adv_ci_co(strm, carryin, carryout, rslt);
30        return carryout;
31}
32
33template <int n> IDISA_ALWAYS_INLINE BitBlock pablo_blk_Advance_n_(BitBlock strm, BitBlock pending_in, BitBlock & rslt) {
34        BitBlock half_block_shifted = esimd<BLOCK_SIZE/2>::mergel(strm, pending_in);
35        rslt = simd_or(simd<BLOCK_SIZE/2>::srli<(BLOCK_SIZE/2)-n>(half_block_shifted),
36                       simd<BLOCK_SIZE/2>::slli<n>(strm));
37        return strm;
38}
39
40/*  Support for pablo.Lookahead.  2 translation modes:
41    (a) pablo.Lookahead(ss.strm, n) ==> pablo_blk_Lookahead_n_<n>(ss_curblock.strm, ss_nxtblock.strm);
42    (b) pablo.Lookahead(ss.strm, n) ==> pablo_blk_Lookahead_n_<n>(ss[0].strm, ss[1].strm);
43*/
44template <int n> IDISA_ALWAYS_INLINE BitBlock pablo_blk_Lookahead_n_(BitBlock strm, BitBlock lookahead) {
45        BitBlock half_block_shifted = mvmd<BLOCK_SIZE/2>::dslli<1>(lookahead, strm);
46        return simd_or(simd<BLOCK_SIZE/2>::slli<(BLOCK_SIZE/2)-n>(half_block_shifted),
47                       simd<BLOCK_SIZE/2>::srli<n>(strm));
48}
49
50IDISA_ALWAYS_INLINE BitBlock pablo_blk_ScanThru(BitBlock marker, BitBlock charclass, BitBlock carryin, BitBlock & rslt) {
51        BitBlock carryout, sum;
52        add_ci_co(marker, charclass, carryin, carryout, sum);
53        rslt = simd_andc(sum, charclass);
54        return carryout;
55}
56
57IDISA_ALWAYS_INLINE BitBlock pablo_blk_MatchStar(BitBlock marker, BitBlock charclass, BitBlock carryin, BitBlock & rslt) {
58        BitBlock carryout, sum;
59        BitBlock
60        add_ci_co(marker, simd_and(charclass, marker), carryin, carryout, sum);
61        rslt = simd_or(simd_xor(sum, charclass), marker);
62        return carryout;
63}
64
65IDISA_ALWAYS_INLINE BitBlock pablo_blk_AdvanceThenScanThru(BitBlock marker, BitBlock charclass, BitBlock carryin, BitBlock & rslt) {
66        BitBlock carryout, sum;
67        add_ci_co(marker, simd_or(charclass, marker), carryin, carryout, sum);
68        rslt = simd_andc(sum, charclass);
69        return carryout;
70}
71
72IDISA_ALWAYS_INLINE BitBlock pablo_blk_ScanTo(BitBlock marker, BitBlock charclass, BitBlock carryin, BitBlock & rslt) {
73        BitBlock carryout, sum;
74        add_ci_co(marker, simd_not(charclass), carryin, carryout, sum);
75        rslt = simd_and(sum, charclass);
76        return carryout;
77}
78
79IDISA_ALWAYS_INLINE BitBlock pablo_blk_AdvanceThenScanTo(BitBlock marker, BitBlock charclass, BitBlock carryin, BitBlock & rslt) {
80        BitBlock carryout, sum;
81        add_ci_co(marker, simd_or(marker, simd_not(charclass)), carryin, carryout, sum);
82        rslt = simd_and(sum, charclass);
83        return carryout;
84}
85
86IDISA_ALWAYS_INLINE BitBlock pablo_blk_ScanToFirst(BitBlock charclass, BitBlock carryin, BitBlock & rslt) {
87        BitBlock carryout, sum;
88        add_ci_co(simd<BLOCK_SIZE>::constant<0>(), simd_not(charclass), carryin, carryout, sum);
89        rslt = simd_and(sum, charclass);
90        return carryout;
91}
92
93IDISA_ALWAYS_INLINE BitBlock pablo_blk_SpanUpTo(BitBlock starts, BitBlock follows, BitBlock carryin, BitBlock & rslt) {
94        BitBlock carryout;
95        sub_bi_bo(follows, starts, carryin, carryout, rslt);
96        return carryout;
97}
98
99IDISA_ALWAYS_INLINE BitBlock pablo_blk_InclusiveSpan(BitBlock starts, BitBlock follows, BitBlock carryin, BitBlock & rslt) {
100        BitBlock carryout, span;
101        sub_bi_bo(follows, starts, carryin, carryout, span);
102        rslt = simd_or(span, follows);
103        return carryout;
104}
105
106IDISA_ALWAYS_INLINE BitBlock pablo_blk_ExclusiveSpan(BitBlock starts, BitBlock follows, BitBlock carryin, BitBlock & rslt) {
107        BitBlock carryout, span;
108        sub_bi_bo(follows, starts, carryin, carryout, span);
109        rslt = simd_andc(span, starts);
110        return carryout;
111}
112
113
114
115#endif // PABLOSUPPORT_HPP_
Note: See TracBrowser for help on using the repository browser.