OpenCores
URL https://opencores.org/ocsvn/connect-6/connect-6/trunk

Subversion Repositories connect-6

[/] [connect-6/] [trunk/] [XILINX/] [BUILD_SCC_SRCH/] [synth_src/] [q.cpp.tmplt] - Blame information for rev 17

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 17 sumanta.ch
 
2
#ifdef PICO_SYNTH
3
#define Q_ASSERT(_cond, _msg)
4
#include 
5
#include "pico.h"
6
#include "shared.h"
7
using namespace std;
8
#else
9
/* not synthesizable */
10
#include 
11
#include 
12
#include 
13
#include 
14
 
15
static void debug_assert (bool cond, char * msg) {
16
        if (!cond) {
17
                printf("assert failed: %s\n", msg);
18
                assert(0);
19
        }
20
}
21
 
22
#define Q_ASSERT(_cond, _msg) debug_assert(_cond, _msg)
23
#endif
24
FIFO(queue,AIMove);
25
//template 
26
class q {
27
  //tp arr[max_size];
28
        #pragma fifo_length queue max_size
29
  unsigned int head, tail;
30
  unsigned char wrapped;
31
  #pragma bitsize q.head ptr_bw
32
  #pragma bitsize q.tail ptr_bw
33
  #pragma bitsize q.wrapped 1
34
 
35
  public:
36
 
37
  /* constructor */
38
  q () { head = tail = 0; wrapped = false; };
39
 
40
 // /* returns front data of queue */
41
 // tp front () {
42
 //   return arr[head];
43
 // }
44
 
45
  bool active;
46
  /* return true iff queue is empty */
47
  bool empty () {
48
    return ((head == tail) && !wrapped);
49
  }
50
 
51
  /* return true iff queue is full */
52
  bool full () {
53
    return ((head == tail) && wrapped);
54
  }
55
 
56
  /* pop front of queue, returning the front data */
57
  /* q is corrupted if pop when empty */
58
  AIMove pop (){
59
    /* assert that before pop, queue is not empty (underflow check) */
60
    Q_ASSERT((!wrapped && (head < tail)) || (wrapped && (head >= tail)),
61
                "queue underflowed");
62
    AIMove d = pico_stream_input_queue();
63
        cout <<"pop: "<
64
    if (head == max_size-1) {
65
      head = 0;
66
      wrapped = false;
67
    } else {
68
      head = head + 1;
69
    }
70
    return d;
71
  }
72
 
73
  /* push data into back of queue */
74
  /* q is corrupted if push when full */
75
   void push (AIMove d){
76
    pico_stream_output_queue(d);
77
    if (tail == max_size-1) {
78
      tail = 0;
79
      wrapped = true;
80
    } else {
81
      tail = tail + 1;
82
    }
83
    /* assert that after push, queue is not empty (overflow check) */
84
    Q_ASSERT((!wrapped && (head < tail)) || (wrapped && (head >= tail)),
85
                "Queue overflowed") ;
86
        cout <<"push: "<
87
  }
88
 
89
  /* return current size of the queue */
90
  int size (){
91
    if (wrapped) {
92
      return (max_size - head) + (tail - 0);
93
    } else {
94
      return tail - head;
95
    }
96
  }
97
};
98
q moves_fifo;
99
//
100
//#include "shared.h"
101
//#include"q.hpp"
102
//
103
//#ifdef PICO_SYNTH
104
//#define Q_ASSERT(_cond, _msg)
105
//#include 
106
//#include "pico.h"
107
//using namespace std;
108
//#else
109
///* not synthesizable */
110
//#include 
111
//#include 
112
//#include 
113
//#include 
114
//
115
//static void debug_assert (bool cond, char * msg) {
116
//      if (!cond) {
117
//              printf("assert failed: %s\n", msg);
118
//              assert(0);
119
//      }
120
//}
121
//
122
//#define Q_ASSERT(_cond, _msg) debug_assert(_cond, _msg)
123
//#endif
124
//FIFO(queue,AIMove);
125
//
126
//  /* pop front of queue, returning the front data */
127
//  /* q is corrupted if pop when empty */
128
//  template
129
//  tp q::pop () {
130
//    /* assert that before pop, queue is not empty (underflow check) */
131
//    Q_ASSERT((!wrapped && (head < tail)) || (wrapped && (head >= tail)),
132
//              "queue underflowed");
133
//    tp d = pico_stream_input_queue();
134
//      cout <<"pop: "<
135
//    if (head == max_size-1) {
136
//      head = 0;
137
//      wrapped = false;
138
//    } else {
139
//      head = head + 1;
140
//    }
141
//    return d;
142
//  }
143
//
144
//  /* push data into back of queue */
145
//  /* q is corrupted if push when full */
146
//  template
147
//  void q::push (tp d) {
148
//    pico_stream_output_queue(d);
149
//    if (tail == max_size-1) {
150
//      tail = 0;
151
//      wrapped = true;
152
//    } else {
153
//      tail = tail + 1;
154
//    }
155
//    /* assert that after push, queue is not empty (overflow check) */
156
//    Q_ASSERT((!wrapped && (head < tail)) || (wrapped && (head >= tail)),
157
//              "Queue overflowed") ;
158
//      cout <<"push: "<
159
//  }
160
//
161
//  /* return current size of the queue */
162
//  template
163
//  int q::size () {
164
//    if (wrapped) {
165
//      return (max_size - head) + (tail - 0);
166
//    } else {
167
//      return tail - head;
168
//    }
169
//  }
170
//
171
//#ifndef PICO_SYNTH
172
//  /* not synthesizable */
173
//  std::string to_string () const {
174
//    std::string s;
175
//    std::stringstream out;
176
//
177
//    out << "{ ";
178
//
179
//    if (wrapped) {
180
//      for (int i=head; i
181
//        out << arr[i];
182
//      out << " , ";
183
//      }
184
//      for (int i=0; i
185
//        out << arr[i];
186
//      if (i != tail - 1) out << " , ";
187
//      }
188
//    } else {
189
//      for (int i=head; i
190
//        out << arr[i];
191
//      if (i != tail - 1) out << " , ";
192
//      }
193
//    }
194
//
195
//    out << " }";
196
//    s = out.str();
197
//    return s;
198
//  }
199
//
200
//  operator std::string () { return to_string(); }
201
//
202
//#endif
203
//
204
//
205
//#ifndef PICO_SYNTH
206
///* not synthesizable */
207
//template 
208
//std::ostream& operator << (std::ostream &os, const q &f)
209
//{
210
//  os << f.to_string();
211
//  return os;
212
//}
213
//#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.