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] - Rev 17
Compare with Previous | Blame | View Log
#ifdef PICO_SYNTH
#define Q_ASSERT(_cond, _msg)
#include <iostream>
#include "pico.h"
#include "shared.h"
using namespace std;
#else
/* not synthesizable */
#include <iostream>
#include <sstream>
#include <string>
#include <assert.h>
static void debug_assert (bool cond, char * msg) {
if (!cond) {
printf("assert failed: %s\n", msg);
assert(0);
}
}
#define Q_ASSERT(_cond, _msg) debug_assert(_cond, _msg)
#endif
FIFO(queue,AIMove);
//template <class tp=AIMove, int max_size=128, int ptr_bw=32>
class q {
//tp arr[max_size];
#pragma fifo_length queue max_size
unsigned int head, tail;
unsigned char wrapped;
#pragma bitsize q.head ptr_bw
#pragma bitsize q.tail ptr_bw
#pragma bitsize q.wrapped 1
public:
/* constructor */
q () { head = tail = 0; wrapped = false; };
// /* returns front data of queue */
// tp front () {
// return arr[head];
// }
bool active;
/* return true iff queue is empty */
bool empty () {
return ((head == tail) && !wrapped);
}
/* return true iff queue is full */
bool full () {
return ((head == tail) && wrapped);
}
/* pop front of queue, returning the front data */
/* q is corrupted if pop when empty */
AIMove pop (){
/* assert that before pop, queue is not empty (underflow check) */
Q_ASSERT((!wrapped && (head < tail)) || (wrapped && (head >= tail)),
"queue underflowed");
AIMove d = pico_stream_input_queue();
cout <<"pop: "<<head<<":"<<tail<<":"<<wrapped<<endl;
if (head == max_size-1) {
head = 0;
wrapped = false;
} else {
head = head + 1;
}
return d;
}
/* push data into back of queue */
/* q is corrupted if push when full */
void push (AIMove d){
pico_stream_output_queue(d);
if (tail == max_size-1) {
tail = 0;
wrapped = true;
} else {
tail = tail + 1;
}
/* assert that after push, queue is not empty (overflow check) */
Q_ASSERT((!wrapped && (head < tail)) || (wrapped && (head >= tail)),
"Queue overflowed") ;
cout <<"push: "<<head<<":"<<tail<<":"<<wrapped<<endl;
}
/* return current size of the queue */
int size (){
if (wrapped) {
return (max_size - head) + (tail - 0);
} else {
return tail - head;
}
}
};
q<AIMove,361,32> moves_fifo;
//
//#include "shared.h"
//#include"q.hpp"
//
//#ifdef PICO_SYNTH
//#define Q_ASSERT(_cond, _msg)
//#include <iostream>
//#include "pico.h"
//using namespace std;
//#else
///* not synthesizable */
//#include <iostream>
//#include <sstream>
//#include <string>
//#include <assert.h>
//
//static void debug_assert (bool cond, char * msg) {
// if (!cond) {
// printf("assert failed: %s\n", msg);
// assert(0);
// }
//}
//
//#define Q_ASSERT(_cond, _msg) debug_assert(_cond, _msg)
//#endif
//FIFO(queue,AIMove);
//
// /* pop front of queue, returning the front data */
// /* q is corrupted if pop when empty */
// template<class tp, int max_size, int ptr_bw>
// tp q<tp,max_size,ptr_bw>::pop () {
// /* assert that before pop, queue is not empty (underflow check) */
// Q_ASSERT((!wrapped && (head < tail)) || (wrapped && (head >= tail)),
// "queue underflowed");
// tp d = pico_stream_input_queue();
// cout <<"pop: "<<head<<":"<<tail<<":"<<wrapped<<endl;
// if (head == max_size-1) {
// head = 0;
// wrapped = false;
// } else {
// head = head + 1;
// }
// return d;
// }
//
// /* push data into back of queue */
// /* q is corrupted if push when full */
// template<class tp, int max_size, int ptr_bw>
// void q<tp,max_size,ptr_bw>::push (tp d) {
// pico_stream_output_queue(d);
// if (tail == max_size-1) {
// tail = 0;
// wrapped = true;
// } else {
// tail = tail + 1;
// }
// /* assert that after push, queue is not empty (overflow check) */
// Q_ASSERT((!wrapped && (head < tail)) || (wrapped && (head >= tail)),
// "Queue overflowed") ;
// cout <<"push: "<<head<<":"<<tail<<":"<<wrapped<<endl;
// }
//
// /* return current size of the queue */
// template<class tp, int max_size, int ptr_bw>
// int q<tp,max_size,ptr_bw>::size () {
// if (wrapped) {
// return (max_size - head) + (tail - 0);
// } else {
// return tail - head;
// }
// }
//
//#ifndef PICO_SYNTH
// /* not synthesizable */
// std::string to_string () const {
// std::string s;
// std::stringstream out;
//
// out << "{ ";
//
// if (wrapped) {
// for (int i=head; i<max_size; i++) {
// out << arr[i];
// out << " , ";
// }
// for (int i=0; i<tail; i++) {
// out << arr[i];
// if (i != tail - 1) out << " , ";
// }
// } else {
// for (int i=head; i<tail; i++) {
// out << arr[i];
// if (i != tail - 1) out << " , ";
// }
// }
//
// out << " }";
// s = out.str();
// return s;
// }
//
// operator std::string () { return to_string(); }
//
//#endif
//
//
//#ifndef PICO_SYNTH
///* not synthesizable */
//template <class tp, int max_size, int ptr_bw>
//std::ostream& operator << (std::ostream &os, const q<tp,max_size,ptr_bw> &f)
//{
// os << f.to_string();
// return os;
//}
//#endif