source: trunk/lib/carrySet.hpp @ 3318

Last change on this file since 3318 was 3318, checked in by ksherdy, 6 years ago

Removed unused methods.

File size: 3.9 KB
Line 
1#ifndef CARRYQ_HPP_
2#define CARRYQ_HPP_
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.hpp"
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<32>::slli<n>(s), simd<32>::srli<32-n>(s32));
38}
39
40template<uint32_t n>
41IDISA_ALWAYS_INLINE BitBlock interpose64_(BitBlock s, BitBlock s64) {
42        return simd_or(simd<64>::slli<n>(s), simd<64>::srli<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    #define Carry0 simd<BLOCK_SIZE>::constant<0>()
60    #define Carry1 simd<BLOCK_SIZE>::constant<1>()
61 
62        BitBlock cq[CarryCount + AdvanceNCount];
63        //BitBlock pending64[AdvanceNCount];
64        CarrySet()
65        {
66            memset (cq, 0, sizeof(BitBlock) * (CarryCount + AdvanceNCount));
67            //memset(pending64, 0, sizeof(BitBlock) * AdvanceNCount);
68        }
69        ~CarrySet() {}
70
71        IDISA_ALWAYS_INLINE bool carryTest(uint16_t carryno, uint16_t carry_count)
72        {
73                  BitBlock c1 = cq[carryno];
74                  int ubound = carryno + carry_count;
75                  for (int i = carryno + 1; i < ubound ; i++) {
76                        c1 = carryOr(c1, cq[i]);
77                  }
78                  return testCarry(c1);
79        }
80
81        IDISA_ALWAYS_INLINE BitBlock carryRange(uint16_t carryno, uint16_t carry_count)
82        {
83                  BitBlock c1 = cq[carryno];
84                  int ubound = carryno + carry_count;
85                  for (int i = carryno + 1; i < ubound ; i++) {
86                        c1 = carryOr(c1, cq[i]);
87                  }
88                  return c1;
89        }
90
91        IDISA_ALWAYS_INLINE void carryDequeueEnqueue(uint16_t carryno, uint16_t carry_count)
92        {
93                return;
94        }
95
96        IDISA_ALWAYS_INLINE void carryAdjust(uint16_t carry_count)
97        {
98                return;
99        }
100
101        IDISA_ALWAYS_INLINE void carryCombine(BitBlock local_cq[], uint16_t carryno, uint16_t carry_count)
102        {
103                  for (int i = 0; i < carry_count; i++) {
104                    cq[carryno+i] = carryOr(cq[carryno+i], local_cq[i]);
105                  }
106        }
107
108        IDISA_ALWAYS_INLINE BitBlock & getCarry(uint16_t carryno) 
109        {
110                return cq[carryno]; // carry2bitblock(cq[carryno]);
111        }
112
113        IDISA_ALWAYS_INLINE BitBlock & getPending64(uint16_t advance_n_blkno) 
114        {
115                return cq[CarryCount + advance_n_blkno];
116        }
117
118        IDISA_ALWAYS_INLINE void setCarry(BitBlock carryVal, uint16_t carryno)
119        {
120                cq[carryno] = carryVal;
121        }
122
123        IDISA_ALWAYS_INLINE BitBlock carryFlip(BitBlock carry) const
124        {
125                return simd_xor(carry, Carry1);
126        }
127
128        IDISA_ALWAYS_INLINE bool testCarry(BitBlock carry) const
129        {
130                return bitblock::any(carry);
131        }
132
133        IDISA_ALWAYS_INLINE BitBlock carryOr(BitBlock carry1, BitBlock carry2) const
134        {
135                return simd_or(carry1, carry2);
136        }
137
138       
139#undef Carry0
140#undef Carry1
141
142};
143
144#endif // CARRYQ_HPP_
Note: See TracBrowser for help on using the repository browser.