source: trunk/lib/pabloSupport.hpp @ 2874

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

Support for pablo.Lookahead

File size: 4.0 KB
RevLine 
[2719]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=============================================================================*/
[2610]10#ifndef PABLOSUPPORT_HPP_
11#define PABLOSUPPORT_HPP_
12
13#include "bitblock.hpp"
14
[2694]15#define BitBlock_declare(name)  BitBlock name
[2610]16
[2705]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     
[2610]24
[2795]25const BitBlock simd_const_1 = mvmd<BLOCK_SIZE/4>::fill4(0,0,0,1); 
26
[2610]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
[2698]33template <int n> IDISA_ALWAYS_INLINE BitBlock pablo_blk_Advance_n_(BitBlock strm, BitBlock pending_in, BitBlock & rslt) {
[2696]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));
[2698]37        return strm;
[2696]38}
39
[2874]40/*  Support for pablo.Lookahead.  2 translation modes:
41    (a) pablo.Lookahead(ss.strm, n) ==> pablo_Lookahead_n_<n>(ss_curblock.strm, ss_nxtblock.strm);
42    (b) pablo.Lookahead(ss.strm, n) ==> pablo_Lookahead_n_<n>(ss[0].strm, ss[1].strm);
43*/
44template <int n> IDISA_ALWAYS_INLINE BitBlock pablo_Lookahead_n_(BitBlock strm, BitBlock lookahead) {
45        BitBlock half_block_shifted = esimd<BLOCK_SIZE/2>::mergel(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
[2610]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_AdvanceThenScanThru(BitBlock marker, BitBlock charclass, BitBlock carryin, BitBlock & rslt) {
58        BitBlock carryout, sum;
59        add_ci_co(marker, simd_or(charclass, marker), carryin, carryout, sum);
60        rslt = simd_andc(sum, charclass);
61        return carryout;
62}
63
64IDISA_ALWAYS_INLINE BitBlock pablo_blk_ScanTo(BitBlock marker, BitBlock charclass, BitBlock carryin, BitBlock & rslt) {
65        BitBlock carryout, sum;
66        add_ci_co(marker, simd_not(charclass), carryin, carryout, sum);
67        rslt = simd_and(sum, charclass);
68        return carryout;
69}
70
71IDISA_ALWAYS_INLINE BitBlock pablo_blk_AdvanceThenScanTo(BitBlock marker, BitBlock charclass, BitBlock carryin, BitBlock & rslt) {
72        BitBlock carryout, sum;
73        add_ci_co(marker, simd_or(marker, simd_not(charclass)), carryin, carryout, sum);
74        rslt = simd_and(sum, charclass);
75        return carryout;
76}
77
78IDISA_ALWAYS_INLINE BitBlock pablo_blk_ScanToFirst(BitBlock charclass, BitBlock carryin, BitBlock & rslt) {
79        BitBlock carryout, sum;
80        add_ci_co(simd<BLOCK_SIZE>::constant<0>(), simd_not(charclass), carryin, carryout, sum);
81        rslt = simd_and(sum, charclass);
82        return carryout;
83}
84
85IDISA_ALWAYS_INLINE BitBlock pablo_blk_SpanUpTo(BitBlock starts, BitBlock follows, BitBlock carryin, BitBlock & rslt) {
86        BitBlock carryout;
87        sub_bi_bo(follows, starts, carryin, carryout, rslt);
88        return carryout;
89}
90
91IDISA_ALWAYS_INLINE BitBlock pablo_blk_InclusiveSpan(BitBlock starts, BitBlock follows, BitBlock carryin, BitBlock & rslt) {
92        BitBlock carryout, span;
93        sub_bi_bo(follows, starts, carryin, carryout, span);
94        rslt = simd_or(span, follows);
95        return carryout;
96}
97
98IDISA_ALWAYS_INLINE BitBlock pablo_blk_ExclusiveSpan(BitBlock starts, BitBlock follows, BitBlock carryin, BitBlock & rslt) {
99        BitBlock carryout, span;
100        sub_bi_bo(follows, starts, carryin, carryout, span);
101        rslt = simd_andc(span, starts);
102        return carryout;
103}
104
105
106
107#endif // PABLOSUPPORT_HPP_
Note: See TracBrowser for help on using the repository browser.