source: trunk/lib/carrySet.hpp @ 4063

Last change on this file since 4063 was 3721, checked in by ksherdy, 5 years ago

Updated name.

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