source: trunk/lib/pabloSupport.hpp @ 3019

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

Add simd_sign_bit constant

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
27const BitBlock simd_sign_bit = bitblock::slli<BLOCK_SIZE-1>(simd_const_1); 
28
29IDISA_ALWAYS_INLINE BitBlock pablo_blk_Advance(BitBlock strm, BitBlock carryin, BitBlock & rslt) {
30        BitBlock carryout;
31        adv_ci_co(strm, carryin, carryout, rslt);
32        return carryout;
33}
34
35template <int n> IDISA_ALWAYS_INLINE BitBlock pablo_blk_Advance_n_(BitBlock strm, BitBlock pending_in, BitBlock & rslt) {
36        BitBlock half_block_shifted = esimd<BLOCK_SIZE/2>::mergel(strm, pending_in);
37        rslt = simd_or(simd<BLOCK_SIZE/2>::srli<(BLOCK_SIZE/2)-n>(half_block_shifted),
38                       simd<BLOCK_SIZE/2>::slli<n>(strm));
39        return strm;
40}
41
42/*  Support for pablo.Lookahead.  2 translation modes:
43    (a) pablo.Lookahead(ss.strm, n) ==> pablo_blk_Lookahead_n_<n>(ss_curblock.strm, ss_nxtblock.strm);
44    (b) pablo.Lookahead(ss.strm, n) ==> pablo_blk_Lookahead_n_<n>(ss[0].strm, ss[1].strm);
45*/
46template <int n> IDISA_ALWAYS_INLINE BitBlock pablo_blk_Lookahead_n_(BitBlock strm, BitBlock lookahead) {
47        BitBlock half_block_shifted = mvmd<BLOCK_SIZE/2>::dslli<1>(lookahead, strm);
48        return simd_or(simd<BLOCK_SIZE/2>::slli<(BLOCK_SIZE/2)-n>(half_block_shifted),
49                       simd<BLOCK_SIZE/2>::srli<n>(strm));
50}
51
52IDISA_ALWAYS_INLINE BitBlock pablo_blk_ScanThru(BitBlock marker, BitBlock charclass, BitBlock carryin, BitBlock & rslt) {
53        BitBlock carryout, sum;
54        add_ci_co(marker, charclass, carryin, carryout, sum);
55        rslt = simd_andc(sum, charclass);
56        return carryout;
57}
58
59IDISA_ALWAYS_INLINE BitBlock pablo_blk_MatchStar(BitBlock marker, BitBlock charclass, BitBlock carryin, BitBlock & rslt) {
60        BitBlock carryout, sum;
61        add_ci_co(simd_and(charclass, marker), charclass, carryin, carryout, sum);
62        rslt = simd_or(simd_xor(sum, charclass), marker);
63        return carryout;
64}
65
66IDISA_ALWAYS_INLINE BitBlock pablo_blk_AdvanceThenScanThru(BitBlock marker, BitBlock charclass, BitBlock carryin, BitBlock & rslt) {
67        BitBlock carryout, sum;
68        add_ci_co(marker, simd_or(charclass, marker), carryin, carryout, sum);
69        rslt = simd_andc(sum, charclass);
70        return carryout;
71}
72
73IDISA_ALWAYS_INLINE BitBlock pablo_blk_ScanTo(BitBlock marker, BitBlock charclass, BitBlock carryin, BitBlock & rslt) {
74        BitBlock carryout, sum;
75        add_ci_co(marker, simd_not(charclass), carryin, carryout, sum);
76        rslt = simd_and(sum, charclass);
77        return carryout;
78}
79
80IDISA_ALWAYS_INLINE BitBlock pablo_blk_AdvanceThenScanTo(BitBlock marker, BitBlock charclass, BitBlock carryin, BitBlock & rslt) {
81        BitBlock carryout, sum;
82        add_ci_co(marker, simd_or(marker, simd_not(charclass)), carryin, carryout, sum);
83        rslt = simd_and(sum, charclass);
84        return carryout;
85}
86
87IDISA_ALWAYS_INLINE BitBlock pablo_blk_ScanToFirst(BitBlock charclass, BitBlock carryin, BitBlock & rslt) {
88        BitBlock carryout, sum;
89        add_ci_co(simd<BLOCK_SIZE>::constant<0>(), simd_not(charclass), carryin, carryout, sum);
90        rslt = simd_and(sum, charclass);
91        return carryout;
92}
93
94IDISA_ALWAYS_INLINE BitBlock pablo_blk_SpanUpTo(BitBlock starts, BitBlock follows, BitBlock carryin, BitBlock & rslt) {
95        BitBlock carryout;
96        sub_bi_bo(follows, starts, carryin, carryout, rslt);
97        return carryout;
98}
99
100IDISA_ALWAYS_INLINE BitBlock pablo_blk_InclusiveSpan(BitBlock starts, BitBlock follows, BitBlock carryin, BitBlock & rslt) {
101        BitBlock carryout, span;
102        sub_bi_bo(follows, starts, carryin, carryout, span);
103        rslt = simd_or(span, follows);
104        return carryout;
105}
106
107IDISA_ALWAYS_INLINE BitBlock pablo_blk_ExclusiveSpan(BitBlock starts, BitBlock follows, BitBlock carryin, BitBlock & rslt) {
108        BitBlock carryout, span;
109        sub_bi_bo(follows, starts, carryin, carryout, span);
110        rslt = simd_andc(span, starts);
111        return carryout;
112}
113
114
115
116#endif // PABLOSUPPORT_HPP_
Note: See TracBrowser for help on using the repository browser.