source: trunk/lib_c/carrySet.h @ 4063

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

check in IDISA C library and other support libraries. Some template features still remain.

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