source: trunk/lib/runtime.hpp @ 4032

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

Added experimental runtime.hpp support.

File size: 4.1 KB
Line 
1#ifndef RuntimeInfoSet_HPP_
2#define RuntimeInfoSet_HPP_
3
4/*=============================================================================
5  RuntimeInfoSet.hpp - s2k support for runtime properties and 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  April 2014
12=============================================================================*/
13
14#include <string.h>
15#include <stdint.h>
16#include <iostream>
17
18#include "bitblock.hpp"
19#include "stdio.h"
20
21#include <iostream>
22using namespace std;
23
24///////////////////////////////////////////////////////////////////////////////
25//
26// Method variants.
27//
28// BitBlock_op_ci_co()  - standard block non while loop statement and in final block if ignore the carry out
29// BitBlock_op_co()     - standard block while loop and in final block while loop if ignore carry out
30// BitBlock_op_ci()     - final block non while loop statement
31// BitBlock_op()        - final while loop statement
32//
33// BitBlock_op_ci(), BitBlock_op() methods not implemented to reduce the total number of
34// methods and resultant compiler complexity.
35//
36
37#define interpose32(x,y,pos) interpose32_<pos>(x,y)     
38template<uint32_t n>
39IDISA_ALWAYS_INLINE BitBlock interpose32_(BitBlock s, BitBlock s32) {
40        return simd_or(simd<32>::slli<n>(s), simd<32>::srli<32-n>(s32));
41}
42
43template<uint32_t n>
44IDISA_ALWAYS_INLINE BitBlock interpose64_(BitBlock s, BitBlock s64) {
45        return simd_or(simd<64>::slli<n>(s), simd<64>::srli<64-n>(s64));
46}
47
48template <uint16_t CarryCount, uint16_t AdvanceNCount> class RuntimeInfoSet;
49
50#define LocalCarryCombine(carrySet, localCarry, carryNo, carryCount)\
51carrySet.carryCombine(localCarry.cq, carryNo, carryCount); 
52
53#define DeclareRuntimeInfoSet(name, carry1_count, carryN_count)\
54RuntimeInfoSet<carry1_count, carryN_count> name;
55
56// Array of BitBlock implementation.
57template <uint16_t CarryCount, uint16_t AdvanceNCount>
58class RuntimeInfoSet {
59
60public:
61
62    uint64_t block_base;
63        BitBlock cq[CarryCount + AdvanceNCount];
64        //BitBlock pending64[AdvanceNCount];
65        RuntimeInfoSet()
66        {
67        block_base = 0;
68            memset (cq, 0, sizeof(BitBlock) * (CarryCount + AdvanceNCount));
69            //memset(pending64, 0, sizeof(BitBlock) * AdvanceNCount);
70        }
71        ~RuntimeInfoSet() {}
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
115        IDISA_ALWAYS_INLINE BitBlock & getPending64(uint16_t advance_n_blkno) 
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
125        IDISA_ALWAYS_INLINE BitBlock carryFlip(uint16_t carryno) const
126        {
127                return simd_xor(cq[carryno], simd<BLOCK_SIZE>::constant<1>());
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    IDISA_ALWAYS_INLINE uint64_t getBlockBase() const {
141        return block_base;
142    }
143   
144    IDISA_ALWAYS_INLINE void blockBaseAdjust(uint16_t val)
145        {
146                block_base += val;
147        }
148       
149};
150
151#endif // RuntimeInfoSet_HPP_
Note: See TracBrowser for help on using the repository browser.