source: trunk/lib_c/cpp2c/expected_output/carrySet.hpp @ 3396

Last change on this file since 3396 was 3396, checked in by linmengl, 6 years ago

handle bitblock_iterator.hpp correctly now

File size: 4.0 KB
Line 
1#ifndef CARRYQ_H_
2#define CARRYQ_H_
3
4/*=============================================================================
5  carrySet.hpp - PabloJ compiler support for carry introduction.
6  Ken Herdy, Robert D. Cameron
7  Copyright (C) 2012, Robert D. Cameron, Kenneth S. Herdy.
8    Licensed to the public under the Open Software License 3.0.
9    Licensed to International Characters Inc.
10       under the Academic Free License version 3.0.
11  June 2012
12=============================================================================*/
13
14#include <string.h>
15#include <stdint.h>
16#include <iostream>
17
18#include "bitblock.h"
19#include "stdio.h"
20
21///////////////////////////////////////////////////////////////////////////////
22//
23// Method variants.
24//
25// BitBlock_op_ci_co()  - standard block non while loop statement and in final block if ignore the carry out
26// BitBlock_op_co()     - standard block while loop and in final block while loop if ignore carry out
27// BitBlock_op_ci()     - final block non while loop statement
28// BitBlock_op()        - final while loop statement
29//
30// BitBlock_op_ci(), BitBlock_op() methods not implemented to reduce the total number of
31// methods and Pablo compiler complexity.
32//
33
34#define interpose32(x,y,pos) interpose32_<pos>(x,y)     
35template<uint32_t n>
36IDISA_ALWAYS_INLINE BitBlock interpose32_(BitBlock s, BitBlock s32) {
37        return simd_or(simd_slli_32(n, s), simd_srli_32(32-n, s32));
38}
39
40template<uint32_t n>
41IDISA_ALWAYS_INLINE BitBlock interpose64_(BitBlock s, BitBlock s64) {
42        return simd_or(simd_slli_64(n, s), simd_srli_64(64-n, s64));
43}
44
45template <uint16_t CarryCount, uint16_t AdvanceNCount> class CarrySet;
46
47#define LocalCarryCombine(carrySet, localCarry, carryNo, carryCount)\
48        carrySet.carryCombine(localCarry.cq, carryNo, carryCount); 
49
50#define CarryDeclare(name, carry1_count, carryN_count)\
51CarrySet<carry1_count, carryN_count> name;
52
53// Array of BitBlock implementation.
54template <uint16_t CarryCount, uint16_t AdvanceNCount>
55class CarrySet {
56
57public:
58
59#if (BLOCK_SIZE == 128)
60    #define Carry0 simd_constant_128(0)
61    #define Carry1 simd_constant_128(1)
62#else //BLOCK_SIZE == 256
63    #define Carry0 simd_constant_256(0)
64    #define Carry1 simd_constant_256(1)
65#endif
66 
67        BitBlock cq[CarryCount + AdvanceNCount];
68        //BitBlock pending64[AdvanceNCount];
69        CarrySet()
70        {
71
72            memset (cq, 0, sizeof(BitBlock) * (CarryCount + AdvanceNCount));
73
74            //memset(pending64, 0, sizeof(BitBlock) * AdvanceNCount);
75        }
76        ~CarrySet() {}
77
78        IDISA_ALWAYS_INLINE bool carryTest(uint16_t carryno, uint16_t carry_count)
79        {
80                  BitBlock c1 = cq[carryno];
81                  int ubound = carryno + carry_count;
82                  for (int i = carryno + 1; i < ubound ; i++) {
83                        c1 = carryOr(c1, cq[i]);
84                  }
85                  return testCarry(c1);
86        }
87
88        IDISA_ALWAYS_INLINE BitBlock carryRange(uint16_t carryno, uint16_t carry_count)
89        {
90                  BitBlock c1 = cq[carryno];
91                  int ubound = carryno + carry_count;
92                  for (int i = carryno + 1; i < ubound ; i++) {
93                        c1 = carryOr(c1, cq[i]);
94                  }
95                  return c1;
96        }
97
98        IDISA_ALWAYS_INLINE void carryDequeueEnqueue(uint16_t carryno, uint16_t carry_count)
99        {
100                return;
101        }
102
103        IDISA_ALWAYS_INLINE void carryAdjust(uint16_t carry_count)
104        {
105                return;
106        }
107
108        IDISA_ALWAYS_INLINE void carryCombine(BitBlock local_cq[], uint16_t carryno, uint16_t carry_count)
109        {
110                  for (int i = 0; i < carry_count; i++) {
111                    cq[carryno+i] = carryOr(cq[carryno+i], local_cq[i]);
112                  }
113        }
114
115        IDISA_ALWAYS_INLINE BitBlock & getCarry(uint16_t carryno) 
116        {
117                return cq[carryno]; // carry2bitblock(cq[carryno]);
118        }
119
120        IDISA_ALWAYS_INLINE BitBlock & getPending64(uint16_t advance_n_blkno) 
121        {
122                return cq[CarryCount + advance_n_blkno];
123        }
124
125        IDISA_ALWAYS_INLINE void setCarry(BitBlock carryVal, uint16_t carryno)
126        {
127                cq[carryno] = carryVal;
128        }
129
130        IDISA_ALWAYS_INLINE BitBlock carryFlip(uint16_t carryno) const
131        {
132                return simd_xor(cq[carryno], Carry1);
133        }
134
135        IDISA_ALWAYS_INLINE bool testCarry(BitBlock carry) const
136        {
137                return bitblock_any(carry);
138        }
139
140        IDISA_ALWAYS_INLINE BitBlock carryOr(BitBlock carry1, BitBlock carry2) const
141        {
142                return simd_or(carry1, carry2);
143        }
144
145       
146#undef Carry0
147#undef Carry1
148
149};
150
151#endif // CARRYQ_H_
Note: See TracBrowser for help on using the repository browser.