Commit d0218176 authored by makoto.nishizawa's avatar makoto.nishizawa

applied to new question model

parent 7164ee51
TARGET = sim
OBJS = $(CPPS:.cpp=.o)
CPPS = $(wildcard *.cpp)
CXX = g++
CXXFLAGS = -O3 -DSOFTWARE
all: $(TARGET)
$(TARGET): $(OBJS)
$(CXX) -o $@ $(OBJS)
clean:
rm *.o
rm $(TARGET)
...@@ -14,6 +14,8 @@ short int block_data[MAXBLOCK+1][5][3]; // ブロックの情報 ...@@ -14,6 +14,8 @@ short int block_data[MAXBLOCK+1][5][3]; // ブロックの情報
short int board_data[MAXW][MAXH]; // 盤面情報 short int board_data[MAXW][MAXH]; // 盤面情報
short int line_num=0;
void reset_parameters(void){ void reset_parameters(void){
int i,j,k; int i,j,k;
for(i=0;i<MAXBLOCK;i++) for(i=0;i<MAXBLOCK;i++)
...@@ -59,10 +61,11 @@ void read_problem(void){ ...@@ -59,10 +61,11 @@ void read_problem(void){
nowx=num=0; nowx=num=0;
gets(str); gets(str);
for(k=0;;k++){ for(k=0;;k++){
if(str[k]=='*') if(str[k]=='0' && num==0)
num=-1; num=-1;
else if('0'<=str[k]&&str[k]<='9') else if('0'<=str[k]&&str[k]<='9')
num=num*10+str[k]-'0'; num=num*10+str[k]-'0';
if(num>line_num) line_num=num;
else if(str[k]==','){ else if(str[k]==','){
if(num<0){ if(num<0){
num=0; num=0;
......
...@@ -30,6 +30,7 @@ extern short int board_data[MAXW][MAXH]; // 盤面情報 ...@@ -30,6 +30,7 @@ extern short int board_data[MAXW][MAXH]; // 盤面情報
// ... // ...
// (0,71),(1,71), ... ,(71,71) // (0,71),(1,71), ... ,(71,71)
// 基本的には回答フォーマットに沿う形 // 基本的には回答フォーマットに沿う形
extern short int line_num;
void reset_parameters(void); // read_problem に内包 void reset_parameters(void); // read_problem に内包
void read_problem(void); void read_problem(void);
......
File added
/* main.c */ /* main.c */
/* Last Change: 2019/05/21 (Tue) 14:44:03. */ /* Last Change: 2019/05/21 (Tue) 14:44:03. */
#include"io.h" #include"io.h"
#include"solver.h" #include"solver.h"
......
File added
all: main.cpp io.c solver.cpp all: main.cpp io.c solver.cpp router/router.cpp
g++ -o solve main.cpp io.c solver.cpp -std=c++11 g++ -o solve solver.cpp main.cpp io.c router/router.cpp -std=c++11
o: main.o io.o solver.o o: main.o io.o solver.o
g++ -o solve main.o io.o solver.o g++ -o solve main.o io.o solver.o
...@@ -11,4 +11,4 @@ io.o: io.c ...@@ -11,4 +11,4 @@ io.o: io.c
g++ -c io.c g++ -c io.c
solver.o: solver.cpp solver.o: solver.cpp
g++ -c solver.cpp g++ -c solver.cpp -std=c++11
TARGET = sim
OBJS = $(CPPS:.cpp=.o)
CPPS = $(wildcard *.cpp)
CXX = g++
CXXFLAGS = -O3 -DSOFTWARE
all: $(TARGET)
$(TARGET): $(OBJS)
$(CXX) -o $@ $(OBJS)
clean:
rm *.o
rm $(TARGET)
# Basic router
* A*ベースの配線プログラム
* 入力
* 盤面サイズ(size_x, size_y)
* ライン数(line_num)
* 盤面情報(size_x$`\times`$size_yの盤面に整数を割り当て,自然数: ライン端点,-1: 配線禁止領域, 0: 配線領域)
* 出力
* status(自然数: 配線成功,0: 配線失敗),配線成功時のstatusは総配線長を表す
* 配線結果
* routerに渡す盤面情報,routerから返される配線結果は1次元配列(入力が2次元配列の場合,変換が必要)
* ハードウェア化に備えて余計な型やヘッダファイルを含むが,その辺はご了承願いたい...
### Change log
* 2019.07.16
* 端点の隣接判定に関するバグを修正
* 端点を結ぶパスが存在しないときにプログラムが停止するバグを修正
* 配線成功時のstatusを総配線長に変更
### 関数呼び出し
* 関数routerの呼び出し方法は以下のサンプルコードの通り
* routerの第5引数はシード値で指定は任意(default=12345)
```
short int size_x = 10, size_y = 10;
short int line_num = 6;
short int board[10][10], board_str[100];
/* ここで盤面情報を設定 */
// Transform "board" to "board_str"
for(int y = 0; y < size_y; y++) {
for(int x = 0; x < size_x; x++) {
int idx = y * size_x + x;
board_str[idx] = board[y][x];
}
}
int status = router(size_x, size_y, line_num, board_str, 1234567);
// Transform "board_str" to "board"
for(int y = 0; y < size_y; y++) {
for(int x = 0; x < size_x; x++) {
int idx = y * size_x + x;
board[y][x] = board_str[idx];
}
}
```
### 必要ファイル
* router.cpp
* router.hpp
* ap_int.h
* etc/ap_fixed_sim.h
* etc/ap_int_sim.h
* etc/ap_private.h
### パラメタ
* router.hpp上部で以下を設定可能
|定数名|説明|
|:---|:---|
|ROUND_LIMIT|引きはがし再配線回数の上限(default: 32768, Max: 65534),小さいほど諦めが早い|
|PRINT_BOARD|配線前と配線後の盤面を表示(コメントアウトで非表示)|
|PRINT_SEARCH|配線の途中経過をすべて表示(コメントアウトで非表示)|
/*
* Copyright 2012 Xilinx, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __AESL_AP_SIM_H__
#define __AESL_AP_SIM_H__
#ifndef __cplusplus
#error C++ is required to include this header file
#else
#include "etc/ap_int_sim.h"
#include "etc/ap_fixed_sim.h"
//Forward declaration
template<int _AP_W, int _AP_I, ap_q_mode _AP_Q,
ap_o_mode _AP_O, int _AP_N> class ap_fixed;
template<int _AP_W, int _AP_I, ap_q_mode _AP_Q,
ap_o_mode _AP_O, int _AP_N> class ap_ufixed;
template<int _AP_W> class ap_int;
template<int _AP_W> class ap_uint;
//AP_INT
//--------------------------------------------------------
template<int _AP_W>
class ap_int : public ap_private<_AP_W, true> {
#ifdef _MSC_VER
#pragma warning(disable: 4521 4522)
#endif /* #ifdef _MSC_VER */
public:
typedef ap_private<_AP_W, true> Base;
//Constructor
INLINE ap_int(): Base() {}
template<int _AP_W2>
INLINE ap_int(const volatile ap_int<_AP_W2> &op):Base((const ap_private<_AP_W2,true> &)(op)) {}
template<int _AP_W2>
INLINE ap_int(const ap_int<_AP_W2> &op):Base((const ap_private<_AP_W2,true> &)(op)) {}
template<int _AP_W2>
INLINE ap_int(const ap_uint<_AP_W2> &op):Base((const ap_private<_AP_W2,false> &)(op)) {}
template<int _AP_W2>
INLINE ap_int(const volatile ap_uint<_AP_W2> &op):Base((const ap_private<_AP_W2,false> &)(op)) {}
template<int _AP_W2, bool _AP_S2>
INLINE ap_int(const ap_range_ref<_AP_W2, _AP_S2>& ref):Base(ref) {}
template<int _AP_W2, bool _AP_S2>
INLINE ap_int(const ap_bit_ref<_AP_W2, _AP_S2>& ref):Base(ref) {}
template<int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
INLINE ap_int(const ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3>& ref):Base(ref) {}
template<int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_int(const ap_fixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2, _AP_N2>& op)
:Base(op.to_ap_private()) {}
template<int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_int(const ap_ufixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2, _AP_N2>& op)
:Base(op.to_ap_private()) {}
template<int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_int(const volatile ap_fixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2, _AP_N2>& op)
:Base(op.to_ap_private()) {}
template<int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_int(const volatile ap_ufixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2, _AP_N2>& op)
:Base(op.to_ap_private()) {}
template<int _AP_W2, bool _AP_S2>
INLINE ap_int(const ap_private<_AP_W2, _AP_S2>& op):Base(op) {}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_int(const af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2,
_AP_N2>& op):Base(op) {}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_int(const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2,
_AP_N2>& op):Base(op) {}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_int(const ap_fixed_base<_AP_W2, _AP_I2, _AP_S2,
_AP_Q2, _AP_O2, _AP_N2>& op):Base(op.to_ap_private()) {}
#define CTOR(TYPE) \
INLINE ap_int(TYPE v):Base(v) {}
CTOR(bool)
CTOR(signed char)
CTOR(unsigned char)
CTOR(short)
CTOR(unsigned short)
CTOR(int)
CTOR(unsigned int)
CTOR(long)
CTOR(unsigned long)
CTOR(unsigned long long)
CTOR(long long)
CTOR(float)
CTOR(double)
CTOR(const char*)
CTOR(const std::string&)
#undef CTOR
INLINE ap_int(const char* str, signed char rd):Base(str, rd) {}
//Assignment
//Another form of "write"
INLINE void operator = (const ap_int<_AP_W>& op2) volatile {
const_cast<ap_int*>(this)->operator = (op2);
}
INLINE void operator = (const volatile ap_int<_AP_W>& op2) volatile {
const_cast<Base*>(this)->operator = (op2);
}
INLINE ap_int<_AP_W>& operator = (const volatile ap_int<_AP_W>& op2) {
Base::operator = (const_cast<ap_int<_AP_W>& >(op2));
return *this;
}
INLINE ap_int<_AP_W>& operator = (const ap_int<_AP_W>& op2) {
Base::operator = ((const ap_private<_AP_W, true>&)op2);
return *this;
}
};
//AP_UINT
//---------------------------------------------------------------
template<int _AP_W>
class ap_uint: public ap_private<_AP_W, false> {
#ifdef _MSC_VER
#pragma warning( disable : 4521 4522 )
#endif
public:
typedef ap_private<_AP_W, false> Base;
//Constructor
INLINE ap_uint(): Base() {}
INLINE ap_uint(const ap_uint<_AP_W>& op) :Base(dynamic_cast<const ap_private<_AP_W, false>&>(op)) {}
INLINE ap_uint(const volatile ap_uint<_AP_W>& op):Base(dynamic_cast<const volatile ap_private<_AP_W, false>&>(op)){}
template<int _AP_W2>
INLINE ap_uint(const volatile ap_uint<_AP_W2> &op):Base((const ap_private<_AP_W2, false>&)(op)) {}
template<int _AP_W2>
INLINE ap_uint(const ap_uint<_AP_W2> &op) : Base((const ap_private<_AP_W2, false>&)(op)){}
template<int _AP_W2>
INLINE ap_uint(const ap_int<_AP_W2> &op) : Base((const ap_private<_AP_W2, true>&)(op)) {}
template<int _AP_W2>
INLINE ap_uint(const volatile ap_int<_AP_W2> &op) : Base((const ap_private<_AP_W2, false>&)(op)) {}
template<int _AP_W2, bool _AP_S2>
INLINE ap_uint(const ap_range_ref<_AP_W2, _AP_S2>& ref):Base(ref) {}
template<int _AP_W2, bool _AP_S2>
INLINE ap_uint(const ap_bit_ref<_AP_W2, _AP_S2>& ref):Base(ref) {}
template<int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
INLINE ap_uint(const ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3>& ref):Base(ref) {}
template<int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_uint(const ap_fixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2, _AP_N2>& op)
:Base(op.to_ap_private()) {}
template<int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_uint(const ap_ufixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2, _AP_N2>& op)
:Base(op.to_ap_private()) {}
template<int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_uint(const volatile ap_fixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2, _AP_N2>& op)
:Base(op.to_ap_private()) {}
template<int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_uint(const volatile ap_ufixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2, _AP_N2>& op)
:Base(op) {}
template<int _AP_W2, bool _AP_S2>
INLINE ap_uint(const ap_private<_AP_W2, _AP_S2>& op):Base(op) {}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_uint(const af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2,
_AP_N2>& op):Base(op) {}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_uint(const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2,
_AP_N2>& op):Base(op) {}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_uint(const ap_fixed_base<_AP_W2, _AP_I2, _AP_S2,
_AP_Q2, _AP_O2, _AP_N2>& op):Base(op.to_ap_private()) {}
#define CTOR(TYPE) \
INLINE ap_uint(TYPE v):Base(v) {}
CTOR(bool)
CTOR(signed char)
CTOR(unsigned char)
CTOR(short)
CTOR(unsigned short)
CTOR(int)
CTOR(unsigned int)
CTOR(long)
CTOR(unsigned long)
CTOR(unsigned long long)
CTOR(long long)
CTOR(float)
CTOR(double)
CTOR(const char*)
CTOR(const std::string&)
#undef CTOR
INLINE ap_uint(const char* str, signed char rd):Base(str, rd) {}
//Assignment
//Another form of "write"
INLINE void operator = (const ap_uint<_AP_W>& op2) volatile {
Base::operator = (op2);
}
INLINE void operator = (const volatile ap_uint<_AP_W>& op2) volatile {
Base::operator = (op2);
}
INLINE ap_uint<_AP_W>& operator = (const volatile ap_uint<_AP_W>& op2) {
Base::operator = (op2);
return *this;
}
INLINE ap_uint<_AP_W>& operator = (const ap_uint<_AP_W>& op2) {
Base::operator = ((const ap_private<_AP_W, false>&)(op2));
return *this;
}
};
#define ap_bigint ap_int
#define ap_biguint ap_uint
//AP_FIXED
//---------------------------------------------------------------------
template<int _AP_W, int _AP_I, ap_q_mode _AP_Q = AP_TRN,
ap_o_mode _AP_O = AP_WRAP, int _AP_N = 0>
class ap_fixed: public ap_fixed_base<_AP_W, _AP_I, true, _AP_Q, _AP_O, _AP_N> {
#ifdef _MSC_VER
#pragma warning( disable : 4521 4522 )
#endif
public:
typedef ap_fixed_base<_AP_W, _AP_I, true, _AP_Q, _AP_O, _AP_N> Base;
//Constructor
INLINE ap_fixed():Base() {}
template<int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_fixed(const ap_fixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2,
_AP_N2>& op): Base(op) {}
template<int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_fixed(const ap_ufixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2,
_AP_N2>& op): Base(ap_fixed_base<_AP_W2, _AP_I2,
false, _AP_Q2, _AP_O2, _AP_N2>(op)) {}
template<int _AP_W2>
INLINE ap_fixed(const ap_int<_AP_W2>& op):
Base(ap_private<_AP_W2, true>(op)) {}
template<int _AP_W2>
INLINE ap_fixed(const ap_uint<_AP_W2>& op):Base(ap_private<_AP_W2, false>(op)) {}
template<int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_fixed(const volatile ap_fixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2,
_AP_N2>& op): Base(ap_fixed_base<_AP_W2, _AP_I2,
true, _AP_Q2, _AP_O2, _AP_N2>(op)) {}
template<int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_fixed(const volatile ap_ufixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2,
_AP_N2>& op): Base(ap_fixed_base<_AP_W2, _AP_I2,
false, _AP_Q2, _AP_O2, _AP_N2>(op)) {}
template<int _AP_W2>
INLINE ap_fixed(const volatile ap_int<_AP_W2>& op):
Base(ap_private<_AP_W2, true>(op)) {}
template<int _AP_W2>
INLINE ap_fixed(const volatile ap_uint<_AP_W2>& op):Base(op) {}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_fixed(const ap_fixed_base<_AP_W2, _AP_I2, _AP_S2,
_AP_Q2, _AP_O2, _AP_N2>& op):Base(op) {}
template<int _AP_W2, bool _AP_S2>
INLINE ap_fixed(const ap_bit_ref<_AP_W2, _AP_S2>& op):
Base(op) {}
template<int _AP_W2, bool _AP_S2>
INLINE ap_fixed(const ap_range_ref<_AP_W2, _AP_S2>& op):
Base(op) {}
template<int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
INLINE ap_fixed(const ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3>& op):
Base(op) {}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_fixed(const af_bit_ref<_AP_W2, _AP_I2, _AP_S2,
_AP_Q2, _AP_O2, _AP_N2>& op): Base(op) {}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_fixed(const af_range_ref<_AP_W2, _AP_I2, _AP_S2,
_AP_Q2, _AP_O2, _AP_N2>& op): Base(op) {}
template<int _AP_W2, bool _AP_S2>
INLINE ap_fixed(const ap_private<_AP_W2, _AP_S2>& op):Base(op) {}
#define CTOR(TYPE) \
INLINE ap_fixed(TYPE v):Base(v) {}
CTOR(bool)
CTOR(signed char)
CTOR(unsigned char)
CTOR(short)
CTOR(unsigned short)
CTOR(int)
CTOR(unsigned int)
CTOR(long)
CTOR(unsigned long)
CTOR(unsigned long long)
CTOR(long long)
CTOR(float)
CTOR(double)
CTOR(const char*)
CTOR(const std::string&)
#undef CTOR
INLINE ap_fixed(const char* str, signed char rd):Base(str, rd) {}
//Assignment
INLINE ap_fixed& operator = (const ap_fixed<_AP_W, _AP_I,
_AP_Q, _AP_O, _AP_N>& op) {
Base::operator = (op);
return *this;
}
INLINE ap_fixed& operator = (const volatile ap_fixed<_AP_W, _AP_I,
_AP_Q, _AP_O, _AP_N>& op) {
Base::operator = (op);
return *this;
}
};
//AP_ UFIXED
//--- ----------------------------------------------------------------
template<int _AP_W, int _AP_I, ap_q_mode _AP_Q = AP_TRN,
ap_o_mode _AP_O = AP_WRAP, int _AP_N = 0>
class ap_ufixed : public ap_fixed_base<_AP_W, _AP_I, false, _AP_Q, _AP_O, _AP_N> {
#ifdef _MSC_VER
#pragma warning(disable: 4521 4522)
#endif /* #ifdef _MSC_VER */
public:
typedef ap_fixed_base<_AP_W, _AP_I, false, _AP_Q, _AP_O, _AP_N> Base;
//Constructor
INLINE ap_ufixed():Base() {}
template<int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_ufixed(const ap_fixed<_AP_W2, _AP_I2, _AP_Q2,
_AP_O2, _AP_N2>& op) : Base(ap_fixed_base<_AP_W2,
_AP_I2, true, _AP_Q2, _AP_O2, _AP_N2>(op)) {}
template<int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_ufixed(const ap_ufixed<_AP_W2, _AP_I2, _AP_Q2,
_AP_O2, _AP_N2>& op): Base(ap_fixed_base<_AP_W2, _AP_I2,
false, _AP_Q2, _AP_O2, _AP_N2>(op)) {}
template<int _AP_W2>
INLINE ap_ufixed(const ap_int<_AP_W2>& op):
Base((const ap_private<_AP_W2, true>&)(op)) {}
template<int _AP_W2>
INLINE ap_ufixed(const ap_uint<_AP_W2>& op):
Base((const ap_private<_AP_W2, false>&)(op)) {}
template<int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_ufixed(const volatile ap_fixed<_AP_W2, _AP_I2, _AP_Q2,
_AP_O2, _AP_N2>& op) : Base(ap_fixed_base<_AP_W2,
_AP_I2, true, _AP_Q2, _AP_O2, _AP_N2>(op)) {}
template<int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_ufixed(const volatile ap_ufixed<_AP_W2, _AP_I2, _AP_Q2,
_AP_O2, _AP_N2>& op): Base(ap_fixed_base<_AP_W2, _AP_I2,
false, _AP_Q2, _AP_O2, _AP_N2>(op)) {}
template<int _AP_W2>
INLINE ap_ufixed(const volatile ap_int<_AP_W2>& op):
Base(ap_private<_AP_W2, true>(op)) {}
template<int _AP_W2>
INLINE ap_ufixed(const volatile ap_uint<_AP_W2>& op):
Base(ap_private<_AP_W2, false>(op)) {}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_ufixed(const ap_fixed_base<_AP_W2, _AP_I2, _AP_S2, _AP_Q2,
_AP_O2, _AP_N2>& op):Base(op) {}
template<int _AP_W2, bool _AP_S2>
INLINE ap_ufixed(const ap_bit_ref<_AP_W2, _AP_S2>& op):
Base(op) {}
template<int _AP_W2, bool _AP_S2>
INLINE ap_ufixed(const ap_range_ref<_AP_W2, _AP_S2>& op):
Base(op) {}
template<int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
INLINE ap_ufixed(const ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3>& op):
Base(op) {}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_ufixed(const af_bit_ref<_AP_W2, _AP_I2, _AP_S2,
_AP_Q2, _AP_O2, _AP_N2>& op): Base(op) {}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_ufixed(const af_range_ref<_AP_W2, _AP_I2, _AP_S2,
_AP_Q2, _AP_O2, _AP_N2>& op): Base(op) {}
template<int _AP_W2, bool _AP_S2>
INLINE ap_ufixed(const ap_private<_AP_W2, _AP_S2>& op):Base(op) {}
#define CTOR(TYPE) \
INLINE ap_ufixed(TYPE v):Base(v) {}
CTOR(bool)
CTOR(signed char)
CTOR(unsigned char)
CTOR(short)
CTOR(unsigned short)
CTOR(int)
CTOR(unsigned int)
CTOR(long)
CTOR(unsigned long)
CTOR(unsigned long long)
CTOR(long long)
CTOR(float)
CTOR(double)
CTOR(const char*)
CTOR(const std::string&)
#undef CTOR
INLINE ap_ufixed(const char* str, signed char rd):Base(str, rd) {}
//Assignment
INLINE ap_ufixed& operator = (const ap_ufixed<_AP_W, _AP_I,
_AP_Q, _AP_O, _AP_N>& op) {
Base::operator = (op);
return *this;
}
INLINE ap_ufixed& operator = (const volatile ap_ufixed<_AP_W, _AP_I,
_AP_Q, _AP_O, _AP_N>& op) {
Base::V = const_cast<ap_ufixed&>(op);
return *this;
}
};
#if defined(SYSTEMC_H) || defined(SYSTEMC_INCLUDED)
template<int _AP_W>
INLINE void sc_trace(sc_core::sc_trace_file *tf, const ap_int<_AP_W> &op,
const std::string &name) {
if (tf)
tf->trace(sc_dt::sc_lv<_AP_W>(op.to_string(2).c_str()), name);
}
template<int _AP_W>
INLINE void sc_trace(sc_core::sc_trace_file *tf, const ap_uint<_AP_W> &op,
const std::string &name) {
if (tf)
tf->trace(sc_dt::sc_lv<_AP_W>(op.to_string(2).c_str()), name);
}
template<int _AP_W, int _AP_I, ap_q_mode _AP_Q,
ap_o_mode _AP_O, int _AP_N>
INLINE void sc_trace(sc_core::sc_trace_file *tf, const ap_fixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N >&op, const std::string &name) {
tf->trace(sc_dt::sc_lv<_AP_W>(op.to_string(2).c_str()), name);
}
template<int _AP_W, int _AP_I, ap_q_mode _AP_Q,
ap_o_mode _AP_O, int _AP_N>
INLINE void sc_trace(sc_core::sc_trace_file *tf, const ap_ufixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N >&op, const std::string &name) {
tf->trace(sc_dt::sc_lv<_AP_W>(op.to_string(2).c_str()), name);
}
#endif /* #if defined(SYSTEMC_H) || defined(SYSTEMC_INCLUDED) */
#endif /* #ifndef __cplusplus */
#endif /* #ifndef __AESL_AP_SIM_H__ */
\ No newline at end of file
/*
* Copyright 2012 Xilinx, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __AESL_GCC_AP_FIXED_H__
#define __AESL_GCC_AP_FIXED_H__
#ifndef __cplusplus
#error C++ is required to include this header file
#endif /* #ifndef __cplusplus */
#include <math.h>
#ifndef __AESL_APDT_IN_SCFLOW__
#include "etc/ap_int_sim.h"
#else
#include "../etc/ap_private.h"
#endif /* #ifndef __AESL_APDT_IN_SCFLOW__ */
#define FLOAT_MAN 23
#define FLOAT_EXP 8
#define DOUBLE_MAN 52
#define DOUBLE_EXP 11
// #define DOUBLE_MAN_MASK (~0ULL >> (64-DOUBLE_MAN-2))
#define DOUBLE_MAN_MASK 0x3fffffffffffffULL
#define BIAS(e) ((1ULL<<(e-1))-1)
#define FLOAT_BIAS BIAS(FLOAT_EXP)
#define DOUBLE_BIAS BIAS(DOUBLE_EXP)
/// Forward declaration.
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N> struct ap_fixed_base;
///Proxy class, which allows bit selection to be used as both rvalue(for reading) and
//lvalue(for writing)
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
struct af_bit_ref {
#ifdef _MSC_VER
#pragma warning(disable: 4521 4522)
#endif /* #ifdef _MSC_VER */
ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& d_bv;
int d_index;
public:
INLINE af_bit_ref(const af_bit_ref<_AP_W, _AP_I, _AP_S,
_AP_Q, _AP_O, _AP_N>& ref):
d_bv(ref.d_bv), d_index(ref.d_index) {}
INLINE af_bit_ref(ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>* bv, int index=0):
d_bv(*bv),d_index(index) {}
INLINE operator bool() const {
return d_bv.V[d_index];
}
INLINE af_bit_ref& operator=(unsigned long long val) {
if (val)
d_bv.V.set(d_index);
else
d_bv.V.clear(d_index);
return *this;
}
template<int _AP_W2, bool _AP_S2>
INLINE af_bit_ref& operator =(const ap_private<_AP_W2,_AP_S2>& val) {
return operator=(val!=0);
}
INLINE af_bit_ref& operator =(const af_bit_ref<_AP_W, _AP_I, _AP_S,
_AP_Q, _AP_O, _AP_N>& val) {
return operator=((unsigned long long)(bool)val);
}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE af_bit_ref operator=(const af_bit_ref<_AP_W2,_AP_I2,_AP_S2,_AP_Q2,_AP_O2, _AP_N2>& val) {
return operator=((unsigned long long)(bool)val);
}
template<int _AP_W2, bool _AP_S2>
INLINE af_bit_ref& operator = ( const ap_bit_ref<_AP_W2, _AP_S2> &val) {
return operator =((unsigned long long) (bool) val);
}
template<int _AP_W2, bool _AP_S2>
INLINE af_bit_ref& operator = ( const ap_range_ref<_AP_W2,_AP_S2>& val) {
return operator =((const ap_private<_AP_W2, false>) val);
}
template<int _AP_W2, int _AP_I2, bool _AP_S2,
ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE af_bit_ref& operator= (const af_range_ref<_AP_W2, _AP_I2, _AP_S2,
_AP_Q2, _AP_O2, _AP_N2>& val) {
return operator=((const ap_private<_AP_W2, false>)(val));
}
template<int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
INLINE af_bit_ref& operator= (const ap_concat_ref<_AP_W2, _AP_T3, _AP_W3, _AP_T3>& val) {
return operator=((const ap_private<_AP_W2 + _AP_W3, false>)(val));
}
template<int _AP_W2, int _AP_S2>
INLINE ap_concat_ref<1, af_bit_ref, _AP_W2, ap_private<_AP_W2, _AP_S2> >
operator, (ap_private<_AP_W2, _AP_S2>& op) {
return ap_concat_ref<1, af_bit_ref, _AP_W2,
ap_private<_AP_W2, _AP_S2> >(*this, op);
}
template<int _AP_W2, int _AP_S2>
INLINE ap_concat_ref<1, af_bit_ref, 1, ap_bit_ref<_AP_W2, _AP_S2> >
operator, (const ap_bit_ref<_AP_W2, _AP_S2> &op) {
return ap_concat_ref<1, af_bit_ref, 1,
ap_bit_ref<_AP_W2, _AP_S2> >(*this,
const_cast<ap_bit_ref<_AP_W2, _AP_S2>& >(op));
}
template<int _AP_W2, int _AP_S2>
INLINE ap_concat_ref<1, af_bit_ref, _AP_W2, ap_range_ref<_AP_W2, _AP_S2> >
operator, (const ap_range_ref<_AP_W2, _AP_S2> &op) {
return ap_concat_ref<1, af_bit_ref, _AP_W2,
ap_range_ref<_AP_W2, _AP_S2> >(*this,
const_cast<ap_range_ref<_AP_W2, _AP_S2>& >(op));
}
template<int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
INLINE ap_concat_ref<1, af_bit_ref, _AP_W2 + _AP_W3,
ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3> >
operator, (const ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3> &op) {
return ap_concat_ref<1, af_bit_ref, _AP_W2 + _AP_W3,
ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3> >(*this,
const_cast<ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3>& >(op));
}
template<int _AP_W2, int _AP_I2, bool _AP_S2,
ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_concat_ref<1, af_bit_ref, _AP_W2,
af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >
operator, (const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2,
_AP_O2, _AP_N2> &op) {
return ap_concat_ref<1, af_bit_ref, _AP_W2,
af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2,
_AP_N2> >(*this, const_cast<af_range_ref<_AP_W2, _AP_I2,
_AP_S2, _AP_Q2, _AP_O2,_AP_N2>& >(op));
}
template<int _AP_W2, int _AP_I2, bool _AP_S2,
ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_concat_ref<1, af_bit_ref, 1,
af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >
operator, (const af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2,
_AP_O2, _AP_N2> &op) {
return ap_concat_ref<1, af_bit_ref, 1,
af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >(*this,
const_cast<af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2,
_AP_O2, _AP_N2>& >(op));
}
template<int _AP_W2, int _AP_I2, bool _AP_S2,
ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE bool operator == (const af_bit_ref<_AP_W2, _AP_I2,
_AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op) {
return get() == op.get();
}
template<int _AP_W2, int _AP_I2, bool _AP_S2,
ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE bool operator != (const af_bit_ref<_AP_W2, _AP_I2,
_AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op) {
return get() != op.get();
}
INLINE bool operator ~ () const {
bool bit = (d_bv.V)[d_index];
return bit ? false : true;
}
INLINE int length() const {
return 1;
}
INLINE bool get() {
return d_bv.V[d_index];
}
INLINE bool get() const {
return d_bv.V[d_index];
}
INLINE std::string to_string() const {
return d_bv.V[d_index] ? "1" : "0";
}
};
///Range(slice) reference
//------------------------------------------------------------
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
struct af_range_ref {
#ifdef _MSC_VER
#pragma warning(disable: 4521 4522)
#endif /* #ifdef _MSC_VER */
ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N> &d_bv;
int l_index;
int h_index;
public:
INLINE af_range_ref(const af_range_ref<_AP_W, _AP_I, _AP_S,
_AP_Q, _AP_O, _AP_N>& ref):
d_bv(ref.d_bv), l_index(ref.l_index), h_index(ref.h_index) {}
INLINE af_range_ref(ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>* bv, int h, int l):
d_bv(*bv),l_index(l),h_index(h) {
//if (h < l)
// fprintf(stderr,
//"Warning! The bits selected will be returned in reverse order\n");
}
INLINE operator ap_private<_AP_W, false> () const {
if (h_index >= l_index) {
ap_private<_AP_W, false> val(d_bv.V);
ap_private<_AP_W,false> mask(-1);
mask>>=_AP_W-(h_index-l_index+1);
val>>=l_index;
return val&=mask;
} else {
ap_private<_AP_W, false> val = 0;
for (int i=0, j=l_index;j>=0&&j>=h_index;j--,i++)
if ((d_bv.V)[j]) val.set(i);
return val;
}
}
INLINE operator unsigned long long() const {
return get().to_uint64();
}
template<int _AP_W2,bool _AP_S2>
INLINE af_range_ref& operator =(const ap_private<_AP_W2,_AP_S2>& val) {
ap_private<_AP_W, false> vval= ap_private<_AP_W, false>(val);
if (l_index > h_index) {
for (int i=0, j=l_index;j>=0&&j>=h_index;j--,i++)
vval[i]? d_bv.V.set(j):d_bv.V.clear(j);
} else {
ap_private<_AP_W,false> mask(-1);
if (l_index>0) {
mask<<=l_index;
vval<<=l_index;
}
if (h_index<_AP_W-1) {
ap_private<_AP_W,false> mask2(-1);
mask2>>=_AP_W-h_index-1;
mask&=mask2;
vval&=mask2;
}
mask.flip();
d_bv.V &= mask;
d_bv.V |= vval;
}
return *this;
}
INLINE af_range_ref& operator = (unsigned long long val) {
const ap_private<_AP_W, false> tmpVal(val);
return operator = (tmpVal);
}
template<int _AP_W3, typename _AP_T3, int _AP_W4, typename _AP_T4>
INLINE af_range_ref& operator =
(const ap_concat_ref <_AP_W3, _AP_T3, _AP_W4, _AP_T4>& val) {
const ap_private<_AP_W, false> tmpVal(val);
return operator = (tmpVal);
}
template <int _AP_W3, bool _AP_S3>
INLINE af_range_ref& operator =(const ap_bit_ref<_AP_W3, _AP_S3>& val) {
const ap_private<_AP_W, false> tmpVal(val);
return operator = (tmpVal);
}
template <int _AP_W3, bool _AP_S3>
INLINE af_range_ref& operator =(const ap_range_ref<_AP_W3,_AP_S3>& val) {
const ap_private<_AP_W, false> tmpVal(val);
return operator =(tmpVal);
}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE af_range_ref& operator= (const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& val) {
const ap_private<_AP_W2, false> tmp= val.get();
return operator = (tmp);
}
INLINE af_range_ref& operator= (const af_range_ref<_AP_W, _AP_I, _AP_S,
_AP_Q, _AP_O, _AP_N>& val) {
const ap_private<_AP_W, false> tmp= val.get();
return operator = (tmp);
}
template<int _AP_W2, int _AP_I2, bool _AP_S2,
ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE af_range_ref& operator= (const ap_fixed_base<_AP_W2,
_AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& val) {
return operator=(val.to_ap_private());
}
template<int _AP_W2, bool _AP_S2>
INLINE bool operator == (const ap_range_ref<_AP_W2, _AP_S2>& op2) {
ap_private<_AP_W,false> lhs=get();
ap_private<_AP_W2,false> rhs=op2.get();
return lhs==rhs;
}
template<int _AP_W2, bool _AP_S2>
INLINE bool operator != (const ap_range_ref<_AP_W2, _AP_S2>& op2) {
ap_private<_AP_W,false> lhs=get();
ap_private<_AP_W2,false> rhs=op2.get();
return lhs!=rhs;
}
template<int _AP_W2, bool _AP_S2>
INLINE bool operator > (const ap_range_ref<_AP_W2, _AP_S2>& op2) {
ap_private<_AP_W,false> lhs=get();
ap_private<_AP_W2,false> rhs=op2.get();
return lhs>rhs;
}
template<int _AP_W2, bool _AP_S2>
INLINE bool operator >= (const ap_range_ref<_AP_W2, _AP_S2>& op2) {
ap_private<_AP_W,false> lhs=get();
ap_private<_AP_W2,false> rhs=op2.get();
return lhs>=rhs;
}
template<int _AP_W2, bool _AP_S2>
INLINE bool operator < (const ap_range_ref<_AP_W2, _AP_S2>& op2) {
ap_private<_AP_W,false> lhs=get();
ap_private<_AP_W2,false> rhs=op2.get();
return lhs<rhs;
}
template<int _AP_W2, bool _AP_S2>
INLINE bool operator <= (const ap_range_ref<_AP_W2, _AP_S2>& op2) {
ap_private<_AP_W,false> lhs=get();
ap_private<_AP_W2,false> rhs=op2.get();
return lhs<=rhs;
}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE bool operator == (const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op2) {
ap_private<_AP_W,false> lhs=get();
ap_private<_AP_W2,false> rhs=op2.get();
return lhs==rhs;
}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE bool operator != (const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op2) {
ap_private<_AP_W,false> lhs=get();
ap_private<_AP_W2,false> rhs=op2.get();
return lhs!=rhs;
}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE bool operator > (const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op2) {
ap_private<_AP_W,false> lhs=get();
ap_private<_AP_W2,false> rhs=op2.get();
return lhs>rhs;
}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE bool operator >= (const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op2) {
ap_private<_AP_W,false> lhs=get();
ap_private<_AP_W2,false> rhs=op2.get();
return lhs>=rhs;
}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE bool operator < (const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op2) {
ap_private<_AP_W,false> lhs=get();
ap_private<_AP_W2,false> rhs=op2.get();
return lhs<rhs;
}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE bool operator <= (const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op2) {
ap_private<_AP_W,false> lhs=get();
ap_private<_AP_W2,false> rhs=op2.get();
return lhs<=rhs;
}
template<int _AP_W2>
INLINE void set(const ap_private<_AP_W2,false>& val) {
ap_private<_AP_W,_AP_S> vval=val;
if (l_index>h_index) {
for (int i=0, j=l_index;j>=0&&j>=h_index;j--,i++)
vval[i]? d_bv.V.set(j):d_bv.V.clear(j);
} else {
ap_private<_AP_W,_AP_S> mask(-1);
if (l_index>0) {
ap_private<_AP_W,false> mask1(-1);
mask1>>=_AP_W-l_index;
mask1.flip();
mask=mask1;
//vval&=mask1;
vval<<=l_index;
}
if (h_index<_AP_W-1) {
ap_private<_AP_W,false> mask2(-1);
mask2<<=h_index+1;
mask2.flip();
mask&=mask2;
vval&=mask2;
}
mask.flip();
d_bv&=mask;
d_bv|=vval;
}
}
INLINE ap_private<_AP_W,false> get() const {
if (h_index<l_index) {
ap_private<_AP_W, false> val(0);
for (int i=0, j=l_index;j>=0&&j>=h_index;j--,i++)
if ((d_bv.V)[j]) val.set(i);
return val;
} else {
ap_private<_AP_W, false> val = ap_private<_AP_W,false>(d_bv.V);
val>>= l_index;
if (h_index<_AP_W-1)
{
ap_private<_AP_W,false> mask(-1);
mask>>=_AP_W-(h_index-l_index+1);
val&=mask;
}
return val;
}
}
template<int _AP_W2, int _AP_S2>
INLINE ap_concat_ref<_AP_W, af_range_ref, _AP_W2, ap_private<_AP_W2, _AP_S2> >
operator, (ap_private<_AP_W2, _AP_S2>& op) {
return ap_concat_ref<_AP_W, af_range_ref, _AP_W2,
ap_private<_AP_W2, _AP_S2> >(*this, op);
}
template<int _AP_W2, int _AP_S2>
INLINE ap_concat_ref<_AP_W, af_range_ref, 1, ap_bit_ref<_AP_W2, _AP_S2> >
operator, (const ap_bit_ref<_AP_W2, _AP_S2> &op) {
return ap_concat_ref<_AP_W, af_range_ref, 1,
ap_bit_ref<_AP_W2, _AP_S2> >(*this,
const_cast<ap_bit_ref<_AP_W2, _AP_S2>& >(op));
}
template<int _AP_W2, int _AP_S2>
INLINE ap_concat_ref<_AP_W, af_range_ref, _AP_W2, ap_range_ref<_AP_W2, _AP_S2> >
operator, (const ap_range_ref<_AP_W2, _AP_S2> &op) {
return ap_concat_ref<_AP_W, af_range_ref, _AP_W2,
ap_range_ref<_AP_W2, _AP_S2> >(*this,
const_cast<ap_range_ref<_AP_W2, _AP_S2>& >(op));
}
template<int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
INLINE ap_concat_ref<_AP_W, af_range_ref, _AP_W2 + _AP_W3,
ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3> >
operator, (const ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3> &op) {
return ap_concat_ref<_AP_W, af_range_ref, _AP_W2 + _AP_W3,
ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3> >(*this,
const_cast<ap_concat_ref<_AP_W2, _AP_T2, _AP_W3,
_AP_T3>& >(op));
}
template<int _AP_W2, int _AP_I2, bool _AP_S2,
ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_concat_ref<_AP_W, af_range_ref, _AP_W2,
af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >
operator, (const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2,
_AP_O2, _AP_N2> &op) {
return ap_concat_ref<_AP_W, af_range_ref, _AP_W2,
af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >(*this,
const_cast<af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2,
_AP_N2>& > (op));
}
template<int _AP_W2, int _AP_I2, bool _AP_S2,
ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_concat_ref<_AP_W, af_range_ref, 1,
af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >
operator, (const af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2,
_AP_O2, _AP_N2> &op) {
return ap_concat_ref<_AP_W, af_range_ref, 1,
af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >(*this,
const_cast<af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2,
_AP_O2, _AP_N2>& >(op));
}
INLINE int length() const {
return h_index>=l_index?h_index-l_index+1:l_index-h_index+1;
}
INLINE int to_int() const {
ap_private<_AP_W,false> val=get();
return val.to_int();
}
INLINE unsigned int to_uint() const {
ap_private<_AP_W,false> val=get();
return val.to_uint();
}
INLINE long to_long() const {
ap_private<_AP_W,false> val=get();
return val.to_long();
}
INLINE unsigned long to_ulong() const {
ap_private<_AP_W,false> val=get();
return val.to_ulong();
}
INLINE ap_slong to_int64() const {
ap_private<_AP_W,false> val=get();
return val.to_int64();
}
INLINE ap_ulong to_uint64() const {
ap_private<_AP_W,false> val=get();
return val.to_uint64();
}
INLINE std::string to_string(uint8_t radix) const {
return get().to_string(radix);
}
};
//-----------------------------------------------------------------------------
///ap_fixed_base: AutoPilot fixed point
//-----------------------------------------------------------------------------
template<int _AP_W, int _AP_I, bool _AP_S=true, ap_q_mode _AP_Q=AP_TRN,
ap_o_mode _AP_O=AP_WRAP, int _AP_N=0>
struct ap_fixed_base {
#ifdef _MSC_VER
#pragma warning(disable: 4521 4522)
#endif /* #ifdef _MSC_VER */
public:
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2> friend struct
ap_fixed_base;
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2> friend struct
af_bit_ref;
INLINE void overflow_adjust(bool underflow, bool overflow,
bool lD, bool sign) {
if (!overflow && !underflow) return;
switch (_AP_O) {
case AP_WRAP:
if (_AP_N == 0)
return;
if (_AP_S) {
//signed SC_WRAP
//n_bits == 1;
if (_AP_N > 1) {
ap_private<_AP_W, _AP_S> mask(-1);
if (_AP_N >= _AP_W) mask = 0;
else mask.lshr(_AP_N);
if (sign)
V &= mask;
else
V |= ~mask;
}
sign ? V.set(_AP_W - 1) : V.clear(_AP_W - 1);
} else {
//unsigned SC_WRAP
ap_private<_AP_W, _AP_S> mask(-1);
if (_AP_N >= _AP_W) mask = 0;
else mask.lshr(_AP_N);
mask.flip();
V |= mask;
}
break;
case AP_SAT_ZERO:
V.clear();
break;
case AP_WRAP_SM:
{
bool Ro = ap_private_ops::get<_AP_W, _AP_S, _AP_W -1>(V); // V[_AP_W -1];
if (_AP_N == 0) {
if (lD != Ro) {
V.flip();
lD ? ap_private_ops::set<_AP_W, _AP_S, _AP_W - 1>(V) :
ap_private_ops::clear<_AP_W, _AP_S, _AP_W - 1>(V);
}
} else {
if (_AP_N == 1 && sign != Ro) {
V.flip();
} else if (_AP_N > 1) {
bool lNo = ap_private_ops::get<_AP_W, _AP_S, _AP_W - _AP_N> (V); // V[_AP_W - _AP_N];
if (lNo == sign)
V.flip();
ap_private<_AP_W, false> mask(-1);
if (_AP_N >= _AP_W) mask = 0;
else mask.lshr(_AP_N);
if (sign)
V &= mask;
else
V |= mask.flip();
sign ? ap_private_ops::set<_AP_W, _AP_S, _AP_W - 1>(V) : ap_private_ops::clear<_AP_W, _AP_S, _AP_W - 1>(V);
}
}
}
break;
default:
if (_AP_S) {
if (overflow) {
V.set(); ap_private_ops::clear<_AP_W, _AP_S, _AP_W-1>(V);
} else if (underflow) {
V.clear();
ap_private_ops::set<_AP_W, _AP_S, _AP_W-1>(V);
if (_AP_O == AP_SAT_SYM)
ap_private_ops::set<_AP_W, _AP_S, 0>(V);
}
} else {
if (overflow)
V.set();
else if (underflow)
V.clear();
}
}
}
INLINE bool quantization_adjust(bool qb, bool r, bool s) {
bool carry=ap_private_ops::get<_AP_W, _AP_S, _AP_W-1>(V);
switch (_AP_Q) {
case AP_TRN:
return false;
case AP_RND_ZERO:
qb &= s || r;
break;
case AP_RND_MIN_INF:
qb &= r;
break;
case AP_RND_INF:
qb &= !s || r;
break;
case AP_RND_CONV:
qb &= ap_private_ops::get<_AP_W, _AP_S, 0>(V) || r;
break;
case AP_TRN_ZERO:
qb = s && ( qb || r );
break;
default:;
}
if (qb) ++V;
//only when old V[_AP_W-1]==1 && new V[_AP_W-1]==0
return carry && !(ap_private_ops::get<_AP_W, _AP_S, _AP_W-1>(V)); //(!V[_AP_W-1]);
}
template<int _AP_W2, int _AP_I2, bool _AP_S2>
struct RType {
enum {
_AP_F=_AP_W-_AP_I,
F2=_AP_W2-_AP_I2,
mult_w = _AP_W+_AP_W2,
mult_i = _AP_I+_AP_I2,
mult_s = _AP_S||_AP_S2,
plus_w = AP_MAX(_AP_I+(_AP_S2&&!_AP_S),_AP_I2+(_AP_S&&!_AP_S2))+1+AP_MAX(_AP_F,F2),
plus_i = AP_MAX(_AP_I+(_AP_S2&&!_AP_S),_AP_I2+(_AP_S&&!_AP_S2))+1,
plus_s = _AP_S||_AP_S2,
minus_w = AP_MAX(_AP_I+(_AP_S2&&!_AP_S),_AP_I2+(_AP_S&&!_AP_S2))+1+AP_MAX(_AP_F,F2),
minus_i = AP_MAX(_AP_I+(_AP_S2&&!_AP_S),_AP_I2+(_AP_S&&!_AP_S2))+1,
minus_s = true,
#ifndef __SC_COMPATIBLE__
div_w = _AP_W + AP_MAX(_AP_W2 - _AP_I2, 0) + _AP_S2,
#else
div_w = _AP_W + AP_MAX(_AP_W2 - _AP_I2, 0) + _AP_S2 + AP_MAX(_AP_I2, 0),
#endif /* #ifndef __SC_COMPATIBLE__ */
div_i = _AP_I + (_AP_W2-_AP_I2) + _AP_S2,
div_s = _AP_S||_AP_S2,
logic_w = AP_MAX(_AP_I+(_AP_S2&&!_AP_S),_AP_I2+(_AP_S&&!_AP_S2))+AP_MAX(_AP_F,F2),
logic_i = AP_MAX(_AP_I+(_AP_S2&&!_AP_S),_AP_I2+(_AP_S&&!_AP_S2)),
logic_s = _AP_S||_AP_S2
};
typedef ap_fixed_base<mult_w, mult_i, mult_s> mult;
typedef ap_fixed_base<plus_w, plus_i, plus_s> plus;
typedef ap_fixed_base<minus_w, minus_i, minus_s> minus;
typedef ap_fixed_base<logic_w, logic_i, logic_s> logic;
typedef ap_fixed_base<div_w, div_i, div_s> div;
typedef ap_fixed_base<_AP_W, _AP_I, _AP_S> arg1;
};
INLINE void report() {
#if 0
if (_AP_W > 1024 && _AP_W <= 4096) {
fprintf(stderr, "[W] W=%d is out of bound (1<=W<=1024):"
" for synthesis, please define macro AP_INT_TYPE_EXT(N) to"
" extend the valid range.\n", _AP_W);
} else
#endif /* #if 0 */
if (_AP_W > MAX_MODE(AP_INT_MAX_W) * 1024) {
fprintf(stderr, "[E] ap_%sfixed<%d, ...>: Bitwidth exceeds the "
"default max value %d. Please use macro "
"AP_INT_MAX_W to set a larger max value.\n",
_AP_S?"":"u", _AP_W,
MAX_MODE(AP_INT_MAX_W) * 1024);
exit(1);
}
}
/// Constructors.
// -------------------------------------------------------------------------
#if 0
#ifdef __SC_COMPATIBLE__
INLINE ap_fixed_base():V(uint32_t(_AP_W), uint64_t(0)) {}
#else
INLINE ap_fixed_base():V(uint32_t(_AP_W)) {}
#endif /* #ifdef __SC_COMPATIBLE__ */
#else
INLINE ap_fixed_base():V(0) {}
#endif /* #if 0 */
// INLINE ap_fixed_base():V() {}
// INLINE explicit ap_fixed_base(const ap_private<_AP_W+_AP_I, _AP_S>& _V):V(_V) {}
INLINE ap_fixed_base(const ap_fixed_base& op):V(op.V) {}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_fixed_base(const ap_fixed_base<_AP_W2,_AP_I2,_AP_S2,_AP_Q2,_AP_O2, _AP_N2>& op):V(0) {
enum {N2=_AP_W2,_AP_F=_AP_W-_AP_I,F2=_AP_W2-_AP_I2,QUAN_INC=F2>_AP_F && !(_AP_Q==AP_TRN ||
(_AP_Q==AP_TRN_ZERO && !_AP_S2))};
if (!op) return;
bool carry=false;
//handle quantization
enum { sh_amt =(F2>_AP_F)?F2-_AP_F:_AP_F-F2};
const ap_private<_AP_W2, _AP_S2>& val = op.V;
bool neg_src=val.isNegative();
if (F2==_AP_F)
V=val;
else if (F2>_AP_F) {
if (sh_amt >= _AP_W2)
V = neg_src ? -1 : 0;
else
V = _AP_S2?val.ashr(sh_amt):val.lshr(sh_amt);
if (_AP_Q!=AP_TRN && !(_AP_Q==AP_TRN_ZERO && !_AP_S2)) {
bool qb = false;
if (F2-_AP_F>_AP_W2)
qb = neg_src;
else
qb = ap_private_ops::get<_AP_W2, _AP_S2, F2-_AP_F-1>(val);
bool r=false;
enum { pos3 = F2-_AP_F-2};
if (pos3>=_AP_W2-1)
r=val!=0;
else if (pos3>=0)
r = (val<<(_AP_W2-1-pos3))!=0;
carry = quantization_adjust(qb,r,neg_src);
}
} else { //no quantization
if (sh_amt < _AP_W) {
V=val;
V <<= sh_amt;
}
}
//hanle overflow/underflow
if ((_AP_O!=AP_WRAP || _AP_N != 0) &&
((!_AP_S && _AP_S2) || _AP_I-_AP_S <
_AP_I2 - _AP_S2 + (QUAN_INC|| (_AP_S2 &&
_AP_O==AP_SAT_SYM)))) {//saturation
bool deleted_zeros = _AP_S2?true:!carry,
deleted_ones = true;
bool lD=(_AP_I2>_AP_I && _AP_W2-_AP_I2+_AP_I>=0) &&
ap_private_ops::get<_AP_W2, _AP_S2, _AP_W2-_AP_I2+_AP_I>(val);
enum { pos1=F2-_AP_F+_AP_W, pos2=F2-_AP_F+_AP_W+1};
if (pos1 < _AP_W2) {
bool Range1_all_ones= true;
bool Range1_all_zeros= true;
if (pos1 >= 0) {
enum { __W = (_AP_W2-pos1) > 0 ? (_AP_W2-pos1) : 1 };
const ap_private<__W, _AP_S2> Range1=ap_private<__W, _AP_S2>(val.lshr(pos1));
Range1_all_ones=Range1.isAllOnesValue();
Range1_all_zeros=Range1.isMinValue();
} else {
Range1_all_ones=false;
Range1_all_zeros=val.isMinValue();
}
bool Range2_all_ones=true;
if (pos2<_AP_W2 && pos2>=0) {
enum { __W = (_AP_W2-pos2)>0 ? (_AP_W2-pos2) : 1};
ap_private<__W, true> Range2=ap_private<__W, true>(val.lshr(pos2));
Range2_all_ones=Range2.isAllOnesValue();
} else if (pos2<0)
Range2_all_ones=false;
deleted_zeros=deleted_zeros && (carry?Range1_all_ones:Range1_all_zeros);
deleted_ones=carry?Range2_all_ones&&(F2-_AP_F+_AP_W<0||!lD)
:Range1_all_ones;
neg_src= neg_src&&!(carry && Range1_all_ones);
} else
neg_src = neg_src && V[_AP_W-1];
bool neg_trg= V.isNegative();
bool overflow=(neg_trg||!deleted_zeros) && !val.isNegative();
bool underflow=(!neg_trg||!deleted_ones)&&neg_src;
//printf("neg_src = %d, neg_trg = %d, deleted_zeros = %d,
// deleted_ones = %d, overflow = %d, underflow = %d\n",
// neg_src, neg_trg, deleted_zeros, deleted_ones,
// overflow, underflow);
if (_AP_O==AP_SAT_SYM && _AP_S2 && _AP_S)
underflow |= neg_src && (_AP_W>1?V.isMinSignedValue():true);
overflow_adjust(underflow, overflow, lD, neg_src);
}
report();
}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_fixed_base(const volatile ap_fixed_base<_AP_W2,_AP_I2,
_AP_S2,_AP_Q2,_AP_O2, _AP_N2> &op) : V(op.V) {
*this = const_cast<ap_fixed_base<_AP_W2,_AP_I2,
_AP_S2,_AP_Q2,_AP_O2, _AP_N2>&>(op);
}
template<int _AP_W2, bool _AP_S2>
INLINE ap_fixed_base(const ap_private<_AP_W2,_AP_S2>& op) {
ap_fixed_base<_AP_W2,_AP_W2,_AP_S2> f_op;
f_op.V=op;
*this = f_op;
}
INLINE ap_fixed_base(bool b) {
*this=(ap_private<1,false>)b;
report();
}
INLINE ap_fixed_base(char b) {
*this=(ap_private<8,false>)b;
report();
}
INLINE ap_fixed_base(signed char b) {
*this=(ap_private<8,true>)b;
report();
}
INLINE ap_fixed_base(unsigned char b) {
*this=(ap_private<8,false>)b;
report();
}
INLINE ap_fixed_base(signed short b) {
*this=(ap_private<16,true>)b;
report();
}
INLINE ap_fixed_base(unsigned short b) {
*this=(ap_private<16,false>)b;
report();
}
INLINE ap_fixed_base(signed int b) {
*this=(ap_private<32,true>)b;
report();
}
INLINE ap_fixed_base(unsigned int b) {
*this=(ap_private<32,false>)b;
report();
}
# if defined __x86_64__
INLINE ap_fixed_base(signed long b) {
*this=(ap_private<64,true>)b;
report();
}
INLINE ap_fixed_base(unsigned long b) {
*this=(ap_private<64,false>)b;
report();
}
# else
INLINE ap_fixed_base(signed long b) {
*this=(ap_private<32,true>)b;
report();
}
INLINE ap_fixed_base(unsigned long b) {
*this=(ap_private<32,false>)b;
report();
}
# endif
INLINE ap_fixed_base(ap_slong b) {
*this=(ap_private<64,true>)b;
report();
}
INLINE ap_fixed_base(ap_ulong b) {
*this=(ap_private<64,false>)b;
report();
}
#if 1
INLINE ap_fixed_base(const char* val):V(0) {
ap_private<_AP_W, _AP_S> Tmp(val);
V = Tmp;
}
INLINE ap_fixed_base(const char* val, signed char rd): V(0) {
ap_private<_AP_W, _AP_S> Tmp(val, rd);
V = Tmp;
}
#endif
INLINE ap_fixed_base(const std::string& val) {
ap_private<_AP_W, _AP_S> Tmp(val, 2);
V = Tmp;
report();
}
template<int _AP_W2, bool _AP_S2>
INLINE ap_fixed_base(const ap_bit_ref<_AP_W2, _AP_S2>& op) {
*this = ((bool)op);
report();
}
template<int _AP_W2, bool _AP_S2>
INLINE ap_fixed_base(const ap_range_ref<_AP_W2, _AP_S2>& op) {
*this = ap_private<_AP_W2, _AP_S2>(op);
report();
}
template<int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
INLINE ap_fixed_base(const ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3>& op) {
*this = ((const ap_private<_AP_W2 + _AP_W3, false>&)(op));
report();
}
template<int _AP_W2, int _AP_I2, bool _AP_S2,
ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_fixed_base(const af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op) {
*this = (bool(op));
report();
}
template<int _AP_W2, int _AP_I2, bool _AP_S2,
ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_fixed_base(const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op) {
*this = (ap_private<_AP_W2, false>(op));
report();
}
//helper function
INLINE unsigned long long doubleToRawBits(double pf)const {
union {
unsigned long long __L;
double __D;
}LD;
LD.__D=pf;
return LD.__L;
}
INLINE double rawBitsToDouble(unsigned long long pi) const {
union {
unsigned long long __L;
double __D;
}LD;
LD.__L=pi;
return LD.__D;
}
INLINE float rawBitsToFloat(uint32_t pi) const {
union {
uint32_t __L;
float __D;
}LD;
LD.__L = pi;
return LD.__D;
}
INLINE ap_fixed_base(double d):V(0) {
if (!d) return;
const bool isneg=d<0;
const uint64_t ireg=doubleToRawBits(isneg?-d:d);
if ((ireg&0x7fffffffffffffffULL)!=0) {
const int32_t exp=(((ireg)>>DOUBLE_MAN)&0x07ff)-DOUBLE_BIAS;
ap_private<DOUBLE_MAN+2, true> man = ireg & DOUBLE_MAN_MASK;
man.clear(DOUBLE_MAN+1);
man.set(DOUBLE_MAN);
if (isneg) {
man.flip();
man++;
}
enum {_AP_S2=true, _AP_W2=DOUBLE_MAN+2,_AP_F=_AP_W -_AP_I };
const int _AP_I2=exp+2;
const int F2=_AP_W2-_AP_I2;
const bool QUAN_INC=F2>_AP_F && !(_AP_Q==AP_TRN || (_AP_Q==AP_TRN_ZERO &&
!_AP_S2));
bool carry=false;
//handle quantization
const unsigned sh_amt=abs(F2-_AP_F); // sh_amt = F2>_AP_F ? F2 -_AP_F : _AP_F-F2;
if (F2==_AP_F )
V=man;
else if (F2>_AP_F) {
if (sh_amt >= DOUBLE_MAN+2)
V=isneg?-1:0;
else
V=(man>>sh_amt) | ((man & 1ULL<<(DOUBLE_MAN+1)) ? (DOUBLE_MAN_MASK>>(DOUBLE_MAN+2-sh_amt) <<(DOUBLE_MAN+2-sh_amt)):0);
if (_AP_Q!=AP_TRN && !(_AP_Q==AP_TRN_ZERO && !_AP_S2)) {
const bool qb=((F2-_AP_F > DOUBLE_MAN+2) ? isneg : (man & (1ULL<<(F2-_AP_F-1))) != 0);
const int pos3=F2-_AP_F-2;
const bool r = (pos3>= 0) ? (man << AP_MAX(0, _AP_W2-pos3-1)& DOUBLE_MAN_MASK)!=0 : false;
carry = quantization_adjust(qb,r,isneg);
}
}
else { //no quantization
// V=man;
if (sh_amt < _AP_W) {
V = man;
V <<= sh_amt;
}
}
//handle overflow/underflow
if ((_AP_O != AP_WRAP || _AP_N != 0) &&
((!_AP_S && _AP_S2) || _AP_I-_AP_S <
_AP_I2-_AP_S2+(QUAN_INC|| (_AP_S2 &&
_AP_O==AP_SAT_SYM)) )) {// saturation
bool deleted_zeros = _AP_S2?true:!carry,
deleted_ones = true;
bool neg_src;
const bool lD=(_AP_I2>_AP_I) && (_AP_W2-_AP_I2+_AP_I>=0) && (man & (1ULL <<(DOUBLE_MAN+2-_AP_I2+_AP_I)));
int pos1=F2+_AP_W-_AP_F;
if (pos1 < _AP_W2) {
int pos2=pos1+1;
bool Range1_all_ones=true;
bool Range1_all_zeros=true;
if (pos1>=0) {
ap_private<_AP_W,_AP_S> Range1=
ap_private<_AP_W,_AP_S>((man >> pos1) | ((1ULL<<(DOUBLE_MAN+1)&man) ? (DOUBLE_MAN_MASK >> (DOUBLE_MAN+2-pos1) <<(DOUBLE_MAN+2-pos1)):0));
Range1_all_ones = Range1.isAllOnesValue(); // Range1.isAllOnesValue();
Range1_all_zeros = Range1.isMinValue(); // Range1.isMinValue();
} else {
Range1_all_ones=false;
Range1_all_zeros = man==0; // man.isMinValue();
}
bool Range2_all_ones=true;
if (pos2<_AP_W2 && pos2>=0) {
ap_private<_AP_W, _AP_S> Range2=
ap_private<_AP_W, _AP_S>((man >> pos2) | ((1ULL<<(DOUBLE_MAN+1)&man) ? (DOUBLE_MAN_MASK >> (DOUBLE_MAN+2-pos2) <<(DOUBLE_MAN+2-pos2)):0));
Range2_all_ones=Range2.isAllOnesValue(); // Range2.isAllOnesValue();
} else if (pos2<0)
Range2_all_ones=false;
deleted_zeros=deleted_zeros && (carry?Range1_all_ones:Range1_all_zeros);
deleted_ones=carry?Range2_all_ones&&(F2-_AP_F+_AP_W<0||!lD) : Range1_all_ones;
neg_src=isneg&&!(carry&Range1_all_ones);
} else
neg_src = isneg && V[_AP_W -1];
const bool neg_trg=V.isNegative();
const bool overflow=(neg_trg||!deleted_zeros) && !isneg;
bool underflow=(!neg_trg||!deleted_ones)&&neg_src;
//printf("neg_src = %d, neg_trg = %d, deleted_zeros = %d,
// deleted_ones = %d, overflow = %d, underflow = %d\n",
// neg_src, neg_trg, deleted_zeros, deleted_ones,
// overflow, underflow);
if (_AP_O==AP_SAT_SYM && _AP_S2 && _AP_S)
underflow |= neg_src && (_AP_W>1?V.isMinSignedValue():true);
overflow_adjust(underflow,overflow,lD, neg_src);
}
}
report();
}
///assign operators
//-------------------------------------------------------------------------
INLINE volatile ap_fixed_base& operator=(const ap_fixed_base<_AP_W, _AP_I, _AP_S,
_AP_Q, _AP_O, _AP_N>& op) volatile {
V = op.V;
return *this;
}
INLINE ap_fixed_base& operator=(const ap_fixed_base<_AP_W, _AP_I, _AP_S,
_AP_Q, _AP_O, _AP_N>& op) {
V = op.V;
return *this;
}
INLINE volatile ap_fixed_base& operator=(const volatile ap_fixed_base<_AP_W, _AP_I, _AP_S,
_AP_Q, _AP_O, _AP_N>& op) volatile {
V = op.V;
return *this;
}
INLINE ap_fixed_base& operator=(const volatile ap_fixed_base<_AP_W, _AP_I, _AP_S,
_AP_Q, _AP_O, _AP_N>& op) {
V = op.V;
return *this;
}
// Set this ap_fixed_base with a bits string. That means the ssdm_int::V
// inside this ap_fixed_base is assigned by bv.
// Note the input parameter should be a fixed-point formatted bit string.
INLINE ap_fixed_base& setBits(unsigned long long bv) {
V=bv;
return *this;
}
// Return a ap_fixed_base object whose ssdm_int::V is assigned by bv.
// Note the input parameter should be a fixed-point formatted bit string.
static INLINE ap_fixed_base bitsToFixed(unsigned long long bv) {
ap_fixed_base Tmp=bv;
return Tmp;
}
// Explicit conversion functions to ap_private that captures
// all integer bits (bits are truncated)
INLINE ap_private<AP_MAX(_AP_I,1),_AP_S>
to_ap_private(bool Cnative = true) const {
ap_private<AP_MAX(_AP_I,1),_AP_S> ret = ap_private<AP_MAX(_AP_I,1),_AP_S> ((_AP_I >= 1) ? (_AP_S==true ? V.ashr(AP_MAX(0,_AP_W - _AP_I)) : V.lshr(AP_MAX(0,_AP_W - _AP_I))) : ap_private<_AP_W, _AP_S>(0));
if (Cnative) {
bool r = false;
if (_AP_I < _AP_W) {
if (_AP_I > 0) r = !(V.getLoBits(_AP_W - _AP_I).isMinValue());
else r = !(V.isMinValue());
}
if (r && V.isNegative()) { // if this is negative integer
++ret;//ap_private<AP_MAX(_AP_I,1),_AP_S>(1,_AP_S);
}
} else {
//Follow OSCI library, conversion from sc_fixed to sc_int
}
return ret;
}
template<int _AP_W2, bool _AP_S2>
INLINE operator ap_private<_AP_W2,_AP_S2> () const {
return (ap_private<_AP_W2,_AP_S2>)to_ap_private();
}
template<int _AP_W2, bool _AP_S2, int _AP_N2>
INLINE operator ap_private<_AP_W2,_AP_S2,_AP_N2> () const {
return (ap_private<_AP_W2,_AP_S2,_AP_N2>)to_ap_private();
}
//Explict conversion function to C built-in integral type
INLINE int to_int() const {
return to_ap_private().to_int();
}
INLINE int to_uint() const {
return to_ap_private().to_uint();
}
INLINE ap_slong to_int64() const {
return to_ap_private().to_int64();
}
INLINE ap_ulong to_uint64() const {
return to_ap_private().to_uint64();
}
INLINE double to_double() const {
if (!V)
return 0;
if (_AP_W>64 || (_AP_W - _AP_I) > 0) {
bool isneg = _AP_S && V[_AP_W-1];
uint64_t res = isneg ? 0x8000000000000000ULL : 0;
ap_private<_AP_W, false> tmp = V;
if (isneg) tmp = -tmp;
int i = _AP_W -1 - tmp.countLeadingZeros();
int exp = _AP_I-(_AP_W-i);
res|=((uint64_t)(exp+DOUBLE_BIAS))<<DOUBLE_MAN;
if (i!=0) {
tmp.clear(i);
uint64_t man = ((i>DOUBLE_MAN)?tmp.lshr(i-DOUBLE_MAN):tmp).to_uint64() & DOUBLE_MAN_MASK;
res |= i<DOUBLE_MAN ? (man)<<(DOUBLE_MAN-i)& DOUBLE_MAN_MASK : man;
}
double dp=rawBitsToDouble(res);
return dp;
} else if (_AP_W - _AP_I > 0) {
/* This specialization is disabled. It is giving wrong results in some cases.
bool isneg=V.isNegative();
double dp = V.get();
dp /= (1<< (_AP_W - _AP_I));
return dp;*/
} else
return double(to_int64());
}
INLINE float to_float() const {
uint32_t res=0;
if (V==0)
return 0;
bool isneg=V.isNegative();
ap_private<_AP_W, _AP_S> tmp=V;
if (isneg) tmp = -tmp;
if (_AP_W-_AP_I>0||_AP_W>64) {
if (isneg)
res=0x80000000;
int i=_AP_W-1;
i-=tmp.countLeadingZeros();
int exp=_AP_I-(_AP_W-i);
res|=(exp+FLOAT_BIAS)<<FLOAT_MAN;
ap_private<_AP_W, _AP_S> man = 0;
if (i!=0) {
tmp.clear(i);
if (i>FLOAT_MAN)
man=tmp.lshr(i-FLOAT_MAN);
else
man=tmp;
res |= i < FLOAT_MAN?man.getZExtValue()<<(FLOAT_MAN-i):man.getZExtValue();
}
} else {
return float(to_int64());
}
float dp=rawBitsToFloat(res);
return dp;
}
INLINE operator double () const {
return to_double();
}
#ifndef __SC_COMPATIBLE__
INLINE operator float () const {
return to_float();
}
INLINE operator char () const {
return (char) to_int();
}
INLINE operator unsigned char () const {
return (unsigned char) to_uint();
}
INLINE operator short () const {
return (short) to_int();
}
INLINE operator unsigned short () const {
return (unsigned short) to_uint();
}
INLINE operator int () const {
return to_int();
}
INLINE operator unsigned int () const {
return to_uint();
}
#if 1
#ifdef __x86_64__
INLINE operator long () const {
return (long)to_int64();
}
INLINE operator unsigned long () const {
return (unsigned long) to_uint64();
}
#else
INLINE operator long () const {
return to_int64();
}
INLINE operator unsigned long () const {
return to_uint64();
}
#endif
#endif
INLINE operator unsigned long long () const {
return to_uint64();
}
INLINE operator long long () const {
return to_int64();
}
#endif
INLINE std::string to_string(uint8_t radix=2, bool sign=false) const;
INLINE ap_slong bits_to_int64() const {
ap_private<AP_MIN(_AP_W, 64), _AP_S> res(V);
return (ap_slong) res;
}
INLINE ap_ulong bits_to_uint64() const {
ap_private<AP_MIN(64,_AP_W), _AP_S> res(V);
return (ap_ulong) res;
}
INLINE int length() const {return _AP_W;}
// Count the number of zeros from the most significant bit
// to the first one bit. Note this is only for ap_fixed_base whose
// _AP_W <= 64, otherwise will incur assertion.
INLINE int countLeadingZeros() {
return V.countLeadingZeros();
}
///Arithmetic:Binary
//-------------------------------------------------------------------------
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE typename RType<_AP_W2,_AP_I2,_AP_S2>::mult
operator * (const ap_fixed_base<_AP_W2,_AP_I2,_AP_S2,_AP_Q2,_AP_O2, _AP_N2>& op2) const {
typename RType<_AP_W2,_AP_I2,_AP_S2>::mult r;
r.V = V * op2.V;
return r;
}
template<int _AP_W1, int _AP_I1, bool _AP_S1, int _AP_W2, int _AP_I2, bool _AP_S2>
static INLINE ap_fixed_base multiply(const ap_fixed_base<_AP_W1,_AP_I1,_AP_S1>& op1, const
ap_fixed_base<_AP_W2,_AP_I2,_AP_S2>& op2) {
ap_private<_AP_W+_AP_W2, _AP_S> OP1=op1.V;
ap_private<_AP_W2,_AP_S2> OP2=op2.V;
return OP1*OP2;
}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE typename RType<_AP_W2,_AP_I2,_AP_S2>::div
operator / (const ap_fixed_base<_AP_W2,_AP_I2,_AP_S2,_AP_Q2,_AP_O2, _AP_N2>& op2) const {
enum {F2 = _AP_W2-_AP_I2, _W1=AP_MAX(_AP_W + AP_MAX(F2, 0), _AP_W2),
_W2=AP_MAX(_AP_W2,AP_MAX(_AP_W + AP_MAX(F2, 0), _AP_W2))};
ap_private<_W1, _AP_S> dividend = (ap_private<_W1, _AP_S>(V)) << ((_W1>_AP_W)?F2:0);
ap_private<_W1, _AP_S2> divisior = ap_private<_W2, _AP_S2>(op2.V);
ap_private<_W1, _AP_S> ret = ap_private<_W1,_AP_S> ((_AP_S||_AP_S2) ? dividend.sdiv(divisior): dividend.udiv(divisior));
typename RType<_AP_W2, _AP_I2, _AP_S2>::div r;
r.V = ret;
return r;
}
#define OP_BIN_AF(Sym, Rty, Width, Sign, Fun) \
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2> \
INLINE typename RType<_AP_W2,_AP_I2,_AP_S2>::Rty \
operator Sym (const ap_fixed_base<_AP_W2,_AP_I2,_AP_S2,_AP_Q2,_AP_O2, _AP_N2>& op2) const \
{ \
enum {_AP_F=_AP_W-_AP_I, F2=_AP_W2-_AP_I2}; \
typename RType<_AP_W2,_AP_I2,_AP_S2>::Rty r, lhs(*this), rhs(op2); \
r.V = lhs.V.Fun(rhs.V); \
return r; \
} \
INLINE typename RType<_AP_W,_AP_I,_AP_S>::Rty \
operator Sym (const ap_fixed_base& op2) const \
{ \
typename RType<_AP_W,_AP_I,_AP_S>::Rty r; \
r.V = V Sym op2.V; \
return r; \
} \
OP_BIN_AF(+, plus, plus_w, plus_s, Add)
OP_BIN_AF(-, minus, minus_w, minus_s, Sub)
#define OP_LOGIC_BIN_AF(Sym, Rty, Width, Sign) \
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2> \
INLINE typename RType<_AP_W2,_AP_I2,_AP_S2>::Rty \
operator Sym (const ap_fixed_base<_AP_W2,_AP_I2,_AP_S2,_AP_Q2,_AP_O2, _AP_N2>& op2) const \
{ \
typename RType<_AP_W2,_AP_I2,_AP_S2>::Rty r, lhs(*this), rhs(op2); \
r.V=lhs.V Sym rhs.V; \
return r; \
} \
INLINE typename RType<_AP_W,_AP_I,_AP_S>::Rty \
operator Sym (const ap_fixed_base& op2) const \
{ \
typename RType<_AP_W,_AP_I,_AP_S>::Rty r; \
r.V = V Sym op2.V; \
return r; \
} \
INLINE typename RType<_AP_W,_AP_I,_AP_S>::Rty operator Sym(int op2) const \
{ \
return V Sym (op2<<(_AP_W - _AP_I)); \
}
OP_LOGIC_BIN_AF(&, logic, logic_w, logic_s)
OP_LOGIC_BIN_AF(|, logic, logic_w, logic_s)
OP_LOGIC_BIN_AF(^, logic, logic_w, logic_s)
///Arithmic : assign
//-------------------------------------------------------------------------
#define OP_ASSIGN_AF(Sym) \
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2> \
INLINE ap_fixed_base& operator Sym##= (const ap_fixed_base<_AP_W2,_AP_I2,_AP_S2,_AP_Q2,_AP_O2, _AP_N2>& op2) \
{ \
*this=operator Sym (op2) ; \
return *this; \
}
OP_ASSIGN_AF(+)
OP_ASSIGN_AF(-)
OP_ASSIGN_AF(&)
OP_ASSIGN_AF(|)
OP_ASSIGN_AF(^)
OP_ASSIGN_AF(*)
OP_ASSIGN_AF(/)
///Prefix increment, decrement
//-------------------------------------------------------------------------
INLINE ap_fixed_base& operator ++() {
operator+=(ap_fixed_base<1,1,false>(1)); //SystemC's semantics
return *this;
}
INLINE ap_fixed_base& operator --() {
operator-=(ap_fixed_base<1,1,false>(1)); //SystemC's semantics
return *this;
}
//Postfix increment, decrement
//-------------------------------------------------------------------------
INLINE const ap_fixed_base operator ++(int) {
ap_fixed_base t(*this);
operator++();
return t;
}
INLINE const ap_fixed_base operator --(int) {
ap_fixed_base t = *this;
operator--();
return t;
}
///Unary arithmetic
//-------------------------------------------------------------------------
INLINE ap_fixed_base operator +() {return *this;}
INLINE ap_fixed_base<_AP_W + 1, _AP_I + 1, true> operator -() const {
ap_fixed_base<_AP_W + 1, _AP_I + 1, true> Tmp(*this);
Tmp.V = - Tmp.V;
return Tmp;
}
INLINE ap_fixed_base<_AP_W,_AP_I,true,_AP_Q,_AP_O, _AP_N> getNeg() {
ap_fixed_base<_AP_W,_AP_I,true,_AP_Q,_AP_O, _AP_N> Tmp(*this);
Tmp.V=-Tmp.V;
return Tmp;
}
///Not (!)
//-------------------------------------------------------------------------
INLINE bool operator !() const {
return !V;
}
///Bitwise complement
//-------------------------------------------------------------------------
INLINE ap_fixed_base<_AP_W, _AP_I, _AP_S>
operator ~() const {
ap_fixed_base<_AP_W, _AP_I, _AP_S> res(*this);
res.V.flip();
return res;
}
///Shift
///template argument as shift value
template<int _AP_SHIFT>
INLINE ap_fixed_base<_AP_W, _AP_I + _AP_SHIFT, _AP_S> lshift () const {
ap_fixed_base<_AP_W, _AP_I + _AP_SHIFT, _AP_S> r;
r.V = V;
return r;
}
template<int _AP_SHIFT>
INLINE ap_fixed_base<_AP_W, _AP_I - _AP_SHIFT, _AP_S> rshift () const {
ap_fixed_base<_AP_W, _AP_I - _AP_SHIFT, _AP_S> r;
r.V = V;
return r;
}
//Because the return type is the type of the the first operand, shift assign
//operators do not carry out any quantization or overflow
//While systemc, shift assigns for sc_fixed/sc_ufixed will result in
//quantization or overflow (depending on the mode of the first operand)
//-------------------------------------------------------------------------
INLINE ap_fixed_base operator << (int sh) const {
ap_fixed_base r;
bool isNeg=(sh&0x80000000) != 0;
sh=isNeg?-sh:sh;
bool shiftoverflow = sh >= _AP_W;
bool NegSrc = V.isNegative();
if (isNeg) {
if (shiftoverflow)
NegSrc?r.V.set():r.V.clear();
else
r.V=_AP_S?V.ashr(sh):V.lshr(sh);
} else {
if (shiftoverflow)
r.V.clear();
else
r.V=V<<sh;
}
#ifdef __SC_COMPATIBLE__
if (sh == 0) return r;
if (isNeg == true && _AP_Q != AP_TRN) {
bool qb = false;
if (sh <= _AP_W) qb = V[sh - 1];
bool rb = false;
if (sh > 1 && sh <= _AP_W)
rb = (V << (_AP_W - sh + 1 )) != 0;
else if (sh > _AP_W)
rb = V != 0;
r.quantization_adjust(qb, rb, NegSrc);
} else if (isNeg == false && _AP_O != AP_WRAP) {
bool allones, allzeros;
if (sh < _AP_W ) {
ap_private<_AP_W, _AP_S > range1 = V.lshr(_AP_W - sh - 1);
allones = range1.isAllOnesValue();
allzeros = range1.isMinValue();
} else {
allones = false;
allzeros = V.isMinValue();
}
bool overflow = !allzeros && !NegSrc;
bool underflow = !allones && NegSrc;
if (_AP_O == AP_SAT_SYM && _AP_S)
underflow |= NegSrc && (_AP_W > 1 ? r.V.isMinSignedValue():true);
bool lD = false;
if ( sh < _AP_W ) lD = V[_AP_W - sh - 1];
r.overflow_adjust(underflow, overflow, lD, NegSrc);
}
#endif
return r;
}
template<int _AP_W2>
INLINE ap_fixed_base operator<<(const ap_private<_AP_W2,true>& op2) const {
int sh = op2.to_int();
return operator << (sh);
}
INLINE ap_fixed_base operator << (unsigned int sh ) const {
ap_fixed_base r;
bool shiftoverflow = sh >= _AP_W;
r.V = shiftoverflow ? ap_private<_AP_W, _AP_S >(0) : V << sh;
if (sh == 0) return r;
#ifdef __SC_COMPATIBLE__
bool NegSrc = V.isNegative();
if (_AP_O != AP_WRAP) {
bool allones, allzeros;
if (sh < _AP_W ) {
ap_private<_AP_W, _AP_S > range1 = V.lshr(_AP_W - sh -1);
allones = range1.isAllOnesValue();
allzeros = range1.isMinValue();
} else {
allones = false;
allzeros = V.isMinValue();
}
bool overflow = !allzeros && !NegSrc;
bool underflow = !allones && NegSrc;
if (_AP_O == AP_SAT_SYM && _AP_S)
underflow |= NegSrc && (_AP_W > 1 ? r.V.isMinSignedValue():true);
bool lD = false;
if ( sh < _AP_W ) lD = V[_AP_W - sh - 1];
r.overflow_adjust(underflow, overflow, lD, NegSrc);
}
#endif
return r;
}
template<int _AP_W2>
INLINE ap_fixed_base operator << (const ap_private<_AP_W2,false>& op2) const {
unsigned int sh = op2.to_uint();
return operator << (sh);
}
INLINE ap_fixed_base operator >> (int sh) const {
ap_fixed_base r;
bool isNeg=(sh&0x80000000) != 0;
bool NegSrc = V.isNegative();
sh=isNeg?-sh:sh;
bool shiftoverflow = sh >= _AP_W;
if (isNeg && !shiftoverflow) r.V=V<<sh;
else {
if (shiftoverflow)
NegSrc?r.V.set():r.V.clear();
else
r.V=_AP_S?V.ashr(sh):V.lshr(sh);
}
#ifdef __SC_COMPATIBLE__
if (sh == 0) return r;
if (isNeg == false && _AP_Q != AP_TRN) {
bool qb = false;
if (sh <= _AP_W) qb = V[sh - 1];
bool rb = false;
if (sh > 1 && sh <= _AP_W)
rb = (V << (_AP_W - sh + 1 )) != 0;
else if (sh > _AP_W)
rb = V != 0;
r.quantization_adjust(qb, rb, NegSrc);
} else if (isNeg == true && _AP_O != AP_WRAP) {
bool allones, allzeros;
if (sh < _AP_W ) {
ap_private<_AP_W, _AP_S > range1 = V.lshr(_AP_W - sh - 1);
allones = range1.isAllOnesValue();
allzeros = range1.isMinValue();
} else {
allones = false;
allzeros = V.isMinValue();
}
bool overflow = !allzeros && !NegSrc;
bool underflow = !allones && NegSrc;
if (_AP_O == AP_SAT_SYM && _AP_S)
underflow |= NegSrc && (_AP_W > 1 ? r.V.isMinSignedValue():true);
bool lD = false;
if ( sh < _AP_W ) lD = V[_AP_W - sh - 1];
r.overflow_adjust(underflow, overflow, lD, NegSrc);
}
#endif
return r;
}
template<int _AP_W2>
INLINE ap_fixed_base operator >> (const ap_private<_AP_W2,true>& op2) const {
int sh = op2.to_int();
return operator >> (sh);
}
INLINE ap_fixed_base operator >> (unsigned int sh) const {
ap_fixed_base r;
bool NegSrc = V.isNegative();
bool shiftoverflow = sh >= _AP_W;
if (shiftoverflow)
NegSrc?r.V.set():r.V.clear();
else
r.V=_AP_S?V.ashr(sh):V.lshr(sh);
#ifdef __SC_COMPATIBLE__
if (sh == 0) return r;
if (_AP_Q != AP_TRN) {
bool qb = false;
if (sh <= _AP_W) qb = V[sh - 1];
bool rb = false;
if (sh > 1 && sh <= _AP_W)
rb = (V << (_AP_W - sh + 1 )) != 0;
else if (sh > _AP_W)
rb = V != 0;
r.quantization_adjust(qb, rb, NegSrc);
}
#endif
return r;
}
template<int _AP_W2>
INLINE ap_fixed_base operator >> (const ap_private<_AP_W2,false>& op2) const {
unsigned int sh = op2.to_uint();
return operator >> (sh);
}
///shift assign
//-------------------------------------------------------------------------
#define OP_AP_SHIFT_AP_ASSIGN_AF(Sym) \
template<int _AP_W2, bool _AP_S2> \
INLINE ap_fixed_base& operator Sym##=(const ap_private<_AP_W2,_AP_S2>& op2) \
{ \
*this=operator Sym (op2); \
return *this; \
}
OP_AP_SHIFT_AP_ASSIGN_AF(<<)
OP_AP_SHIFT_AP_ASSIGN_AF(>>)
///Support shift(ap_fixed_base)
#define OP_AP_SHIFT_AF(Sym) \
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2> \
INLINE ap_fixed_base operator Sym (const ap_fixed_base<_AP_W2,_AP_I2,_AP_S2,_AP_Q2,_AP_O2, _AP_N2>& op2) const \
{ \
return operator Sym (op2.to_ap_private()); \
} \
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2> \
INLINE ap_fixed_base& operator Sym##= (const ap_fixed_base<_AP_W2,_AP_I2,_AP_S2,_AP_Q2,_AP_O2, _AP_N2>& op2) \
{ \
*this=operator Sym (op2); \
return *this; \
}
OP_AP_SHIFT_AF(<<)
OP_AP_SHIFT_AF(>>)
INLINE ap_fixed_base& operator >>= (unsigned int sh) {
*this = operator >> (sh);
return *this;
}
INLINE ap_fixed_base& operator <<= (unsigned int sh) {
*this = operator << (sh);
return *this;
}
INLINE ap_fixed_base& operator >>= (int sh) {
*this = operator >> (sh);
return *this;
}
INLINE ap_fixed_base& operator <<= (int sh) {
*this = operator << (sh);
return *this;
}
///Comparisons
//-------------------------------------------------------------------------
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE bool operator == (const ap_fixed_base<_AP_W2,_AP_I2,_AP_S2,_AP_Q2,_AP_O2, _AP_N2>& op2) const {
enum {_AP_F=_AP_W-_AP_I,F2=_AP_W2-_AP_I2, shAmt1 = AP_MAX(F2-_AP_F, 0), shAmt2 = AP_MAX(_AP_F-F2,0), _AP_W3 = (_AP_F==F2) ? AP_MAX(_AP_W,_AP_W2) : AP_MAX(_AP_W+shAmt1, _AP_W2+shAmt2)};
ap_private<_AP_W3, _AP_S > OP1= ap_private<_AP_W3, _AP_S >(V)<<shAmt1;
ap_private<_AP_W3,_AP_S2 > OP2=ap_private<_AP_W3,_AP_S2 >(op2.V)<<shAmt2;
return OP1 == OP2;
}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE bool operator != (const ap_fixed_base<_AP_W2,_AP_I2,_AP_S2,_AP_Q2,_AP_O2, _AP_N2>& op2) const {
return !(*this==op2);
}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE bool operator > (const ap_fixed_base<_AP_W2,_AP_I2,_AP_S2,_AP_Q2,_AP_O2, _AP_N2>& op2) const {
enum {_AP_F=_AP_W-_AP_I,F2=_AP_W2-_AP_I2, shAmt1 = AP_MAX(F2-_AP_F, 0), shAmt2 = AP_MAX(_AP_F-F2,0), _AP_W3 = (_AP_F==F2) ? AP_MAX(_AP_W,_AP_W2) : AP_MAX(_AP_W+shAmt1, _AP_W2+shAmt2)};
ap_private<_AP_W3, _AP_S > OP1= ap_private<_AP_W3, _AP_S >(V)<<shAmt1;
ap_private<_AP_W3,_AP_S2 > OP2=ap_private<_AP_W3,_AP_S2 >(op2.V)<<shAmt2;
if (_AP_S||_AP_S2)
return OP1.sgt(OP2);
else
return OP1.ugt(OP2);
}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE bool operator <= (const ap_fixed_base<_AP_W2,_AP_I2,_AP_S2,_AP_Q2,_AP_O2, _AP_N2>& op2) const {
return !(*this>op2);
}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE bool operator < (const ap_fixed_base<_AP_W2,_AP_I2,_AP_S2,_AP_Q2,_AP_O2, _AP_N2>& op2) const {
enum {_AP_F=_AP_W-_AP_I,F2=_AP_W2-_AP_I2, shAmt1 = AP_MAX(F2-_AP_F, 0), shAmt2 = AP_MAX(_AP_F-F2,0), _AP_W3 = (_AP_F==F2) ? AP_MAX(_AP_W,_AP_W2) : AP_MAX(_AP_W+shAmt1, _AP_W2+shAmt2)};
ap_private<_AP_W3, _AP_S > OP1= ap_private<_AP_W3, _AP_S >(V)<<shAmt1;
ap_private<_AP_W3,_AP_S2 > OP2=ap_private<_AP_W3,_AP_S2 >(op2.V)<<shAmt2;
if (_AP_S||_AP_S2)
return OP1.slt(OP2);
else
return OP1.ult(OP2);
}
template<int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE bool operator >= (const ap_fixed_base<_AP_W2,_AP_I2,_AP_S2,_AP_Q2,_AP_O2, _AP_N2>& op2) const {
return !(*this<op2);
}
#define DOUBLE_CMP_AF(Sym) \
INLINE bool operator Sym (double d) const { \
return to_double() Sym d; \
}
DOUBLE_CMP_AF(==)
DOUBLE_CMP_AF(!=)
DOUBLE_CMP_AF(>)
DOUBLE_CMP_AF(>=)
DOUBLE_CMP_AF(<)
DOUBLE_CMP_AF(<=)
// Bit and Slice Select
INLINE af_bit_ref<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N> operator [] (unsigned int index) {
assert(index<_AP_W&&"Attemping to read bit beyond MSB");
return af_bit_ref<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>(this, index);
}
INLINE af_bit_ref<_AP_W, _AP_I,_AP_S,_AP_Q,_AP_O, _AP_N> bit(unsigned int index) {
assert(index < _AP_W && "Attempting to read bit beyond MSB");
return af_bit_ref<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>(this, index);
}
template<int _AP_W2, bool _AP_S2>
INLINE af_bit_ref<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N> bit (const ap_private<_AP_W2,_AP_S2>& index) {
assert(index >= 0 && "Attempting to read bit with negative index");
assert(index < _AP_W && "Attempting to read bit beyond MSB");
return af_bit_ref<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>(this, index.to_int());
}
INLINE bool bit (unsigned int index) const {
assert(index < _AP_W && "Attempting to read bit beyond MSB");
return V[index];
}
INLINE bool operator [] (unsigned int index) const {
assert(index < _AP_W && "Attempting to read bit beyond MSB");
return V[index];
}
template<int _AP_W2, bool _AP_S2>
INLINE bool bit (const ap_private<_AP_W2, _AP_S2>& index) const {
assert(index < _AP_W && "Attempting to read bit beyond MSB");
return V[index.to_uint()];
}
template<int _AP_W2, bool _AP_S2>
INLINE bool operator [] (const ap_private<_AP_W2, _AP_S2>& index) const {
assert(index < _AP_W && "Attempting to read bit beyond MSB");
return V[index.to_uint()];
}
INLINE af_bit_ref<_AP_W, _AP_I,_AP_S,_AP_Q,_AP_O, _AP_N> get_bit(int index) {
assert(index < _AP_I && "Attempting to read bit beyond MSB");
assert(index >= _AP_I - _AP_W&& "Attempting to read bit beyond MSB");
return af_bit_ref<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>(this, index + _AP_W - _AP_I);
}
template<int _AP_W2>
INLINE af_bit_ref<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N> get_bit (const ap_private<_AP_W2, true>& index) {
assert(index >= _AP_I - _AP_W && "Attempting to read bit with negative index");
assert(index < _AP_I && "Attempting to read bit beyond MSB");
return af_bit_ref<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>(this, index.to_int() + _AP_W - _AP_I);
}
INLINE bool get_bit (int index) const {
assert(index >= _AP_I - _AP_W && "Attempting to read bit with negative index");
assert(index < _AP_I && "Attempting to read bit beyond MSB");
return V[index + _AP_W - _AP_I];
}
template<int _AP_W2>
INLINE bool get_bit (const ap_private<_AP_W2, true>& index) const {
assert(index >= _AP_I - _AP_W && "Attempting to read bit with negative index");
assert(index < _AP_I && "Attempting to read bit beyond MSB");
return V[index.to_int() + _AP_W - _AP_I];
}
INLINE af_range_ref<_AP_W,_AP_I,_AP_S, _AP_Q, _AP_O, _AP_N>
range(int Hi, int Lo) {
assert((Hi < _AP_W) && (Lo < _AP_W) && "Out of bounds in range()");
return af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>(this, Hi, Lo);
}
INLINE af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>
operator () (int Hi, int Lo) {
assert((Hi < _AP_W) && (Lo < _AP_W) && "Out of bounds in range()");
return af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>(this, Hi, Lo);
}
INLINE af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>
range(int Hi, int Lo) const {
assert((Hi < _AP_W) && (Lo < _AP_W) &&"Out of bounds in range()");
return af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>(const_cast<ap_fixed_base*>(this), Hi, Lo);
}
INLINE af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>
operator () (int Hi, int Lo) const {
return this->range(Hi, Lo);
}
template<int _AP_W2, bool _AP_S2, int _AP_W3, bool _AP_S3>
INLINE af_range_ref<_AP_W,_AP_I,_AP_S, _AP_Q, _AP_O, _AP_N>
range(const ap_private<_AP_W2, _AP_S2> &HiIdx,
const ap_private<_AP_W3, _AP_S3> &LoIdx) {
int Hi = HiIdx.to_int();
int Lo = LoIdx.to_int();
assert((Hi < _AP_W) && (Lo < _AP_W) && "Out of bounds in range()");
return af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>(this, Hi, Lo);
}
template<int _AP_W2, bool _AP_S2, int _AP_W3, bool _AP_S3>
INLINE af_range_ref<_AP_W,_AP_I,_AP_S, _AP_Q, _AP_O, _AP_N>
operator () (const ap_private<_AP_W2, _AP_S2> &HiIdx,
const ap_private<_AP_W3, _AP_S3> &LoIdx) {
int Hi = HiIdx.to_int();
int Lo = LoIdx.to_int();
assert((Hi < _AP_W) && (Lo < _AP_W) && "Out of bounds in range()");
return af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>(this, Hi, Lo);
}
template<int _AP_W2, bool _AP_S2, int _AP_W3, bool _AP_S3>
INLINE af_range_ref<_AP_W,_AP_I,_AP_S, _AP_Q, _AP_O, _AP_N>
range(const ap_private<_AP_W2, _AP_S2> &HiIdx,
const ap_private<_AP_W3, _AP_S3> &LoIdx) const {
int Hi = HiIdx.to_int();
int Lo = LoIdx.to_int();
assert((Hi < _AP_W) && (Lo < _AP_W) && "Out of bounds in range()");
return af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>(const_cast<
ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>*>(this),
Hi, Lo);
}
template<int _AP_W2, bool _AP_S2, int _AP_W3, bool _AP_S3>
INLINE af_range_ref<_AP_W,_AP_I,_AP_S, _AP_Q, _AP_O, _AP_N>
operator () (const ap_private<_AP_W2, _AP_S2> &HiIdx,
const ap_private<_AP_W3, _AP_S3> &LoIdx) const {
int Hi = HiIdx.to_int();
int Lo = LoIdx.to_int();
return this->range(Hi, Lo);
}
INLINE af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>
range() {
return this->range(_AP_W - 1, 0);
}
INLINE af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>
range() const {
return this->range(_AP_W - 1, 0);
}
INLINE bool is_zero () const {
return V.isMinValue();
}
INLINE bool is_neg () const {
if (V.isNegative())
return true;
return false;
}
INLINE int wl () const {
return _AP_W;
}
INLINE int iwl () const {
return _AP_I;
}
INLINE ap_q_mode q_mode () const {
return _AP_Q;
}
INLINE ap_o_mode o_mode () const {
return _AP_O;
}
INLINE int n_bits () const {
return 0;
}
//private:
public:
ap_private<_AP_W, _AP_S> V;
};
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
std::string ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>::to_string(
uint8_t radix, bool sign) const {
std::string str;
str.clear();
char step;
std::string prefix;
switch (radix) {
case 2 : prefix = "0b"; step = 1; break;
case 8 : prefix = "0o"; step = 3; break;
case 16 : prefix = "0x"; step = 4; break;
default : break;
}
if (_AP_W <= _AP_I)
str = this->to_ap_private().to_string(radix,
radix == 10 ? _AP_S : sign);
else {
if (radix == 10) {
bool isNeg = _AP_S && V.isNegative();
if (_AP_I > 0) {
ap_private<AP_MAX(_AP_I, 1), _AP_S> int_part(0);
int_part = this->to_ap_private();
str += int_part.to_string(radix, false);
} else {
if (isNeg) str += '-';
}
ap_fixed_base<_AP_W, _AP_I, _AP_S> tmp(*this);
if (isNeg && _AP_I <= 0) tmp = -tmp;
ap_fixed_base<_AP_W - AP_MIN(_AP_I, 0), 0, false> frac_part = tmp;
if (frac_part == 0) return str;
str += ".";
while (frac_part != 0) {
char digit = (frac_part * radix).to_ap_private();
str += static_cast<char>(digit + '0');
frac_part *= radix;
}
} else {
if (_AP_I > 0) {
for (signed i = _AP_W - _AP_I; i < _AP_W; i += step) {
char digit = (char)(this->range(AP_MIN(i + step - 1, _AP_W - 1), i));
str = (digit < 10 ? static_cast<char>(digit + '0') :
static_cast<char>(digit - 10 + 'a')) + str;
}
}
str += '.';
ap_fixed_base<AP_MAX(_AP_W - _AP_I, 1), 0, _AP_S> tmp(*this);
for (signed i = _AP_W - _AP_I - 1; i >= 0; i -= step) {
char digit = (char)(tmp.range(i, AP_MAX(0, i - step + 1)));
str += digit < 10 ? static_cast<char>(digit + '0') :
static_cast<char>(digit - 10 + 'a');
}
}
}
str = prefix + str;
return str;
}
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
INLINE void b_not(ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& ret,
const ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op) {
ret.V = op.V;
ret.V.flip();
}
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
INLINE void b_and(ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& ret,
const ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op1,
const ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op2) {
ret.V = op1.V & op2.V;
}
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
INLINE void b_or(ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& ret,
const ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op1,
const ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op2) {
ret.V = op1.V | op2.V;
}
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
INLINE void b_xor(ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& ret,
const ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op1,
const ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op2) {
ret.V = op1.V ^ op2.V;
}
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,
int _AP_N, int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE void neg(ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& ret,
const ap_fixed_base<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op) {
ap_fixed_base<_AP_W2+!_AP_S2, _AP_I2+!_AP_S2, true, _AP_Q2, _AP_O2, _AP_N2> Tmp;
Tmp.V = - op.V;
ret = Tmp;
}
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,
int _AP_N>
INLINE void neg(ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& ret,
const ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op) {
ret.V = -op.V;
}
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,
int _AP_N, int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE void lshift(ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& ret,
const ap_fixed_base<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op,
int i) {
ap_fixed_base<_AP_W2 - _AP_I2 + AP_MAX(_AP_I, _AP_I2), AP_MAX(_AP_I, _AP_I2), _AP_S2, _AP_Q2, _AP_O2, _AP_N2> Tmp;
Tmp = op;
Tmp.V <<= i;
ret = Tmp;
}
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,
int _AP_N>
INLINE void lshift(ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& ret,
const ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op,
int i) {
ret.V = op.V << i;
}
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,
int _AP_N, int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE void rshift(ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& ret,
const ap_fixed_base<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op,
int i) {
ap_fixed_base<_AP_I2 + AP_MAX(_AP_W - _AP_I, _AP_W2 - _AP_I2), _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> Tmp;
Tmp = op;
Tmp.V = _AP_S2 ? Tmp.V.ashr(i): Tmp.V.lshr(i);
ret = Tmp;
}
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,
int _AP_N>
INLINE void rshift(ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& ret,
const ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op,
int i) {
ret.V = _AP_S ? op.V.ashr(i): op.V.lshr(i);
}
#define AF_CTOR_SPEC_BASE(_AP_W,_AP_S,C_TYPE) \
template<> INLINE ap_fixed_base<_AP_W,_AP_W,_AP_S,AP_TRN,AP_WRAP>::ap_fixed_base(C_TYPE i_op):V(i_op) \
{ \
}
#define AF_CTOR_SPEC(__W,C_TYPE) \
AF_CTOR_SPEC_BASE(__W,true,C_TYPE) \
AF_CTOR_SPEC_BASE(__W,false,C_TYPE)
AF_CTOR_SPEC(1,bool)
AF_CTOR_SPEC(8, signed char)
AF_CTOR_SPEC(8, unsigned char)
AF_CTOR_SPEC(16, signed short)
AF_CTOR_SPEC(16, unsigned short)
AF_CTOR_SPEC(32, signed int)
AF_CTOR_SPEC(32, unsigned int)
AF_CTOR_SPEC(64, ap_slong)
AF_CTOR_SPEC(64, ap_ulong)
///Output streaming
//-----------------------------------------------------------------------------
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
INLINE std::ostream&
operator <<(std::ostream& os, const ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& x) {
os << x.to_double();
return os;
}
///Input streaming
//-----------------------------------------------------------------------------
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
INLINE std::istream&
operator >> (std::istream& os, ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& x) {
double d;
os >> d;
x = ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>(x);
return os;
}
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
INLINE void print(const ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& x) {
ap_private<_AP_W,_AP_S> data=x.V;
if (_AP_I>0) {
const ap_private<_AP_I,_AP_S> p1=data>>(_AP_W-_AP_I);
print(p1);
} else
printf("0");
printf(".");
if (_AP_I<_AP_W) {
const ap_private<_AP_W-_AP_I,false> p2=data;
print(p2,false);
}
}
///Operators mixing Integers with ap_fixed_base
//-----------------------------------------------------------------------------
#if 1
#define AF_BIN_OP_WITH_INT_SF(BIN_OP,C_TYPE,_AP_W2,_AP_S2,RTYPE) \
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N> \
INLINE typename ap_fixed_base<_AP_W,_AP_I,_AP_S>::template RType<_AP_W2,_AP_W2,_AP_S2>::RTYPE \
operator BIN_OP (const ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op, C_TYPE i_op) \
{ \
return op.operator BIN_OP(ap_private<_AP_W2,_AP_S2>(i_op)); \
}
#define AF_BIN_OP_WITH_INT(BIN_OP, C_TYPE, _AP_W2,_AP_S2,RTYPE) \
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N> \
INLINE typename ap_fixed_base<_AP_W,_AP_I,_AP_S>::template RType<_AP_W2,_AP_W2,_AP_S2>::RTYPE \
operator BIN_OP (const ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op, C_TYPE i_op) \
{ \
return op.operator BIN_OP (ap_fixed_base<_AP_W2,_AP_W2,_AP_S2>(i_op)); \
} \
\
template<int _AP_W, int _AP_I, bool _AP_S,ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N > \
INLINE typename ap_fixed_base<_AP_W,_AP_I,_AP_S>::template RType<_AP_W2,_AP_W2,_AP_S2>::RTYPE \
operator BIN_OP (C_TYPE i_op, const ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op) \
{ \
return ap_fixed_base<_AP_W2,_AP_W2,_AP_S2>(i_op).operator BIN_OP (op); \
}
#else
#define AF_BIN_OP_WITH_INT_SF(BIN_OP,C_TYPE,_AP_W2,_AP_S2,RTYPE) \
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N> \
INLINE typename ap_fixed_base<_AP_W,_AP_I,_AP_S>::template RType<_AP_W2,_AP_W2,_AP_S2>::RTYPE \
operator BIN_OP (const ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op, C_TYPE i_op) \
{ \
return op BIN_OP (i_op); \
}
#define AF_BIN_OP_WITH_INT(BIN_OP, C_TYPE, _AP_W2,_AP_S2,RTYPE) \
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N> \
INLINE typename ap_fixed_base<_AP_W,_AP_I,_AP_S>::template RType<_AP_W2,_AP_W2,_AP_S2>::RTYPE \
operator BIN_OP (const ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op, C_TYPE i_op) \
{ \
return op.V BIN_OP (i_op<<(_AP_W-_AP_I)); \
} \
\
\
template<int _AP_W, int _AP_I, bool _AP_S,ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N > \
INLINE typename ap_fixed_base<_AP_W,_AP_I,_AP_S>::template RType<_AP_W2,_AP_W2,_AP_S2>::RTYPE \
operator BIN_OP (C_TYPE i_op, const ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op) \
{ \
return ap_fixed_base<_AP_W2,_AP_W2,_AP_S2>(i_op).operator BIN_OP (op); \
}
#endif
#if 1
#define AF_REL_OP_WITH_INT(REL_OP, C_TYPE, _AP_W2,_AP_S2) \
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N> \
INLINE bool operator REL_OP (const ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op, C_TYPE i_op) \
{ \
return op.operator REL_OP (ap_fixed_base<_AP_W2,_AP_W2,_AP_S2>(i_op)); \
} \
\
\
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N> \
INLINE bool operator REL_OP (C_TYPE i_op, const ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op) \
{ \
return ap_fixed_base<_AP_W2,_AP_W2,_AP_S2>(i_op).operator REL_OP (op); \
}
#else
#define AF_REL_OP_WITH_INT(REL_OP, C_TYPE, _AP_W2,_AP_S2) \
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N> \
INLINE bool operator REL_OP (const ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op, C_TYPE i_op) \
{ \
return op.V.operator REL_OP (i_op<<(_AP_W-_AP_I)); \
} \
\
\
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N> \
INLINE bool operator REL_OP (C_TYPE i_op, const ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op) \
{ \
return (i_op<<(_AP_W-_AP_I)) REL_OP (op.V.VAL); \
}
#endif
#if 1
#define AF_ASSIGN_OP_WITH_INT(ASSIGN_OP, C_TYPE, _AP_W2, _AP_S2) \
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N> \
INLINE ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& operator ASSIGN_OP ( ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op, C_TYPE i_op) { \
return op.operator ASSIGN_OP (ap_fixed_base<_AP_W2,_AP_W2,_AP_S2>(i_op)); \
}
#define AF_ASSIGN_OP_WITH_INT_SF(ASSIGN_OP, C_TYPE, _AP_W2, _AP_S2) \
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N> \
INLINE ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& operator ASSIGN_OP ( ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op, C_TYPE i_op) { \
return op.operator ASSIGN_OP (ap_private<_AP_W2,_AP_S2>(i_op)); \
}
#else
#define AF_ASSIGN_OP_WITH_INT(ASSIGN_OP, C_TYPE, _AP_W2, _AP_S2) \
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N> \
INLINE ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& operator ASSIGN_OP ( ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op, C_TYPE i_op) { \
return op.V.operator ASSIGN_OP (i_op); \
}
#define AF_ASSIGN_OP_WITH_INT_SF(ASSIGN_OP, C_TYPE, _AP_W2, _AP_S2) \
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N> \
INLINE ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& operator ASSIGN_OP ( ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op, C_TYPE i_op) { \
return op.V.operator ASSIGN_OP (i_op); \
}
#endif
#define AF_OPS_WITH_INT(C_TYPE, WI, SI) \
AF_BIN_OP_WITH_INT(+, C_TYPE, WI, SI, plus) \
AF_BIN_OP_WITH_INT(-, C_TYPE, WI, SI, minus) \
AF_BIN_OP_WITH_INT(*, C_TYPE, WI, SI, mult) \
AF_BIN_OP_WITH_INT(/, C_TYPE, WI, SI, div) \
AF_BIN_OP_WITH_INT_SF(>>, C_TYPE, WI, SI, arg1) \
AF_BIN_OP_WITH_INT_SF(<<, C_TYPE, WI, SI, arg1) \
AF_BIN_OP_WITH_INT(&, C_TYPE, WI, SI, logic) \
AF_BIN_OP_WITH_INT(|, C_TYPE, WI, SI, logic) \
AF_BIN_OP_WITH_INT(^, C_TYPE, WI, SI, logic) \
\
AF_REL_OP_WITH_INT(==, C_TYPE, WI, SI) \
AF_REL_OP_WITH_INT(!=, C_TYPE, WI, SI) \
AF_REL_OP_WITH_INT(>, C_TYPE, WI, SI) \
AF_REL_OP_WITH_INT(>=, C_TYPE, WI, SI) \
AF_REL_OP_WITH_INT(<, C_TYPE, WI, SI) \
AF_REL_OP_WITH_INT(<=, C_TYPE, WI, SI) \
\
AF_ASSIGN_OP_WITH_INT(+=, C_TYPE, WI, SI) \
AF_ASSIGN_OP_WITH_INT(-=, C_TYPE, WI, SI) \
AF_ASSIGN_OP_WITH_INT(*=, C_TYPE, WI, SI) \
AF_ASSIGN_OP_WITH_INT(/=, C_TYPE, WI, SI) \
AF_ASSIGN_OP_WITH_INT_SF(>>=, C_TYPE, WI, SI) \
AF_ASSIGN_OP_WITH_INT_SF(<<=, C_TYPE, WI, SI) \
AF_ASSIGN_OP_WITH_INT(&=, C_TYPE, WI, SI) \
AF_ASSIGN_OP_WITH_INT(|=, C_TYPE, WI, SI) \
AF_ASSIGN_OP_WITH_INT(^=, C_TYPE, WI, SI)
AF_OPS_WITH_INT(bool, 1, false)
AF_OPS_WITH_INT(char, 8, true)
AF_OPS_WITH_INT(signed char, 8, true)
AF_OPS_WITH_INT(unsigned char, 8, false)
AF_OPS_WITH_INT(short, 16, true)
AF_OPS_WITH_INT(unsigned short, 16, false)
AF_OPS_WITH_INT(int, 32, true)
AF_OPS_WITH_INT(unsigned int, 32, false)
# if defined __x86_64__
AF_OPS_WITH_INT(long, 64, true)
AF_OPS_WITH_INT(unsigned long, 64, false)
# else
AF_OPS_WITH_INT(long, 32, true)
AF_OPS_WITH_INT(unsigned long, 32, false)
# endif
AF_OPS_WITH_INT(ap_slong, 64, true)
AF_OPS_WITH_INT(ap_ulong, 64, false)
#define AF_BIN_OP_WITH_AP_INT(BIN_OP, RTYPE) \
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,int _AP_N, int _AP_W2, bool _AP_S2> \
INLINE typename ap_fixed_base<_AP_W2,_AP_W2,_AP_S2>::template RType<_AP_W,_AP_I,_AP_S>::RTYPE \
operator BIN_OP ( const ap_private<_AP_W2,_AP_S2>& i_op, const ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op) { \
return ap_fixed_base<_AP_W2,_AP_W2,_AP_S2>(i_op).operator BIN_OP (op); \
} \
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,int _AP_N, int _AP_W2, bool _AP_S2> \
INLINE typename ap_fixed_base<_AP_W,_AP_I,_AP_S>::template RType<_AP_W2,_AP_W2,_AP_S2>::RTYPE \
operator BIN_OP ( const ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op, const ap_private<_AP_W2,_AP_S2>& i_op) { \
return op.operator BIN_OP (ap_fixed_base<_AP_W2,_AP_W2,_AP_S2>(i_op)); \
}
#define AF_REL_OP_WITH_AP_INT(REL_OP) \
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,int _AP_N, int _AP_W2, bool _AP_S2> \
INLINE bool operator REL_OP ( const ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op, const ap_private<_AP_W2,_AP_S2>& i_op) { \
return op.operator REL_OP ( ap_fixed_base<_AP_W2,_AP_W2,_AP_S2>(i_op)); \
} \
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,int _AP_N, int _AP_W2, bool _AP_S2> \
INLINE bool operator REL_OP ( const ap_private<_AP_W2,_AP_S2>& i_op, const ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op) { \
return ap_fixed_base<_AP_W2,_AP_W2,_AP_S2>(i_op).operator REL_OP (op); \
}
#define AF_ASSIGN_OP_WITH_AP_INT(ASSIGN_OP) \
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,int _AP_N, int _AP_W2, bool _AP_S2> \
INLINE ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& operator ASSIGN_OP ( ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op, const ap_private<_AP_W2,_AP_S2>& i_op) { \
return op.operator ASSIGN_OP (ap_fixed_base<_AP_W2,_AP_W2,_AP_S2>(i_op)); \
} \
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,int _AP_N, int _AP_W2, bool _AP_S2> \
INLINE ap_private<_AP_W2,_AP_S2>& operator ASSIGN_OP ( ap_private<_AP_W2,_AP_S2>& i_op, const ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op) { \
return i_op.operator ASSIGN_OP (op.to_ap_private()); \
}
AF_BIN_OP_WITH_AP_INT(+, plus)
AF_BIN_OP_WITH_AP_INT(-, minus)
AF_BIN_OP_WITH_AP_INT(*, mult)
AF_BIN_OP_WITH_AP_INT(/, div)
AF_BIN_OP_WITH_AP_INT(&, logic)
AF_BIN_OP_WITH_AP_INT(|, logic)
AF_BIN_OP_WITH_AP_INT(^, logic)
AF_REL_OP_WITH_AP_INT(==)
AF_REL_OP_WITH_AP_INT(!=)
AF_REL_OP_WITH_AP_INT(>)
AF_REL_OP_WITH_AP_INT(>=)
AF_REL_OP_WITH_AP_INT(<)
AF_REL_OP_WITH_AP_INT(<=)
AF_ASSIGN_OP_WITH_AP_INT(+=)
AF_ASSIGN_OP_WITH_AP_INT(-=)
AF_ASSIGN_OP_WITH_AP_INT(*=)
AF_ASSIGN_OP_WITH_AP_INT(/=)
AF_ASSIGN_OP_WITH_AP_INT(&=)
AF_ASSIGN_OP_WITH_AP_INT(|=)
AF_ASSIGN_OP_WITH_AP_INT(^=)
#define AF_REF_REL_OP_MIX_INT(REL_OP, C_TYPE, _AP_W2, _AP_S2) \
template<int _AP_W, int _AP_I, bool _AP_S, \
ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N> \
INLINE bool operator REL_OP ( const af_range_ref<_AP_W,_AP_I, _AP_S, _AP_Q, _AP_O, _AP_N> &op, C_TYPE op2) { \
return (ap_private<_AP_W, false>(op)).operator REL_OP (ap_private<_AP_W2,_AP_S2>(op2)); \
} \
template<int _AP_W, int _AP_I, bool _AP_S, \
ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N> \
INLINE bool operator REL_OP ( C_TYPE op2, const af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N> &op) { \
return ap_private<_AP_W2,_AP_S2>(op2).operator REL_OP (ap_private<_AP_W, false>(op)); \
} \
template<int _AP_W, int _AP_I, bool _AP_S, \
ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N> \
INLINE bool operator REL_OP ( const af_bit_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N> &op, C_TYPE op2) { \
return (bool(op)) REL_OP op2; \
} \
template<int _AP_W, int _AP_I, bool _AP_S, \
ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N> \
INLINE bool operator REL_OP ( C_TYPE op2, const af_bit_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N> &op) { \
return op2 REL_OP (bool(op)); \
}
#define AF_REF_REL_MIX_INT(C_TYPE, _AP_WI, _AP_SI) \
AF_REF_REL_OP_MIX_INT(>, C_TYPE, _AP_WI, _AP_SI) \
AF_REF_REL_OP_MIX_INT(<, C_TYPE, _AP_WI, _AP_SI) \
AF_REF_REL_OP_MIX_INT(>=, C_TYPE, _AP_WI, _AP_SI) \
AF_REF_REL_OP_MIX_INT(<=, C_TYPE, _AP_WI, _AP_SI) \
AF_REF_REL_OP_MIX_INT(==, C_TYPE, _AP_WI, _AP_SI) \
AF_REF_REL_OP_MIX_INT(!=, C_TYPE, _AP_WI, _AP_SI)
AF_REF_REL_MIX_INT(bool, 1, false)
AF_REF_REL_MIX_INT(char, 8, true)
AF_REF_REL_MIX_INT(signed char, 8, true)
AF_REF_REL_MIX_INT(unsigned char, 8, false)
AF_REF_REL_MIX_INT(short, 16, true)
AF_REF_REL_MIX_INT(unsigned short, 16, false)
AF_REF_REL_MIX_INT(int, 32, true)
AF_REF_REL_MIX_INT(unsigned int, 32, false)
# if defined __x86_64__
AF_REF_REL_MIX_INT(long, 64, true)
AF_REF_REL_MIX_INT(unsigned long, 64, false)
# else
AF_REF_REL_MIX_INT(long, 32, true)
AF_REF_REL_MIX_INT(unsigned long, 32, false)
# endif
AF_REF_REL_MIX_INT(ap_slong, 64, true)
AF_REF_REL_MIX_INT(ap_ulong, 64, false)
#define AF_REF_REL_OP_AP_INT(REL_OP) \
template<int _AP_W, int _AP_I, bool _AP_S, \
ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N, int _AP_W2, bool _AP_S2> \
INLINE bool operator REL_OP ( const af_range_ref<_AP_W,_AP_I, _AP_S, _AP_Q, _AP_O, _AP_N> &op, const ap_private<_AP_W2, _AP_S> &op2) { \
return (ap_private<_AP_W, false>(op)).operator REL_OP (op2); \
} \
template<int _AP_W, int _AP_I, bool _AP_S, \
ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N, int _AP_W2, bool _AP_S2> \
INLINE bool operator REL_OP (const ap_private<_AP_W2, _AP_S2> &op2, const af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N> &op) { \
return op2.operator REL_OP (ap_private<_AP_W, false>(op)); \
} \
template<int _AP_W, int _AP_I, bool _AP_S, \
ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N, int _AP_W2, bool _AP_S2> \
INLINE bool operator REL_OP ( const af_bit_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N> &op, const ap_private<_AP_W2, _AP_S2> &op2) { \
return (ap_private<1, false>(op)).operator REL_OP (op2); \
} \
template<int _AP_W, int _AP_I, bool _AP_S, \
ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N, int _AP_W2, bool _AP_S2> \
INLINE bool operator REL_OP ( const ap_private<_AP_W2, _AP_S2> &op2, const af_bit_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N> &op) { \
return op2.operator REL_OP (ap_private<1,false>(op)); \
}
AF_REF_REL_OP_AP_INT(>)
AF_REF_REL_OP_AP_INT(<)
AF_REF_REL_OP_AP_INT(>=)
AF_REF_REL_OP_AP_INT(<=)
AF_REF_REL_OP_AP_INT(==)
AF_REF_REL_OP_AP_INT(!=)
// Relational Operators with double
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
INLINE bool operator == ( double op1, const ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op2) {
return op2.operator == (op1);
}
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
INLINE bool operator != ( double op1, const ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op2) {
return op2.operator != (op1);
}
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
INLINE bool operator > ( double op1, const ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op2) {
return op2.operator < (op1);
}
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
INLINE bool operator >= ( double op1, const ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op2) {
return op2.operator <= (op1);
}
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
INLINE bool operator < ( double op1, const ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op2) {
return op2.operator > (op1);
}
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
INLINE bool operator <= ( double op1, const ap_fixed_base<_AP_W,_AP_I,_AP_S,_AP_Q,_AP_O, _AP_N>& op2) {
return op2.operator >= (op1);
}
#endif /* #ifndef __AESL_GCC_AP_FIXED_H__ */
\ No newline at end of file
/*
* Copyright 2012 Xilinx, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __AESL_GCC_AP_INT_H__
#define __AESL_GCC_AP_INT_H__
#ifndef __cplusplus
#error C++ is required to include this header file
#endif /* #ifndef __cplusplus */
#undef _AP_DEBUG_
#include <stdio.h>
#include <iostream>
// for safety
#if (defined(_AP_N)|| defined(_AP_C))
#error One or more of the following is defined: _AP_N, _AP_C. Definition conflicts with their usage as template parameters.
#endif /* #if (defined(_AP_N)|| defined(_AP_C)) */
// for safety
#if (defined(_AP_W) || defined(_AP_I) || defined(_AP_S) || defined(_AP_Q) || defined(_AP_O) || defined(_AP_W2) || defined(_AP_I2) || defined(_AP_S2) || defined(_AP_Q2) || defined(_AP_O2))
#error One or more of the following is defined: _AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2. Definition conflicts with their usage as template parameters.
#endif /* #if (defined(_AP_W) || defined(_AP_I) || defined(_AP_S) || defined(_AP_Q) || defined(_AP_O) || defined(_AP_W2) || defined(_AP_I2) || defined(_AP_S2) || defined(_AP_Q2) || defined(_AP_O2)) */
//for safety
#if (defined(_AP_W3) || defined(_AP_S3) || defined(_AP_W4) || defined(_AP_S4))
#error One or more of the following is defined: _AP_W3, _AP_S3, _AP_W4,_AP_S4. Definition conflicts with their usage as template parameters.
#endif /* #if (defined(_AP_W3) || defined(_AP_S3) || defined(_AP_W4) || defined(_AP_S4)) */
//for safety
#if (defined(_AP_W1) || defined(_AP_S1) || defined(_AP_I1) || defined(_AP_T) || defined(_AP_T1) || defined(_AP_T2) || defined(_AP_T3) || defined(_AP_T4))
#error One or more of the following is defined: _AP_W1, _AP_S1, _AP_I1, _AP_T, _AP_T1, _AP_T2, _AP_T3, _AP_T4. Definition conflicts with their usage as template parameters.
#endif /* #if (defined(_AP_W1) || defined(_AP_S1) || defined(_AP_I1) || defined(_AP_T) || defined(_AP_T1) || defined(_AP_T2) || defined(_AP_T3) || defined(_AP_T4)) */
#define __AESL_APDT_IN_SCFLOW__
#ifndef __AESL_APDT_IN_SCFLOW__
#include "etc/ap_private.h"
#else
#include "../etc/ap_private.h"
#endif /* #ifndef __AESL_APDT_IN_SCFLOW__ */
#ifdef _AP_DEBUG_
#define AP_DEBUG(s) s
#else
#define AP_DEBUG(s)
#endif /* #ifdef _AP_DEBUG_ */
#ifndef __SIMULATION__
#define __SIMULATION__
#endif /* #ifndef __SIMULATION__ */
#if !(defined SYSTEMC_H) && !(defined SYSTEMC_INCLUDED)
#ifndef SC_TRN
#define SC_TRN AP_TRN
#endif /* #ifndef SC_TRN */
#ifndef SC_RND
#define SC_RND AP_RND
#endif /* #ifndef SC_RND */
#ifndef SC_TRN_ZERO
#define SC_TRN_ZERO AP_TRN_ZERO
#endif /* #ifndef SC_TRN_ZERO */
#ifndef SC_RND_ZERO
#define SC_RND_ZERO AP_RND_ZERO
#endif /* #ifndef SC_RND_ZERO */
#ifndef SC_RND_INF
#define SC_RND_INF AP_RND_INF
#endif /* #ifndef SC_RND_INF */
#ifndef SC_RND_MIN_INF
#define SC_RND_MIN_INF AP_RND_MIN_INF
#endif /* #ifndef SC_RND_MIN_INF */
#ifndef SC_RND_CONV
#define SC_RND_CONV AP_RND_CONV
#endif /* #ifndef SC_RND_CONV */
#ifndef SC_WRAP
#define SC_WRAP AP_WRAP
#endif /* #ifndef SC_WRAP */
#ifndef SC_SAT
#define SC_SAT AP_SAT
#endif /* #ifndef SC_SAT */
#ifndef SC_SAT_ZERO
#define SC_SAT_ZERO AP_SAT_ZERO
#endif /* #ifndef SC_SAT_ZERO */
#ifndef SC_SAT_SYM
#define SC_SAT_SYM AP_SAT_SYM
#endif /* #ifndef SC_SAT_SYM */
#ifndef SC_WRAP_SM
#define SC_WRAP_SM AP_WRAP_SM
#endif /* #ifndef SC_WRAP_SM */
#ifndef SC_BIN
#define SC_BIN AP_BIN
#endif /* #ifndef SC_BIN */
#ifndef SC_OCT
#define SC_OCT AP_OCT
#endif /* #ifndef SC_OCT */
#ifndef SC_DEC
#define SC_DEC AP_DEC
#endif /* #ifndef SC_DEC */
#ifndef SC_HEX
#define SC_HEX AP_HEX
#endif /* #ifndef SC_HEX */
#endif /* #if !(defined SYSTEMC_H) && !(defined SYSTEMC_INCLUDED) */
#ifndef AP_INT_MAX_W
#define AP_INT_MAX_W 1024
#endif
#define BIT_WIDTH_UPPER_LIMIT (1 << 15)
#if AP_INT_MAX_W > BIT_WIDTH_UPPER_LIMIT
#error "Bitwidth exceeds 32768 (1 << 15), the maximum allowed value"
#endif
#define MAX_MODE(BITS) ((BITS + 1023) / 1024)
///Forward declaration
template<int _AP_W, bool _AP_S> struct ap_range_ref;
template<int _AP_W, bool _AP_S> struct ap_bit_ref;
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q,
ap_o_mode _AP_O, int _AP_N> struct ap_fixed_base;
template<int _AP_W, int _AP_I, bool _AP_S,
ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N> struct af_range_ref;
template<int _AP_W, int _AP_I, bool _AP_S,
ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N> struct af_bit_ref;
template<int _AP_W> class ap_uint;
enum {
AP_BIN = 2,
AP_OCT = 8,
AP_DEC = 10,
AP_HEX = 16
};
///Why to use reference?
///Because we will operate the original object indirectly by operating the
///result object directly after concating or part selecting
///Proxy class which allows concatination to be used as rvalue(for reading) and
//lvalue(for writing)
/// Concatination reference.
// ----------------------------------------------------------------
template<int _AP_W1, typename _AP_T1, int _AP_W2, typename _AP_T2>
struct ap_concat_ref {
#ifdef _MSC_VER
#pragma warning(disable: 4521 4522)
#endif /* #ifdef _MSC_VER */
enum {_AP_WR=_AP_W1+_AP_W2,};
_AP_T1& mbv1;
_AP_T2& mbv2;
INLINE ap_concat_ref(const ap_concat_ref<_AP_W1, _AP_T1,
_AP_W2, _AP_T2>& ref):
mbv1(ref.mbv1), mbv2(ref.mbv2) {}
INLINE ap_concat_ref(_AP_T1& bv1, _AP_T2& bv2):mbv1(bv1),mbv2(bv2) {}
template <int _AP_W3, bool _AP_S3>
INLINE ap_concat_ref& operator = (const ap_private<_AP_W3,_AP_S3>& val) {
ap_private<_AP_W1+_AP_W2, false> vval(val);
int W_ref1=mbv1.length();
int W_ref2=mbv2.length();
ap_private<_AP_W1,false> mask1(-1);
mask1>>=_AP_W1-W_ref1;
ap_private<_AP_W2,false> mask2(-1);
mask2>>=_AP_W2-W_ref2;
mbv1.set(ap_private<_AP_W1,false>((vval>>W_ref2)&mask1));
mbv2.set(ap_private<_AP_W2,false>(vval&mask2));
return *this;
}
INLINE ap_concat_ref& operator = (unsigned long long val) {
ap_private<_AP_W1+_AP_W2, false> tmpVal(val);
return operator = (tmpVal);
}
template<int _AP_W3, typename _AP_T3, int _AP_W4, typename _AP_T4>
INLINE ap_concat_ref& operator =
(const ap_concat_ref <_AP_W3, _AP_T3, _AP_W4, _AP_T4>& val) {
ap_private<_AP_W1+_AP_W2, false> tmpVal(val);
return operator = (tmpVal);
}
INLINE ap_concat_ref& operator =
(const ap_concat_ref <_AP_W1, _AP_T1, _AP_W2, _AP_T2>& val) {
ap_private<_AP_W1+_AP_W2, false> tmpVal(val);
return operator = (tmpVal);
}
template <int _AP_W3, bool _AP_S3>
INLINE ap_concat_ref& operator =(const ap_bit_ref<_AP_W3, _AP_S3>& val) {
ap_private<_AP_W1+_AP_W2, false> tmpVal(val);
return operator = (tmpVal);
}
template <int _AP_W3, bool _AP_S3>
INLINE ap_concat_ref& operator =(const ap_range_ref<_AP_W3,_AP_S3>& val) {
ap_private<_AP_W1+_AP_W2, false> tmpVal(val);
return operator =(tmpVal);
}
template<int _AP_W3, int _AP_I3, bool _AP_S3,
ap_q_mode _AP_Q3, ap_o_mode _AP_O3, int _AP_N3>
INLINE ap_concat_ref& operator= (const af_range_ref<_AP_W3, _AP_I3, _AP_S3,
_AP_Q3, _AP_O3, _AP_N3>& val) {
return operator = ((const ap_private<_AP_W3, false>)(val));
}
template<int _AP_W3, int _AP_I3, bool _AP_S3,
ap_q_mode _AP_Q3, ap_o_mode _AP_O3, int _AP_N3>
INLINE ap_concat_ref& operator= (const ap_fixed_base<_AP_W3, _AP_I3, _AP_S3,
_AP_Q3, _AP_O3, _AP_N3>& val) {
return operator = (val.to_ap_private());
}
template<int _AP_W3, int _AP_I3, bool _AP_S3,
ap_q_mode _AP_Q3, ap_o_mode _AP_O3, int _AP_N3>
INLINE ap_concat_ref& operator= (const af_bit_ref<_AP_W3, _AP_I3, _AP_S3,
_AP_Q3, _AP_O3, _AP_N3>& val) {
return operator=((unsigned long long)(bool)(val));
}
INLINE operator ap_private<_AP_WR, false> () const {
return get();
}
INLINE operator unsigned long long () const {
return get().to_uint64();
}
template<int _AP_W3, bool _AP_S3>
INLINE ap_concat_ref<_AP_WR, ap_concat_ref, _AP_W3, ap_range_ref<_AP_W3, _AP_S3> >
operator, (const ap_range_ref<_AP_W3, _AP_S3> &a2) {
return ap_concat_ref<_AP_WR, ap_concat_ref,
_AP_W3, ap_range_ref<_AP_W3, _AP_S3> >(*this,
const_cast<ap_range_ref<_AP_W3, _AP_S3> &>(a2));
}
template<int _AP_W3, bool _AP_S3>
INLINE ap_concat_ref<_AP_WR, ap_concat_ref, _AP_W3, ap_private<_AP_W3, _AP_S3> >
operator, (ap_private<_AP_W3, _AP_S3> &a2) {
return ap_concat_ref<_AP_WR, ap_concat_ref,
_AP_W3, ap_private<_AP_W3, _AP_S3> >(*this, a2);
}
template<int _AP_W3, bool _AP_S3>
INLINE ap_concat_ref<_AP_WR, ap_concat_ref, _AP_W3, ap_private<_AP_W3, _AP_S3> >
operator, (const ap_private<_AP_W3, _AP_S3> &a2) {
return ap_concat_ref<_AP_WR, ap_concat_ref,
_AP_W3, ap_private<_AP_W3, _AP_S3> >(*this,
const_cast<ap_private<_AP_W3, _AP_S3>&>(a2));
}
template<int _AP_W3, bool _AP_S3>
INLINE ap_concat_ref<_AP_WR, ap_concat_ref, 1, ap_bit_ref<_AP_W3, _AP_S3> >
operator, (const ap_bit_ref<_AP_W3, _AP_S3> &a2) {
return ap_concat_ref<_AP_WR, ap_concat_ref,
1, ap_bit_ref<_AP_W3, _AP_S3> >(*this,
const_cast<ap_bit_ref<_AP_W3, _AP_S3> &>(a2));
}
template<int _AP_W3, typename _AP_T3, int _AP_W4, typename _AP_T4>
INLINE ap_concat_ref<_AP_WR, ap_concat_ref, _AP_W3+_AP_W4, ap_concat_ref<_AP_W3,_AP_T3,_AP_W4,_AP_T4> >
operator, (const ap_concat_ref<_AP_W3,_AP_T3,_AP_W4,_AP_T4> &a2)
{
return ap_concat_ref<_AP_WR, ap_concat_ref,
_AP_W3+_AP_W4, ap_concat_ref<_AP_W3,_AP_T3,_AP_W4,
_AP_T4> >(*this, const_cast<ap_concat_ref<_AP_W3,
_AP_T3,_AP_W4, _AP_T4>& >(a2));
}
template <int _AP_W3, int _AP_I3, bool _AP_S3, ap_q_mode _AP_Q3, ap_o_mode _AP_O3, int _AP_N3>
INLINE
ap_concat_ref<_AP_WR, ap_concat_ref, _AP_W3, af_range_ref<_AP_W3, _AP_I3, _AP_S3, _AP_Q3, _AP_O3, _AP_N3> >
operator, (const af_range_ref<_AP_W3, _AP_I3, _AP_S3, _AP_Q3,
_AP_O3, _AP_N3> &a2) {
return ap_concat_ref<_AP_WR, ap_concat_ref, _AP_W3, af_range_ref<_AP_W3,
_AP_I3, _AP_S3, _AP_Q3, _AP_O3, _AP_N3> >(*this,
const_cast<af_range_ref<_AP_W3,_AP_I3, _AP_S3, _AP_Q3,
_AP_O3, _AP_N3>& >(a2));
}
template <int _AP_W3, int _AP_I3, bool _AP_S3, ap_q_mode _AP_Q3, ap_o_mode _AP_O3, int _AP_N3>
INLINE
ap_concat_ref<_AP_WR, ap_concat_ref, 1, af_bit_ref<_AP_W3, _AP_I3, _AP_S3, _AP_Q3, _AP_O3, _AP_N3> >
operator, (const af_bit_ref<_AP_W3, _AP_I3, _AP_S3, _AP_Q3,
_AP_O3, _AP_N3> &a2) {
return ap_concat_ref<_AP_WR, ap_concat_ref, 1, af_bit_ref<_AP_W3,
_AP_I3, _AP_S3, _AP_Q3, _AP_O3, _AP_N3> >(*this,
const_cast<af_bit_ref<_AP_W3,_AP_I3, _AP_S3,
_AP_Q3, _AP_O3, _AP_N3>& >(a2));
}
template<int _AP_W3, bool _AP_S3>
INLINE ap_private<AP_MAX(_AP_WR,_AP_W3), _AP_S3>
operator & (const ap_private<_AP_W3,_AP_S3>& a2) {
return get() & a2;
}
template<int _AP_W3, bool _AP_S3>
INLINE ap_private<AP_MAX(_AP_WR,_AP_W3), _AP_S3>
operator | (const ap_private<_AP_W3,_AP_S3>& a2) {
return get() | a2;
}
template<int _AP_W3, bool _AP_S3>
INLINE ap_private<AP_MAX(_AP_WR,_AP_W3), _AP_S3>
operator ^ (const ap_private<_AP_W3,_AP_S3>& a2) {
return ap_private<AP_MAX(_AP_WR,_AP_W3), _AP_S3>(get() ^ a2);
}
INLINE const ap_private<_AP_WR, false> get() const
{
ap_private<_AP_W1+_AP_W2, false> tmpVal = ap_private<_AP_W1+_AP_W2, false> (mbv1.get());
ap_private<_AP_W1+_AP_W2, false> tmpVal2 = ap_private<_AP_W1+_AP_W2, false> (mbv2.get());
int W_ref2 = mbv2.length();
tmpVal <<= W_ref2;
tmpVal |= tmpVal2;
return tmpVal;
}
INLINE const ap_private<_AP_WR, false> get() {
ap_private<_AP_W1+_AP_W2, false> tmpVal = ap_private<_AP_W1+_AP_W2, false> ( mbv1.get());
ap_private<_AP_W1+_AP_W2, false> tmpVal2 = ap_private<_AP_W1+_AP_W2, false> (mbv2.get());
int W_ref2 = mbv2.length();
tmpVal <<= W_ref2;
tmpVal |= tmpVal2;
return tmpVal;
}
template <int _AP_W3>
INLINE void set(const ap_private<_AP_W3,false> & val) {
ap_private<_AP_W1+_AP_W2, false> vval(val);
int W_ref1=mbv1.length();
int W_ref2=mbv2.length();
ap_private<_AP_W1,false> mask1(-1);
mask1>>=_AP_W1-W_ref1;
ap_private<_AP_W2,false> mask2(-1);
mask2>>=_AP_W2-W_ref2;
mbv1.set(ap_private<_AP_W1,false>((vval>>W_ref2)&mask1));
mbv2.set(ap_private<_AP_W2,false>(vval&mask2));
}
INLINE int length() const {
return mbv1.length()+mbv2.length();
}
INLINE std::string to_string(uint8_t radix=2) const {
return get().to_string(radix);
}
};
///Proxy class, which allows part selection to be used as rvalue(for reading) and
//lvalue(for writing)
///Range(slice) reference
//------------------------------------------------------------
template<int _AP_W, bool _AP_S>
struct ap_range_ref {
#ifdef _MSC_VER
#pragma warning( disable : 4521 4522 )
#endif /* #ifdef _MSC_VER */
ap_private<_AP_W,_AP_S> &d_bv;
int l_index;
int h_index;
public:
INLINE ap_range_ref(const ap_range_ref<_AP_W, _AP_S>& ref):
d_bv(ref.d_bv), l_index(ref.l_index), h_index(ref.h_index) {}
INLINE ap_range_ref(ap_private<_AP_W,_AP_S>* bv, int h, int l):
d_bv(*bv),l_index(l),h_index(h) {
//if (h < l)
//fprintf(stderr, "Warning! The bits selected will be returned in reverse order\n");
}
INLINE operator ap_private<_AP_W, false> () const {
ap_private<_AP_W, false> val(0);
if(h_index>=l_index) {
if (_AP_W > 64) {
val=d_bv;
ap_private<_AP_W,false> mask(-1);
mask>>=_AP_W-(h_index-l_index+1);
val>>=l_index;
val&=mask;
} else {
const static uint64_t mask = (~0ULL>> (64>_AP_W ? (64-_AP_W):0));
val = (d_bv >> l_index) & (mask >>(_AP_W-(h_index-l_index+1)));
}
} else {
for(int i=0, j=l_index;j>=0&&j>=h_index;j--,i++)
if((d_bv)[j]) val.set(i);
}
return val;
}
INLINE operator unsigned long long () const {
return to_uint64();
}
template<int _AP_W2,bool _AP_S2>
INLINE ap_range_ref& operator =(const ap_private<_AP_W2,_AP_S2>& val) {
ap_private<_AP_W,false> vval=ap_private<_AP_W,false>(val);
if (l_index>h_index) {
for (int i=0, j=l_index;j>=0&&j>=h_index;j--,i++)
(vval)[i]? d_bv.set(j):d_bv.clear(j);
} else {
if (_AP_W > 64) {
ap_private<_AP_W,false> mask(-1);
if (l_index>0) {
mask<<=l_index;
vval<<=l_index;
}
if(h_index<_AP_W-1)
{
ap_private<_AP_W,false> mask2(-1);
mask2>>=_AP_W-h_index-1;
mask&=mask2;
vval&=mask2;
}
mask.flip();
d_bv&=mask;
d_bv|=vval;
} else {
unsigned shift = 64-_AP_W;
uint64_t mask = ~0ULL>>(shift);
if(l_index>0)
{
vval = mask & vval << l_index;
mask = mask & mask << l_index;
}
if(h_index<_AP_W-1)
{
uint64_t mask2 = mask;
mask2 >>= (_AP_W-h_index-1);
mask&=mask2;
vval&=mask2;
}
mask = ~mask;
d_bv&=mask;
d_bv|=vval;
}
}
return *this;
}
INLINE ap_range_ref& operator = (unsigned long long val)
{
const ap_private<_AP_W,_AP_S> vval=val;
return operator = (vval);
}
INLINE ap_range_ref& operator =(const ap_range_ref<_AP_W, _AP_S>& val)
{
const ap_private<_AP_W, false> tmpVal(val);
return operator =(tmpVal);
}
template<int _AP_W3, typename _AP_T3, int _AP_W4, typename _AP_T4>
INLINE ap_range_ref& operator =
(const ap_concat_ref <_AP_W3, _AP_T3, _AP_W4, _AP_T4>& val)
{
const ap_private<_AP_W, false> tmpVal(val);
return operator = (tmpVal);
}
template <int _AP_W3, bool _AP_S3>
INLINE ap_range_ref& operator =(const ap_range_ref<_AP_W3,_AP_S3>& val)
{
const ap_private<_AP_W, false> tmpVal(val);
return operator =(tmpVal);
}
template<int _AP_W2, int _AP_I2, bool _AP_S2,
ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_range_ref& operator= (const af_range_ref<_AP_W2, _AP_I2, _AP_S2,
_AP_Q2, _AP_O2, _AP_N2>& val) {
return operator=((const ap_private<_AP_W2, _AP_S2>)(val));
}
template<int _AP_W2, int _AP_I2, bool _AP_S2,
ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_range_ref& operator= (const ap_fixed_base<_AP_W2, _AP_I2, _AP_S2,
_AP_Q2, _AP_O2, _AP_N2>& val) {
return operator=(val.to_ap_private());
}
template<int _AP_W2, int _AP_I2, bool _AP_S2,
ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_range_ref& operator= (const af_bit_ref<_AP_W2, _AP_I2, _AP_S2,
_AP_Q2, _AP_O2, _AP_N2>& val) {
return operator=((unsigned long long)(bool)(val));
}
template<int _AP_W2, bool _AP_S2>
INLINE ap_range_ref& operator= (const ap_bit_ref<_AP_W2, _AP_S2>& val) {
return operator=((unsigned long long)(bool)(val));
}
template <int _AP_W2, bool _AP_S2>
INLINE
ap_concat_ref<_AP_W,ap_range_ref,_AP_W2,ap_range_ref<_AP_W2,_AP_S2> >
operator, (const ap_range_ref<_AP_W2,_AP_S2> &a2)
{
return
ap_concat_ref<_AP_W, ap_range_ref, _AP_W2,
ap_range_ref<_AP_W2,_AP_S2> >(*this,
const_cast<ap_range_ref<_AP_W2,_AP_S2>& >(a2));
}
template <int _AP_W2, bool _AP_S2>
INLINE ap_concat_ref<_AP_W,ap_range_ref,_AP_W2,ap_private<_AP_W2,_AP_S2> >
operator , (ap_private<_AP_W2,_AP_S2>& a2)
{
return
ap_concat_ref<_AP_W, ap_range_ref, _AP_W2, ap_private<_AP_W2,_AP_S2> >(*this, a2);
}
INLINE ap_concat_ref<_AP_W,ap_range_ref,_AP_W,ap_private<_AP_W,_AP_S> >
operator , (ap_private<_AP_W, _AP_S>& a2)
{
return
ap_concat_ref<_AP_W, ap_range_ref, _AP_W,
ap_private<_AP_W,_AP_S> >(*this, a2);
}
template <int _AP_W2, bool _AP_S2>
INLINE
ap_concat_ref<_AP_W,ap_range_ref,1,ap_bit_ref<_AP_W2,_AP_S2> >
operator, (const ap_bit_ref<_AP_W2,_AP_S2> &a2)
{
return
ap_concat_ref<_AP_W, ap_range_ref, 1,
ap_bit_ref<_AP_W2,_AP_S2> >(*this, const_cast<ap_bit_ref<
_AP_W2,_AP_S2>& >(a2));
}
template <int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
INLINE
ap_concat_ref<_AP_W, ap_range_ref, _AP_W2+_AP_W3, ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3> >
operator, (const ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3> &a2)
{
return ap_concat_ref<_AP_W, ap_range_ref, _AP_W2+_AP_W3,
ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3> >(*this,
const_cast<ap_concat_ref<_AP_W2, _AP_T2, _AP_W3,
_AP_T3>& >(a2));
}
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE
ap_concat_ref<_AP_W, ap_range_ref, _AP_W2, af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >
operator, (const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2,
_AP_O2, _AP_N2> &a2) {
return ap_concat_ref<_AP_W, ap_range_ref, _AP_W2, af_range_ref<_AP_W2,
_AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >(*this,
const_cast<af_range_ref<_AP_W2,_AP_I2, _AP_S2,
_AP_Q2, _AP_O2, _AP_N2>& >(a2));
}
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE
ap_concat_ref<_AP_W, ap_range_ref, 1, af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >
operator, (const af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2,
_AP_O2, _AP_N2> &a2) {
return ap_concat_ref<_AP_W, ap_range_ref, 1, af_bit_ref<_AP_W2,
_AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >(*this,
const_cast<af_bit_ref<_AP_W2,_AP_I2, _AP_S2,
_AP_Q2, _AP_O2, _AP_N2>& >(a2));
}
template<int _AP_W2, bool _AP_S2>
INLINE bool operator == (const ap_range_ref<_AP_W2, _AP_S2>& op2)
{
ap_private<_AP_W,false> lhs=get();
ap_private<_AP_W2,false> rhs=op2.get();
return lhs==rhs;
}
template<int _AP_W2, bool _AP_S2>
INLINE bool operator != (const ap_range_ref<_AP_W2, _AP_S2>& op2)
{
ap_private<_AP_W,false> lhs=get();
ap_private<_AP_W2,false> rhs=op2.get();
return lhs!=rhs;
}
template<int _AP_W2, bool _AP_S2>
INLINE bool operator > (const ap_range_ref<_AP_W2, _AP_S2>& op2)
{
ap_private<_AP_W,false> lhs=get();
ap_private<_AP_W2,false> rhs=op2.get();
return lhs>rhs;
}
template<int _AP_W2, bool _AP_S2>
INLINE bool operator >= (const ap_range_ref<_AP_W2, _AP_S2>& op2)
{
ap_private<_AP_W,false> lhs=get();
ap_private<_AP_W2,false> rhs=op2.get();
return lhs>=rhs;
}
template<int _AP_W2, bool _AP_S2>
INLINE bool operator < (const ap_range_ref<_AP_W2, _AP_S2>& op2)
{
ap_private<_AP_W,false> lhs=get();
ap_private<_AP_W2,false> rhs=op2.get();
return lhs<rhs;
}
template<int _AP_W2, bool _AP_S2>
INLINE bool operator <= (const ap_range_ref<_AP_W2, _AP_S2>& op2)
{
ap_private<_AP_W,false> lhs=get();
ap_private<_AP_W2,false> rhs=op2.get();
return lhs<=rhs;
}
template<int _AP_W2>
INLINE void set(const ap_private<_AP_W2,false>& val)
{
ap_private<_AP_W,_AP_S> vval=val;
if(l_index>h_index)
{
for(int i=0, j=l_index;j>=0&&j>=h_index;j--,i++)
(vval)[i]? d_bv.set(j):d_bv.clear(j);
} else {
if (_AP_W>64 ) {
ap_private<_AP_W,_AP_S> mask(-1);
if(l_index>0)
{
ap_private<_AP_W,false> mask1(-1);
mask1>>=_AP_W-l_index;
mask1.flip();
mask=mask1;
//vval&=mask1;
vval<<=l_index;
}
if(h_index<_AP_W-1)
{
ap_private<_AP_W,false> mask2(-1);
mask2<<=h_index+1;
mask2.flip();
mask&=mask2;
vval&=mask2;
}
mask.flip();
d_bv&=mask;
d_bv|=vval;
} else {
uint64_t mask = ~0ULL >> (64-_AP_W);
if(l_index>0)
{
uint64_t mask1 = mask;
mask1=mask & (mask1>>(_AP_W-l_index));
vval =mask&( vval <<l_index);
mask=~mask1&mask;
//vval&=mask1;
}
if(h_index<_AP_W-1) {
uint64_t mask2 = ~0ULL >> (64-_AP_W);
mask2 = mask &(mask2<<(h_index+1));
mask&=~mask2;
vval&=~mask2;
}
d_bv&=(~mask&(~0ULL >> (64-_AP_W)));
d_bv|=vval;
}
}
}
INLINE ap_private<_AP_W,false> get() const
{
ap_private<_AP_W,false> val(0);
if(h_index<l_index) {
for(int i=0, j=l_index;j>=0&&j>=h_index;j--,i++)
if((d_bv)[j]) val.set(i);
} else {
val=d_bv;
val>>=l_index;
if(h_index<_AP_W-1)
{
if (_AP_W <= 64) {
const static uint64_t mask = (~0ULL>> (64>_AP_W ? (64-_AP_W):0));
val &= (mask>> (_AP_W-(h_index-l_index+1)));
} else {
ap_private<_AP_W,false> mask(-1);
mask>>=_AP_W-(h_index-l_index+1);
val&=mask;
}
}
}
return val;
}
INLINE ap_private<_AP_W,false> get()
{
ap_private<_AP_W,false> val(0);
if(h_index<l_index) {
for(int i=0, j=l_index;j>=0&&j>=h_index;j--,i++)
if((d_bv)[j]) val.set(i);
} else {
val=d_bv;
val>>=l_index;
if(h_index<_AP_W-1)
{
if (_AP_W <= 64 ) {
static const uint64_t mask = ~0ULL>> (64>_AP_W ? (64-_AP_W):0);
return val &= ( (mask) >> (_AP_W - (h_index-l_index+1)));
} else {
ap_private<_AP_W,false> mask(-1);
mask>>=_AP_W-(h_index-l_index+1);
val&=mask;
}
}
}
return val;
}
INLINE int length() const
{
return h_index>=l_index?h_index-l_index+1:l_index-h_index+1;
}
INLINE int to_int() const
{
ap_private<_AP_W,false> val=get();
return val.to_int();
}
INLINE unsigned int to_uint() const
{
ap_private<_AP_W,false> val=get();
return val.to_uint();
}
INLINE long to_long() const
{
ap_private<_AP_W,false> val=get();
return val.to_long();
}
INLINE unsigned long to_ulong() const
{
ap_private<_AP_W,false> val=get();
return val.to_ulong();
}
INLINE ap_slong to_int64() const
{
ap_private<_AP_W,false> val=get();
return val.to_int64();
}
INLINE ap_ulong to_uint64() const
{
ap_private<_AP_W,false> val=get();
return val.to_uint64();
}
INLINE std::string to_string(uint8_t radix=2) const {
return get().to_string(radix);
}
};
///Proxy class, which allows bit selection to be used as rvalue(for reading) and
//lvalue(for writing)
///Bit reference
//--------------------------------------------------------------
template <int _AP_W, bool _AP_S>
struct ap_bit_ref {
#ifdef _MSC_VER
#pragma warning( disable : 4521 4522 )
#endif
ap_private<_AP_W,_AP_S>& d_bv;
int d_index;
public:
INLINE ap_bit_ref(const ap_bit_ref<_AP_W, _AP_S>& ref):
d_bv(ref.d_bv), d_index(ref.d_index) {}
INLINE ap_bit_ref(ap_private<_AP_W,_AP_S>& bv, int index=0):
d_bv(bv),d_index(index)
{
#ifdef _AP_DEBUG_
assert(d_index<_AP_W&&"index out of bound");
#endif
}
INLINE operator bool () const
{
return d_bv.get_bit(d_index);
}
INLINE bool to_bool() const
{
return operator bool ();
}
INLINE ap_bit_ref& operator = (unsigned long long val)
{
if(val)
d_bv.set(d_index);
else
d_bv.clear(d_index);
return *this;
}
#if 0
INLINE ap_bit_ref& operator = (bool val)
{
if(val)
d_bv.set(d_index);
else
d_bv.clear(d_index);
return *this;
}
#endif
template<int _AP_W2, bool _AP_S2>
INLINE ap_bit_ref& operator =(const ap_private<_AP_W2,_AP_S2>& val)
{
return operator =((unsigned long long)(val != 0));
}
template<int _AP_W2, bool _AP_S2>
INLINE ap_bit_ref& operator =(const ap_bit_ref<_AP_W2,_AP_S2>& val)
{
return operator =((unsigned long long)(bool)val);
}
INLINE ap_bit_ref& operator =(const ap_bit_ref<_AP_W,_AP_S>& val)
{
return operator =((unsigned long long)(bool)val);
}
template<int _AP_W2, bool _AP_S2>
INLINE ap_bit_ref& operator =(const ap_range_ref<_AP_W2,_AP_S2>& val)
{
return operator =((unsigned long long)(bool) val);
}
template<int _AP_W2, int _AP_I2, bool _AP_S2,
ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_bit_ref& operator= (const af_range_ref<_AP_W2, _AP_I2, _AP_S2,
_AP_Q2, _AP_O2, _AP_N2>& val) {
return operator=((const ap_private<_AP_W2, false>)(val));
}
template<int _AP_W2, int _AP_I2, bool _AP_S2,
ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_bit_ref& operator= (const af_bit_ref<_AP_W2, _AP_I2, _AP_S2,
_AP_Q2, _AP_O2, _AP_N2>& val) {
return operator=((unsigned long long)(bool)(val));
}
template<int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
INLINE ap_bit_ref& operator= (const ap_concat_ref<_AP_W2, _AP_T3, _AP_W3, _AP_T3>& val) {
return operator=((const ap_private<_AP_W2 + _AP_W3, false>)(val));
}
template<int _AP_W2, bool _AP_S2>
INLINE ap_concat_ref<1, ap_bit_ref, _AP_W2, ap_private<_AP_W2,_AP_S2> >
operator , (ap_private<_AP_W2, _AP_S2>& a2)
{
return ap_concat_ref<1, ap_bit_ref, _AP_W2, ap_private<_AP_W2,_AP_S2> >(*this, a2);
}
template<int _AP_W2, bool _AP_S2>
INLINE ap_concat_ref<1, ap_bit_ref, _AP_W2, ap_range_ref<_AP_W2,_AP_S2> >
operator, (const ap_range_ref<_AP_W2, _AP_S2> &a2)
{
return
ap_concat_ref<1, ap_bit_ref, _AP_W2, ap_range_ref<_AP_W2,_AP_S2> >(*this,
const_cast<ap_range_ref<_AP_W2, _AP_S2> &>(a2));
}
template<int _AP_W2, bool _AP_S2>
INLINE ap_concat_ref<1, ap_bit_ref, 1, ap_bit_ref<_AP_W2,_AP_S2> >
operator, (const ap_bit_ref<_AP_W2, _AP_S2> &a2)
{
return
ap_concat_ref<1, ap_bit_ref, 1, ap_bit_ref<_AP_W2,_AP_S2> >(*this,
const_cast<ap_bit_ref<_AP_W2, _AP_S2> &>(a2));
}
INLINE ap_concat_ref<1, ap_bit_ref, 1, ap_bit_ref >
operator, (const ap_bit_ref &a2)
{
return
ap_concat_ref<1, ap_bit_ref, 1, ap_bit_ref >(*this,
const_cast<ap_bit_ref&>(a2));
}
template<int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
INLINE ap_concat_ref<1, ap_bit_ref, _AP_W2+_AP_W3, ap_concat_ref<_AP_W2,_AP_T2,_AP_W3,_AP_T3> >
operator, (const ap_concat_ref<_AP_W2,_AP_T2,_AP_W3,_AP_T3> &a2)
{
return
ap_concat_ref<1,ap_bit_ref,_AP_W2+_AP_W3,
ap_concat_ref<_AP_W2,_AP_T2,_AP_W3,_AP_T3> >(*this,
const_cast<ap_concat_ref<_AP_W2,_AP_T2,_AP_W3,_AP_T3>& >(a2));
}
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE
ap_concat_ref<1, ap_bit_ref, _AP_W2, af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >
operator, (const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2,
_AP_O2, _AP_N2> &a2) {
return ap_concat_ref<1, ap_bit_ref, _AP_W2, af_range_ref<_AP_W2,
_AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >(*this,
const_cast<af_range_ref<_AP_W2,_AP_I2, _AP_S2, _AP_Q2,
_AP_O2, _AP_N2>& >(a2));
}
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2, int _AP_N2>
INLINE
ap_concat_ref<1, ap_bit_ref, 1, af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >
operator, (const af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2,
_AP_O2, _AP_N2> &a2) {
return ap_concat_ref<1, ap_bit_ref, 1, af_bit_ref<_AP_W2,
_AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >(*this,
const_cast<af_bit_ref<_AP_W2, _AP_I2, _AP_S2,
_AP_Q2, _AP_O2, _AP_N2>& >(a2));
}
template<int _AP_W2, bool _AP_S2>
INLINE bool operator == (const ap_bit_ref<_AP_W2, _AP_S2>& op) {
return get() == op.get();
}
template<int _AP_W2, bool _AP_S2>
INLINE bool operator != (const ap_bit_ref<_AP_W2, _AP_S2>& op) {
return get() != op.get();
}
INLINE bool get() const
{
return operator bool ();
}
INLINE bool get()
{
return operator bool ();
}
template <int _AP_W3>
INLINE void set(const ap_private<_AP_W3, false>& val)
{
operator = (val);
}
INLINE bool operator ~ () const {
bool bit = (d_bv)[d_index];
return bit ? false : true;
}
INLINE int length() const { return 1; }
INLINE std::string to_string() const {
bool val = get();
return val ? "1" : "0";
}
};
/// Operators mixing Integers with AP_Int
// ----------------------------------------------------------------
#if 1
#define OP_BIN_MIX_INT(BIN_OP, C_TYPE, _AP_WI, _AP_SI, RTYPE) \
template<int _AP_W, bool _AP_S> \
INLINE typename ap_private<_AP_WI,_AP_SI>::template RType<_AP_W,_AP_S>::RTYPE \
operator BIN_OP ( C_TYPE i_op, const ap_private<_AP_W,_AP_S> &op) { \
return ap_private<_AP_WI,_AP_SI>(i_op).operator BIN_OP (op); \
} \
template<int _AP_W, bool _AP_S> \
INLINE typename ap_private<_AP_W,_AP_S>::template RType<_AP_WI,_AP_SI>::RTYPE \
operator BIN_OP ( const ap_private<_AP_W,_AP_S> &op, C_TYPE i_op) { \
return op.operator BIN_OP (ap_private<_AP_WI,_AP_SI>(i_op)); \
}
#else
#define OP_BIN_MIX_INT(BIN_OP, C_TYPE, _AP_WI, _AP_SI, RTYPE) \
template<int _AP_W, bool _AP_S> \
INLINE typename ap_private<_AP_WI,_AP_SI>::template RType<_AP_W,_AP_S>::RTYPE \
operator BIN_OP ( C_TYPE i_op, const ap_private<_AP_W,_AP_S> &op) { \
return ap_private<_AP_WI,_AP_SI>(i_op).operator BIN_OP (op); \
} \
template<int _AP_W, bool _AP_S> \
INLINE typename ap_private<_AP_W,_AP_S>::template RType<_AP_WI,_AP_SI>::RTYPE \
operator BIN_OP ( const ap_private<_AP_W,_AP_S> &op, C_TYPE i_op) { \
return op.operator BIN_OP (ap_private<_AP_WI,_AP_SI>(i_op)); \
}
#endif
#define OP_REL_MIX_INT(REL_OP, C_TYPE, _AP_W2, _AP_S2) \
template<int _AP_W, bool _AP_S> \
INLINE bool operator REL_OP ( const ap_private<_AP_W,_AP_S> &op, C_TYPE op2) { \
return op.operator REL_OP (ap_private<_AP_W2, _AP_S2>(op2)); \
} \
template<int _AP_W, bool _AP_S> \
INLINE bool operator REL_OP ( C_TYPE op2, const ap_private<_AP_W,_AP_S> &op) { \
return ap_private<_AP_W2,_AP_S2>(op2).operator REL_OP (op); \
}
#define OP_ASSIGN_MIX_INT(ASSIGN_OP, C_TYPE, _AP_W2, _AP_S2) \
template<int _AP_W, bool _AP_S> \
INLINE ap_private<_AP_W,_AP_S> &operator ASSIGN_OP ( ap_private<_AP_W,_AP_S> &op, C_TYPE op2) { \
return op.operator ASSIGN_OP (ap_private<_AP_W2,_AP_S2>(op2)); \
}
#define OP_BIN_SHIFT_INT(BIN_OP, C_TYPE, _AP_WI, _AP_SI, RTYPE) \
template<int _AP_W, bool _AP_S> \
C_TYPE operator BIN_OP ( C_TYPE i_op, const ap_private<_AP_W,_AP_S> &op) { \
return i_op BIN_OP (op.getVal()); \
} \
template<int _AP_W, bool _AP_S> \
INLINE typename ap_private<_AP_W,_AP_S>::template RType<_AP_WI,_AP_SI>::RTYPE \
operator BIN_OP ( const ap_private<_AP_W,_AP_S> &op, C_TYPE i_op) { \
return op.operator BIN_OP (i_op); \
}
#define OP_ASSIGN_RSHIFT_INT(ASSIGN_OP, C_TYPE, _AP_W2, _AP_S2) \
template<int _AP_W, bool _AP_S> \
INLINE ap_private<_AP_W,_AP_S> &operator ASSIGN_OP ( ap_private<_AP_W,_AP_S> &op, C_TYPE op2) { \
op = op.operator >> (op2); \
return op; \
}
#define OP_ASSIGN_LSHIFT_INT(ASSIGN_OP, C_TYPE, _AP_W2, _AP_S2) \
template<int _AP_W, bool _AP_S> \
INLINE ap_private<_AP_W,_AP_S> &operator ASSIGN_OP ( ap_private<_AP_W,_AP_S> &op, C_TYPE op2) { \
op = op.operator << (op2); \
return op; \
}
#define OPS_MIX_INT(C_TYPE, WI, SI) \
OP_BIN_MIX_INT(*, C_TYPE, WI, SI, mult) \
OP_BIN_MIX_INT(+, C_TYPE, WI, SI, plus) \
OP_BIN_MIX_INT(-, C_TYPE, WI, SI, minus) \
OP_BIN_MIX_INT(/, C_TYPE, WI, SI, div) \
OP_BIN_MIX_INT(%, C_TYPE, WI, SI, mod) \
OP_BIN_MIX_INT(&, C_TYPE, WI, SI, logic) \
OP_BIN_MIX_INT(|, C_TYPE, WI, SI, logic) \
OP_BIN_MIX_INT(^, C_TYPE, WI, SI, logic) \
OP_BIN_SHIFT_INT(>>, C_TYPE, WI, SI, arg1) \
OP_BIN_SHIFT_INT(<<, C_TYPE, WI, SI, arg1) \
\
OP_REL_MIX_INT(==, C_TYPE, WI, SI) \
OP_REL_MIX_INT(!=, C_TYPE, WI, SI) \
OP_REL_MIX_INT(>, C_TYPE, WI, SI) \
OP_REL_MIX_INT(>=, C_TYPE, WI, SI) \
OP_REL_MIX_INT(<, C_TYPE, WI, SI) \
OP_REL_MIX_INT(<=, C_TYPE, WI, SI) \
\
OP_ASSIGN_MIX_INT(+=, C_TYPE, WI, SI) \
OP_ASSIGN_MIX_INT(-=, C_TYPE, WI, SI) \
OP_ASSIGN_MIX_INT(*=, C_TYPE, WI, SI) \
OP_ASSIGN_MIX_INT(/=, C_TYPE, WI, SI) \
OP_ASSIGN_MIX_INT(%=, C_TYPE, WI, SI) \
OP_ASSIGN_MIX_INT(&=, C_TYPE, WI, SI) \
OP_ASSIGN_MIX_INT(|=, C_TYPE, WI, SI) \
OP_ASSIGN_MIX_INT(^=, C_TYPE, WI, SI) \
OP_ASSIGN_RSHIFT_INT(>>=, C_TYPE, WI, SI) \
OP_ASSIGN_LSHIFT_INT(<<=, C_TYPE, WI, SI)
OPS_MIX_INT(bool, 1, false)
OPS_MIX_INT(char, 8, true)
OPS_MIX_INT(signed char, 8, true)
OPS_MIX_INT(unsigned char, 8, false)
OPS_MIX_INT(short, 16, true)
OPS_MIX_INT(unsigned short, 16, false)
OPS_MIX_INT(int, 32, true)
OPS_MIX_INT(unsigned int, 32, false)
# if defined __x86_64__
OPS_MIX_INT(long, 64, true)
OPS_MIX_INT(unsigned long, 64, false)
# else
OPS_MIX_INT(long, 32, true)
OPS_MIX_INT(unsigned long, 32, false)
# endif
OPS_MIX_INT(ap_slong, 64, true)
OPS_MIX_INT(ap_ulong, 64, false)
#define OP_BIN_MIX_RANGE(BIN_OP, RTYPE) \
template<int _AP_W1, bool _AP_S1, int _AP_W2, bool _AP_S2> \
INLINE typename ap_private<_AP_W1,_AP_S1>::template RType<_AP_W2,_AP_S2>::RTYPE \
operator BIN_OP ( const ap_range_ref<_AP_W1,_AP_S1>& op1, const ap_private<_AP_W2,_AP_S2>& op2) { \
return ap_private<_AP_W1, false>(op1).operator BIN_OP (op2); \
} \
template<int _AP_W1, bool _AP_S1, int _AP_W2, bool _AP_S2> \
INLINE typename ap_private<_AP_W1,_AP_S1>::template RType<_AP_W2,_AP_S2>::RTYPE \
operator BIN_OP ( const ap_private<_AP_W1,_AP_S1>& op1, const ap_range_ref<_AP_W2,_AP_S2>& op2) { \
return op1.operator BIN_OP (ap_private<_AP_W2, false>(op2)); \
}
#define OP_REL_MIX_RANGE(REL_OP) \
template<int _AP_W1, bool _AP_S1, int _AP_W2, bool _AP_S2> \
INLINE bool operator REL_OP ( const ap_range_ref<_AP_W1,_AP_S1>& op1, const ap_private<_AP_W2,_AP_S2>& op2) { \
return ap_private<_AP_W1,false>(op1).operator REL_OP (op2); \
} \
template<int _AP_W1, bool _AP_S1, int _AP_W2, bool _AP_S2> \
INLINE bool operator REL_OP ( const ap_private<_AP_W1,_AP_S1>& op1, const ap_range_ref<_AP_W2,_AP_S2>& op2) { \
return op1.operator REL_OP (op2.operator ap_private<_AP_W2, false>()); \
}
#define OP_ASSIGN_MIX_RANGE(ASSIGN_OP) \
template<int _AP_W1, bool _AP_S1, int _AP_W2, bool _AP_S2> \
INLINE ap_private<_AP_W1,_AP_S1>& operator ASSIGN_OP ( ap_private<_AP_W1,_AP_S1>& op1, const ap_range_ref<_AP_W2,_AP_S2>& op2) { \
return op1.operator ASSIGN_OP (ap_private<_AP_W2, false>(op2)); \
} \
template<int _AP_W1, bool _AP_S1, int _AP_W2, bool _AP_S2> \
INLINE ap_range_ref<_AP_W1,_AP_S1>& operator ASSIGN_OP (ap_range_ref<_AP_W1,_AP_S1>& op1, ap_private<_AP_W2,_AP_S2>& op2) { \
ap_private<_AP_W1, false> tmp(op1); \
tmp.operator ASSIGN_OP (op2); \
op1 = tmp; \
return op1; \
}
OP_ASSIGN_MIX_RANGE(+=)
OP_ASSIGN_MIX_RANGE(-=)
OP_ASSIGN_MIX_RANGE(*=)
OP_ASSIGN_MIX_RANGE(/=)
OP_ASSIGN_MIX_RANGE(%=)
OP_ASSIGN_MIX_RANGE(>>=)
OP_ASSIGN_MIX_RANGE(<<=)
OP_ASSIGN_MIX_RANGE(&=)
OP_ASSIGN_MIX_RANGE(|=)
OP_ASSIGN_MIX_RANGE(^=)
OP_REL_MIX_RANGE(==)
OP_REL_MIX_RANGE(!=)
OP_REL_MIX_RANGE(>)
OP_REL_MIX_RANGE(>=)
OP_REL_MIX_RANGE(<)
OP_REL_MIX_RANGE(<=)
OP_BIN_MIX_RANGE(+, plus)
OP_BIN_MIX_RANGE(-, minus)
OP_BIN_MIX_RANGE(*, mult)
OP_BIN_MIX_RANGE(/, div)
OP_BIN_MIX_RANGE(%, mod)
OP_BIN_MIX_RANGE(>>, arg1)
OP_BIN_MIX_RANGE(<<, arg1)
OP_BIN_MIX_RANGE(&, logic)
OP_BIN_MIX_RANGE(|, logic)
OP_BIN_MIX_RANGE(^, logic)
#define OP_BIN_MIX_BIT(BIN_OP, RTYPE) \
template<int _AP_W1, bool _AP_S1, int _AP_W2, bool _AP_S2> \
INLINE typename ap_private<1, false>::template RType<_AP_W2,_AP_S2>::RTYPE \
operator BIN_OP ( const ap_bit_ref<_AP_W1,_AP_S1>& op1, const ap_private<_AP_W2,_AP_S2>& op2) { \
return ap_private<1, false>(op1).operator BIN_OP (op2); \
} \
template<int _AP_W1, bool _AP_S1, int _AP_W2, bool _AP_S2> \
INLINE typename ap_private<_AP_W1,_AP_S1>::template RType<1,false>::RTYPE \
operator BIN_OP ( const ap_private<_AP_W1,_AP_S1>& op1, const ap_bit_ref<_AP_W2,_AP_S2>& op2) { \
return op1.operator BIN_OP (ap_private<1, false>(op2)); \
}
#define OP_REL_MIX_BIT(REL_OP) \
template<int _AP_W1, bool _AP_S1, int _AP_W2, bool _AP_S2> \
INLINE bool operator REL_OP ( const ap_bit_ref<_AP_W1,_AP_S1>& op1, const ap_private<_AP_W2,_AP_S2>& op2) { \
return ap_private<_AP_W1,false>(op1).operator REL_OP (op2); \
} \
template<int _AP_W1, bool _AP_S1, int _AP_W2, bool _AP_S2> \
INLINE bool operator REL_OP ( const ap_private<_AP_W1,_AP_S1>& op1, const ap_bit_ref<_AP_W2,_AP_S2>& op2) { \
return op1.operator REL_OP (ap_private<1, false>(op2)); \
}
#define OP_ASSIGN_MIX_BIT(ASSIGN_OP) \
template<int _AP_W1, bool _AP_S1, int _AP_W2, bool _AP_S2> \
INLINE ap_private<_AP_W1,_AP_S1>& operator ASSIGN_OP ( ap_private<_AP_W1,_AP_S1>& op1, ap_bit_ref<_AP_W2,_AP_S2>& op2) { \
return op1.operator ASSIGN_OP (ap_private<1, false>(op2)); \
} \
template<int _AP_W1, bool _AP_S1, int _AP_W2, bool _AP_S2> \
INLINE ap_bit_ref<_AP_W1,_AP_S1>& operator ASSIGN_OP ( ap_bit_ref<_AP_W1,_AP_S1>& op1, ap_private<_AP_W2,_AP_S2>& op2) { \
ap_private<1, false> tmp(op1); \
tmp.operator ASSIGN_OP (op2); \
op1 = tmp; \
return op1; \
}
OP_ASSIGN_MIX_BIT(+=)
OP_ASSIGN_MIX_BIT(-=)
OP_ASSIGN_MIX_BIT(*=)
OP_ASSIGN_MIX_BIT(/=)
OP_ASSIGN_MIX_BIT(%=)
OP_ASSIGN_MIX_BIT(>>=)
OP_ASSIGN_MIX_BIT(<<=)
OP_ASSIGN_MIX_BIT(&=)
OP_ASSIGN_MIX_BIT(|=)
OP_ASSIGN_MIX_BIT(^=)
OP_REL_MIX_BIT(==)
OP_REL_MIX_BIT(!=)
OP_REL_MIX_BIT(>)
OP_REL_MIX_BIT(>=)
OP_REL_MIX_BIT(<)
OP_REL_MIX_BIT(<=)
OP_BIN_MIX_BIT(+, plus)
OP_BIN_MIX_BIT(-, minus)
OP_BIN_MIX_BIT(*, mult)
OP_BIN_MIX_BIT(/, div)
OP_BIN_MIX_BIT(%, mod)
OP_BIN_MIX_BIT(>>, arg1)
OP_BIN_MIX_BIT(<<, arg1)
OP_BIN_MIX_BIT(&, logic)
OP_BIN_MIX_BIT(|, logic)
OP_BIN_MIX_BIT(^, logic)
#define REF_REL_OP_MIX_INT(REL_OP, C_TYPE, _AP_W2, _AP_S2) \
template<int _AP_W, bool _AP_S> \
INLINE bool operator REL_OP ( const ap_range_ref<_AP_W,_AP_S> &op, C_TYPE op2) { \
return (ap_private<_AP_W, false>(op)).operator REL_OP (ap_private<_AP_W2,_AP_S2>(op2)); \
} \
template<int _AP_W, bool _AP_S> \
INLINE bool operator REL_OP ( C_TYPE op2, const ap_range_ref<_AP_W,_AP_S> &op) { \
return ap_private<_AP_W2,_AP_S2>(op2).operator REL_OP (ap_private<_AP_W, false>(op)); \
} \
template<int _AP_W, bool _AP_S> \
INLINE bool operator REL_OP ( const ap_bit_ref<_AP_W,_AP_S> &op, C_TYPE op2) { \
return (bool(op)) REL_OP op2; \
} \
template<int _AP_W, bool _AP_S> \
INLINE bool operator REL_OP ( C_TYPE op2, const ap_bit_ref<_AP_W,_AP_S> &op) { \
return op2 REL_OP (bool(op)); \
} \
template<int _AP_W, typename _AP_T, int _AP_W1, typename _AP_T1> \
INLINE bool operator REL_OP ( const ap_concat_ref<_AP_W,_AP_T, _AP_W1, _AP_T1> &op, C_TYPE op2) { \
return (ap_private<_AP_W + _AP_W1, false>(op)).operator REL_OP (ap_private<_AP_W2,_AP_S2>(op2)); \
} \
template<int _AP_W, typename _AP_T, int _AP_W1, typename _AP_T1> \
INLINE bool operator REL_OP ( C_TYPE op2, const ap_concat_ref<_AP_W,_AP_T, _AP_W1, _AP_T1> &op) { \
return ap_private<_AP_W2,_AP_S2>(op2).operator REL_OP (ap_private<_AP_W + _AP_W1, false>(op)); \
}
#define REF_REL_MIX_INT(C_TYPE, _AP_WI, _AP_SI) \
REF_REL_OP_MIX_INT(>, C_TYPE, _AP_WI, _AP_SI) \
REF_REL_OP_MIX_INT(<, C_TYPE, _AP_WI, _AP_SI) \
REF_REL_OP_MIX_INT(>=, C_TYPE, _AP_WI, _AP_SI) \
REF_REL_OP_MIX_INT(<=, C_TYPE, _AP_WI, _AP_SI) \
REF_REL_OP_MIX_INT(==, C_TYPE, _AP_WI, _AP_SI) \
REF_REL_OP_MIX_INT(!=, C_TYPE, _AP_WI, _AP_SI)
REF_REL_MIX_INT(bool, 1, false)
REF_REL_MIX_INT(char, 8, true)
REF_REL_MIX_INT(signed char, 8, true)
REF_REL_MIX_INT(unsigned char, 8, false)
REF_REL_MIX_INT(short, 16, true)
REF_REL_MIX_INT(unsigned short, 16, false)
REF_REL_MIX_INT(int, 32, true)
REF_REL_MIX_INT(unsigned int, 32, false)
# if defined __x86_64__
REF_REL_MIX_INT(long, 64, true)
REF_REL_MIX_INT(unsigned long, 64, false)
# else
REF_REL_MIX_INT(long, 32, true)
REF_REL_MIX_INT(unsigned long, 32, false)
# endif
REF_REL_MIX_INT(ap_slong, 64, true)
REF_REL_MIX_INT(ap_ulong, 64, false)
#define REF_BIN_OP_MIX_INT(BIN_OP, RTYPE, C_TYPE, _AP_W2, _AP_S2) \
template<int _AP_W, bool _AP_S> \
INLINE typename ap_private<_AP_W, false>::template RType<_AP_W2,_AP_S2>::RTYPE \
operator BIN_OP ( const ap_range_ref<_AP_W,_AP_S> &op, C_TYPE op2) { \
return (ap_private<_AP_W, false>(op)).operator BIN_OP (ap_private<_AP_W2,_AP_S2>(op2)); \
} \
template<int _AP_W, bool _AP_S> \
INLINE typename ap_private<_AP_W2, _AP_S2>::template RType<_AP_W,false>::RTYPE \
operator BIN_OP ( C_TYPE op2, const ap_range_ref<_AP_W,_AP_S> &op) { \
return ap_private<_AP_W2,_AP_S2>(op2).operator BIN_OP (ap_private<_AP_W, false>(op)); \
}
#define REF_BIN_MIX_INT(C_TYPE, _AP_WI, _AP_SI) \
REF_BIN_OP_MIX_INT(+, plus, C_TYPE, _AP_WI, _AP_SI) \
REF_BIN_OP_MIX_INT(-, minus, C_TYPE, _AP_WI, _AP_SI) \
REF_BIN_OP_MIX_INT(*, mult, C_TYPE, _AP_WI, _AP_SI) \
REF_BIN_OP_MIX_INT(/, div, C_TYPE, _AP_WI, _AP_SI) \
REF_BIN_OP_MIX_INT(%, mod, C_TYPE, _AP_WI, _AP_SI) \
REF_BIN_OP_MIX_INT(>>, arg1, C_TYPE, _AP_WI, _AP_SI) \
REF_BIN_OP_MIX_INT(<<, arg1, C_TYPE, _AP_WI, _AP_SI) \
REF_BIN_OP_MIX_INT(&, logic, C_TYPE, _AP_WI, _AP_SI) \
REF_BIN_OP_MIX_INT(|, logic, C_TYPE, _AP_WI, _AP_SI) \
REF_BIN_OP_MIX_INT(^, logic, C_TYPE, _AP_WI, _AP_SI)
REF_BIN_MIX_INT(bool, 1, false)
REF_BIN_MIX_INT(char, 8, true)
REF_BIN_MIX_INT(signed char, 8, true)
REF_BIN_MIX_INT(unsigned char, 8, false)
REF_BIN_MIX_INT(short, 16, true)
REF_BIN_MIX_INT(unsigned short, 16, false)
REF_BIN_MIX_INT(int, 32, true)
REF_BIN_MIX_INT(unsigned int, 32, false)
# if defined __x86_64__
REF_BIN_MIX_INT(long, 64, true)
REF_BIN_MIX_INT(unsigned long, 64, false)
#else
REF_BIN_MIX_INT(long, 32, true)
REF_BIN_MIX_INT(unsigned long, 32, false)
#endif
REF_BIN_MIX_INT(ap_slong, 64, true)
REF_BIN_MIX_INT(ap_ulong, 64, false)
#define REF_BIN_OP(BIN_OP, RTYPE) \
template<int _AP_W, bool _AP_S, int _AP_W2, bool _AP_S2> \
INLINE typename ap_private<_AP_W, false>::template RType<_AP_W2, false>::RTYPE \
operator BIN_OP (const ap_range_ref<_AP_W,_AP_S> &lhs, const ap_range_ref<_AP_W2,_AP_S2> &rhs) { \
return ap_private<_AP_W,false>(lhs).operator BIN_OP (ap_private<_AP_W2, false>(rhs)); \
}
REF_BIN_OP(+, plus)
REF_BIN_OP(-, minus)
REF_BIN_OP(*, mult)
REF_BIN_OP(/, div)
REF_BIN_OP(%, mod)
REF_BIN_OP(>>, arg1)
REF_BIN_OP(<<, arg1)
REF_BIN_OP(&, logic)
REF_BIN_OP(|, logic)
REF_BIN_OP(^, logic)
#if 1
#define CONCAT_OP_MIX_INT(C_TYPE, _AP_WI, _AP_SI) \
template<int _AP_W, bool _AP_S> \
INLINE \
ap_private< _AP_W + _AP_WI, false > \
operator, (const ap_private<_AP_W, _AP_S> &op1, C_TYPE op2) { \
ap_private<_AP_WI + _AP_W, false> val(op2); \
ap_private<_AP_WI + _AP_W, false> ret(op1); \
ret <<= _AP_WI; \
if (_AP_SI) { \
val <<= _AP_W; val >>= _AP_W; \
}\
ret |= val; \
return ret;\
} \
template<int _AP_W, bool _AP_S> \
INLINE \
ap_private< _AP_W + _AP_WI, false > \
operator, (C_TYPE op1, const ap_private<_AP_W, _AP_S>& op2) { \
ap_private<_AP_WI + _AP_W, false> val(op1); \
ap_private<_AP_WI + _AP_W, false> ret(op2); \
if (_AP_S) { \
ret <<= _AP_WI; ret >>= _AP_WI; \
} \
ret |= val << _AP_W; \
return ret; \
} \
template<int _AP_W, bool _AP_S> \
INLINE \
ap_private< _AP_W + _AP_WI, false > \
operator, (const ap_range_ref<_AP_W, _AP_S> &op1, C_TYPE op2) { \
ap_private<_AP_WI + _AP_W, false> val(op2); \
ap_private<_AP_WI + _AP_W, false> ret(op1); \
ret <<= _AP_WI; \
if (_AP_SI) { \
val <<= _AP_W; val >>= _AP_W; \
} \
ret |= val; \
return ret; \
} \
template<int _AP_W, bool _AP_S> \
INLINE \
ap_private< _AP_W + _AP_WI, false > \
operator, (C_TYPE op1, const ap_range_ref<_AP_W, _AP_S> &op2) { \
ap_private<_AP_WI + _AP_W, false> val(op1); \
ap_private<_AP_WI + _AP_W, false> ret(op2); \
int len = op2.length(); \
val <<= len; \
ret |= val; \
return ret; \
} \
template<int _AP_W, bool _AP_S> \
INLINE \
ap_private<_AP_WI + 1, false > \
operator, (const ap_bit_ref<_AP_W, _AP_S> &op1, C_TYPE op2) { \
ap_private<_AP_WI + 1, false> val(op2); \
val[_AP_WI] = op1; \
return val; \
} \
template<int _AP_W, bool _AP_S> \
INLINE \
ap_private<_AP_WI + 1, false > \
operator, (C_TYPE op1, const ap_bit_ref<_AP_W, _AP_S> &op2) { \
ap_private<_AP_WI + 1, false> val(op1); \
val <<= 1; \
val[0] = op2; \
return val; \
} \
template<int _AP_W, typename _AP_T, int _AP_W2, typename _AP_T2> \
INLINE \
ap_private<_AP_W + _AP_W2 + _AP_WI, false > \
operator, (const ap_concat_ref<_AP_W, _AP_T, _AP_W2, _AP_T2> &op1, C_TYPE op2) {\
ap_private<_AP_WI + _AP_W + _AP_W2, _AP_SI> val(op2);\
ap_private<_AP_WI + _AP_W + _AP_W2, _AP_SI> ret(op1);\
if (_AP_SI) { \
val <<= _AP_W + _AP_W2; val >>= _AP_W + _AP_W2; \
} \
ret <<= _AP_WI; \
ret |= val; \
return ret; \
}\
template<int _AP_W, typename _AP_T, int _AP_W2, typename _AP_T2> \
INLINE \
ap_private<_AP_W + _AP_W2 + _AP_WI, false > \
operator, (C_TYPE op1, const ap_concat_ref<_AP_W, _AP_T, _AP_W2, _AP_T2> &op2) {\
ap_private<_AP_WI + _AP_W + _AP_W2, _AP_SI> val(op1);\
ap_private<_AP_WI + _AP_W + _AP_W2, _AP_SI> ret(op2);\
int len = op2.length(); \
val <<= len; \
ret |= val;\
return ret; \
}\
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, \
int _AP_N > \
INLINE \
ap_private< _AP_W + _AP_WI, false > \
operator, (const af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N> &op1, C_TYPE op2) { \
ap_private<_AP_WI + _AP_W, false> val(op2); \
ap_private<_AP_WI + _AP_W, false> ret(op1); \
if (_AP_SI) { \
val <<= _AP_W; val >>= _AP_W; \
}\
ret <<= _AP_WI; \
ret |= val; \
return ret; \
} \
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, \
int _AP_N > \
INLINE \
ap_private< _AP_W + _AP_WI, false > \
operator, (C_TYPE op1, const af_range_ref<_AP_W, _AP_I, _AP_S, \
_AP_Q, _AP_O, _AP_N> &op2) { \
ap_private<_AP_WI + _AP_W, false> val(op1); \
ap_private<_AP_WI + _AP_W, false> ret(op2); \
int len = op2.length(); \
val <<= len; \
ret |= val; \
return ret; \
} \
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, \
int _AP_N > \
INLINE \
ap_private< 1 + _AP_WI, false> \
operator, (const af_bit_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, \
_AP_N> &op1, C_TYPE op2) { \
ap_private<_AP_WI + 1, _AP_SI> val(op2); \
val[_AP_WI] = op1; \
return val; \
} \
template<int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O, \
int _AP_N > \
INLINE \
ap_private< 1 + _AP_WI, false> \
operator, (C_TYPE op1, const af_bit_ref<_AP_W, _AP_I, _AP_S, _AP_Q,\
_AP_O, _AP_N> &op2) { \
ap_private<_AP_WI + 1, _AP_SI> val(op1); \
val <<= 1; \
val[0] = op2; \
return val; \
}
CONCAT_OP_MIX_INT(bool, 1, false)
CONCAT_OP_MIX_INT(char, 8, true)
CONCAT_OP_MIX_INT(signed char, 8, true)
CONCAT_OP_MIX_INT(unsigned char, 8, false)
CONCAT_OP_MIX_INT(short, 16, true)
CONCAT_OP_MIX_INT(unsigned short, 16, false)
CONCAT_OP_MIX_INT(int, 32, true)
CONCAT_OP_MIX_INT(unsigned int, 32, false)
# if defined __x86_64__
CONCAT_OP_MIX_INT(long, 64, true)
CONCAT_OP_MIX_INT(unsigned long, 64, false)
# else
CONCAT_OP_MIX_INT(long, 32, true)
CONCAT_OP_MIX_INT(unsigned long, 32, false)
# endif
CONCAT_OP_MIX_INT(ap_slong, 64, true)
CONCAT_OP_MIX_INT(ap_ulong, 64, false)
#endif
#if 1
#define CONCAT_SHIFT_MIX_INT(C_TYPE, op) \
template<int _AP_W, typename _AP_T, int _AP_W1, typename _AP_T1> \
INLINE ap_uint<_AP_W+_AP_W1> operator op (const ap_concat_ref<_AP_W, _AP_T, _AP_W1, _AP_T1> lhs, C_TYPE rhs) { \
return ((ap_uint<_AP_W+_AP_W1>)lhs.get()) op ((int)rhs); \
}
CONCAT_SHIFT_MIX_INT(long, <<)
CONCAT_SHIFT_MIX_INT(unsigned long, <<)
CONCAT_SHIFT_MIX_INT(unsigned int, <<)
CONCAT_SHIFT_MIX_INT(ap_ulong, <<)
CONCAT_SHIFT_MIX_INT(ap_slong, <<)
CONCAT_SHIFT_MIX_INT(long, >>)
CONCAT_SHIFT_MIX_INT(unsigned long, >>)
CONCAT_SHIFT_MIX_INT(unsigned int, >>)
CONCAT_SHIFT_MIX_INT(ap_ulong, >>)
CONCAT_SHIFT_MIX_INT(ap_slong, >>)
#endif
#if defined(SYSTEMC_H) || defined(SYSTEMC_INCLUDED)
template<int _AP_W, bool _AP_S>
INLINE void sc_trace(sc_core::sc_trace_file *tf, const ap_private<_AP_W, _AP_S> &op,
const std::string &name) {
if (tf)
tf->trace(sc_dt::sc_lv<_AP_W>(op.to_string(2).c_str()), name);
}
#endif
template<int _AP_W, bool _AP_S>
INLINE std::ostream& operator<<(std::ostream& out, const ap_private<_AP_W,_AP_S> &op)
{
ap_private<_AP_W, _AP_S> v=op;
const std::ios_base::fmtflags basefield = out.flags() & std::ios_base::basefield;
unsigned radix = (basefield == std::ios_base::hex) ? 16 :
((basefield == std::ios_base::oct) ? 8 : 10);
std::string str=v.toString(radix,_AP_S);
out<<str;
return out;
}
template<int _AP_W, bool _AP_S>
INLINE std::istream& operator >> (std::istream& in, ap_private<_AP_W,_AP_S> &op)
{
std::string str;
in >> str;
op = ap_private<_AP_W, _AP_S>(str.c_str());
return in;
}
template<int _AP_W, bool _AP_S>
INLINE std::ostream& operator<<(std::ostream& out, const ap_range_ref<_AP_W,_AP_S> &op)
{
return operator<<(out, ap_private<_AP_W, _AP_S>(op));
}
template<int _AP_W, bool _AP_S>
INLINE std::istream& operator >> (std::istream& in, ap_range_ref<_AP_W,_AP_S> &op)
{
return operator>>(in, ap_private<_AP_W, _AP_S>(op));;
}
template<int _AP_W, bool _AP_S>
INLINE void print(const ap_private<_AP_W,_AP_S> &op, bool fill=true )
{
ap_private<_AP_W, _AP_S> v=op;
uint32_t ws=v.getNumWords();
const uint64_t *ptr=v.getRawData();
int i=ws-1;
#if 0
if(fill)
printf("%016llx",*(ptr+i));
else
printf("%llx",*(ptr+i));
#else
//match SystemC output
if(_AP_W%64 != 0) {
uint32_t offset=_AP_W%64;
uint32_t count=(offset+3)/4;
int64_t data=*(ptr+i);
if(_AP_S)
data=(data<<(64-offset))>>(64-offset);
else
count=(offset+4)/4;
while(count-->0)
printf("%llx",(data>>(count*4))&0xf);
} else {
if(_AP_S==false)
printf("0");
printf("%016llx",*(ptr+i));
}
#endif
for(--i;i>=0;i--)
printf("%016llx",*(ptr+i));
printf("\n");
}
#endif /* #ifndef __AESL_GCC_AP_INT_H__ */
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
#include "router.hpp"
int main(int argc, char *argv[]){
short int size_x = 10, size_y = 10;
short int line_num = 6;
short int board[10][10], board_str[100];
int x, y;
for(y = 0; y < size_y; y++) {
for(x = 0; x < size_x; x ++) {
board[y][x] = 0;
}
}
// Terminal cells (value > 0)
board[0][1] = 1;
board[7][1] = 1;
board[0][3] = 2;
board[8][4] = 2;
board[4][5] = 3;
board[6][5] = 3;
board[4][6] = 4;
board[7][2] = 4;
board[5][4] = 5;
board[6][6] = 5;
board[9][8] = 6;
board[9][9] = 6;
// Routing disenabled cells (value < 0)
board[0][0] = -1;
board[1][7] = -1;
board[1][8] = -1;
board[2][1] = -1;
board[2][7] = -1;
board[2][8] = -1;
board[3][1] = -1;
board[4][1] = -1;
board[5][1] = -1;
// Transform "board" to "board_str"
for(y = 0; y < size_y; y++) {
for(x = 0; x < size_x; x++) {
int idx = y * size_x + x;
board_str[idx] = board[y][x];
}
}
/** top function of router **/
// status = 1: OK
// status = 0: NG
int status = router(size_x, size_y, line_num, board_str);
/** top function of router (User can set "seed" value manually when calling this function.) **/
//int status = router(size_x, size_y, line_num, board_str, 1234567);
cout << "Router status: " << status << endl;
// Transform "board_str" to "board"
for(y = 0; y < size_y; y++) {
for(x = 0; x < size_x; x++) {
int idx = y * size_x + x;
board[y][x] = board_str[idx];
}
}
return 0;
}
File added
#include "router.hpp"
// DATA_BIT: bit length of cell idx
// PRIO_BIT: bit length of cost(priority)
int router(short int size_x, short int size_y, short int line_num, short int board_str[], ap_uint<32> seed){
ap_uint<DATA_BIT> board_str_len = size_x * size_y;
ap_uint<DATA_BIT> j;
ap_uint<DATA_BIT> terminals[MAX_LINES][2];
short int paths_size[MAX_LINES];
ap_uint<DATA_BIT> paths[MAX_LINES][MAX_PATH];
bool adjacents[MAX_LINES];
ap_uint<PRIO_BIT> weights[MAX_CELLS];
short int i, x, y, p;
// Line init.
for(i = 0; i < line_num; i++) {
terminals[i][0] = DATA_MAX;
terminals[i][1] = DATA_MAX;
paths_size[i] = 0;
adjacents[i] = false;
}
for(j = 0; j < board_str_len; j++) {
weights[j] = 1; // init. value is "1"
i = board_str[j];
if(i > 0) {
if(terminals[i-1][0] == DATA_MAX) { terminals[i-1][0] = j; }
else if(terminals[i-1][1] == DATA_MAX) { terminals[i-1][1] = j; }
else {
cout << "Error: line#" << i << endl;
exit(1);
}
weights[j] = PRIO_MAX;
}
else if(i < 0) {
weights[j] = PRIO_MAX;
}
}
#ifdef PRINT_BOARD
cout << "== Print board ==" << endl;
for(y = 0; y < size_y; y++) {
for(x = 0; x < size_x; x++) {
j = y * size_x + x;
i = board_str[j];
if(i == 0) { cout << "-"; }
else if(i == -1) { cout << "X"; }
else{ cout << i; }
if(x != size_x-1) { cout << " "; }
}
cout << endl;
}
#endif
for(i = 0; i < line_num; i++) {
ap_uint<DATA_BIT> t1 = terminals[i][0];
ap_uint<DATA_BIT> t2 = terminals[i][1];
short int t1_x = t1 % size_x;
short int t1_y = t1 / size_x;
short int t2_x = t2 % size_x;
short int t2_y = t2 / size_x;
short int dist = abs(t1_x - t2_x) + abs(t1_y - t2_y); // Manhattan dist.
if(dist == 1) {
adjacents[i] = true;
#ifdef PRINT_BOARD
cout << "Line #" << i + 1 << " needs no routing" << endl;
#endif
}
}
lfsr_random_init(seed);
// Step 1
cout << "1st routing ..." << endl;
for(i = 0; i < line_num; i++) {
if(adjacents[i]) continue;
#ifdef PRINT_SEARCH
cout << "Line #" << i + 1 << endl;
#endif
ap_uint<DATA_BIT> t1 = terminals[i][0];
ap_uint<DATA_BIT> t2 = terminals[i][1];
weights[t1] = 1;
if(search(size_x, size_y, &paths_size[i], paths[i], t1, t2, weights) < 0) { return 0; }
weights[t1] = PRIO_MAX;
}
bool has_overlap;
ap_uint<1> overlap_checks[MAX_CELLS];
// Step 2
cout << "rip-up routing ..." << endl;
short int last_target = -1;
ap_uint<16> round;
for(round = 1; round <= ROUND_LIMIT; round++) {
short int target = lfsr_random() % line_num;
if(adjacents[target]) continue;
if(target == last_target) continue;
last_target = target;
ap_uint<PRIO_BIT> round_weight = new_weight(round);
#ifdef PRINT_SEARCH
cout << "Line #" << target + 1 << "(round: " << round << ", weight: " << round_weight << ")" << endl;
#endif
ap_uint<DATA_BIT> t1 = terminals[target][0];
ap_uint<DATA_BIT> t2 = terminals[target][1];
for(p = 0; p < paths_size[target]; p++) {
weights[paths[target][p]] = 1;
}
for(i = 0; i < line_num; i++) {
if(i == target) continue;
for(p = 0; p < paths_size[i]; p++) {
weights[paths[i][p]] = round_weight;
}
}
weights[t1] = 1;
search(size_x, size_y, &paths_size[target], paths[target], t1, t2, weights);
weights[t1] = PRIO_MAX;
has_overlap = false;
for(j = 0; j < board_str_len; j++) {
i = board_str[j];
if(i > 0 || i < 0) { overlap_checks[j] = 1; }
else { overlap_checks[j] = 0; }
}
for(i = 0; i < line_num; i++) {
for(p = 0; p < paths_size[i]; p++) {
ap_uint<DATA_BIT> cell_id = paths[i][p];
if(overlap_checks[cell_id]) {
has_overlap = true;
break;
}
overlap_checks[cell_id] = 1;
}
}
if(!has_overlap) break;
}
/** //debug
for(j = 0; j < board_str_len; j++) {
i = board_str[j];
cout << i << ": " << weights[j] << endl;
}
**/
if(has_overlap) { // Cannot solve
return 0;
}
int total_wire_length = 0;
for(i = 0; i < line_num; i++) {
total_wire_length += paths_size[i];
for(p = 0; p < paths_size[i]; p++) {
ap_uint<DATA_BIT> cell_id = paths[i][p];
board_str[cell_id] = i + 1;
}
}
#ifdef PRINT_BOARD
cout << "== Print answer ==" << endl;
for(y = 0; y < size_y; y++) {
for(x = 0; x < size_x; x++) {
j = y * size_x + x;
i = board_str[j];
if(i == 0) { cout << "-"; }
else if(i == -1) { cout << "X"; }
else{ cout << i; }
if(x != size_x-1) { cout << " "; }
}
cout << endl;
}
#endif
return total_wire_length;
}
void lfsr_random_init(ap_uint<32> seed) {
lfsr = seed;
}
ap_uint<32> lfsr_random() {
bool b_32 = lfsr.get_bit(32-32);
bool b_22 = lfsr.get_bit(32-22);
bool b_2 = lfsr.get_bit(32-2);
bool b_1 = lfsr.get_bit(32-1);
bool new_bit = b_32 ^ b_22 ^ b_2 ^ b_1;
lfsr = lfsr >> 1;
lfsr.set_bit(31, new_bit);
return lfsr.to_uint();
}
ap_uint<PRIO_BIT> new_weight(ap_uint<16> x) {
ap_uint<16> y = (x & 0x00FF) + 1;
return (ap_uint<PRIO_BIT>)(y);
}
int search(short int size_x, short int size_y, short int *path_size, ap_uint<DATA_BIT> path[MAX_PATH], ap_uint<DATA_BIT> start, ap_uint<DATA_BIT> goal, ap_uint<PRIO_BIT> w[MAX_CELLS]){
ap_uint<PRIO_BIT> dist[MAX_CELLS];
ap_uint<DATA_BIT> prev[MAX_CELLS];
int j;
for(j = 0; j < MAX_CELLS; j++) {
dist[j] = PRIO_MAX;
}
ap_uint<PQ_BIT> pq_len = 0;
bool is_empty = true;
ap_uint<ELEM_BIT> pq_nodes[MAX_PQ];
short int goal_x = goal % size_x;
short int goal_y = goal / size_x;
dist[start] = 0;
enqueue(pq_nodes, 0, start, &pq_len, &is_empty);
bool find_path = false; // No path exists
while(!is_empty) {
ap_uint<PRIO_BIT> prev_cost;
ap_uint<DATA_BIT> s;
dequeue(pq_nodes, &prev_cost, &s, &pq_len, &is_empty);
ap_uint<PRIO_BIT> dist_s = dist[s];
if(s == goal) {
find_path = true;
break;
}
ap_uint<PRIO_BIT> cost = w[s];
short int s_x = s % size_x;
short int s_y = s / size_x;
int a;
for(a = 0; a < 4; a++) {
short int d_x = s_x;
short int d_y = s_y;
switch(a) {
case 0: d_x -= 1; break;
case 1: d_x += 1; break;
case 2: d_y -= 1; break;
case 3: d_y += 1; break;
}
if(d_x >= 0 && d_x < size_x && d_y >= 0 && d_y < size_y) {
ap_uint<DATA_BIT> d = d_y * size_x + d_x;
if(w[d] == PRIO_MAX && d != goal) continue;
ap_uint<PRIO_BIT> dist_d = dist_s + cost;
if(dist_d < dist[d]) {
dist[d] = dist_d;
prev[d] = s;
dist_d += abs(d_x - goal_x) + abs(d_y - goal_y);
enqueue(pq_nodes, dist_d, d, &pq_len, &is_empty);
}
}
}
}
if(!find_path){ return -1; }
ap_uint<DATA_BIT> t = prev[goal];
short int p = 0;
#ifdef PRINT_SEARCH
cout << "Path: ";
#endif
while(t != start) {
#ifdef PRINT_SEARCH
cout << "(" << (short int)t % size_x << ", " << (short int)t / size_x << ")";
#endif
path[p] = t;
p++;
t = prev[t];
}
#ifdef PRINT_SEARCH
cout << endl;
#endif
*path_size = p;
return 0;
}
// Enqueue (Insert an element)
void enqueue(ap_uint<ELEM_BIT> pq_nodes[MAX_PQ], ap_uint<PRIO_BIT> priority, ap_uint<DATA_BIT> data, ap_uint<PQ_BIT> *pq_len, bool *is_empty){
(*pq_len)++;
if ((*pq_len) == 0) { (*pq_len)--; } // Queue is full -> Last element is automatically removed
// Note that last element is not always the lowest priority one. //
ap_uint<PQ_BIT> i = (*pq_len);
ap_uint<PQ_BIT> p = (*pq_len) >> 1; // parent node
while (i > 1 && (ap_uint<PRIO_BIT>)(pq_nodes[p] >> DATA_BIT) >= priority) {
pq_nodes[i] = pq_nodes[p];
i = p;
p = p >> 1; // parent node
}
pq_nodes[i] = ((ap_uint<ELEM_BIT>)priority << DATA_BIT) | (ap_uint<ELEM_BIT>)data;
*is_empty = false;
}
// Dequeue (Extract and remove the top element)
void dequeue(ap_uint<ELEM_BIT> pq_nodes[MAX_PQ], ap_uint<PRIO_BIT> *ret_priority, ap_uint<DATA_BIT> *ret_data, ap_uint<PQ_BIT> *pq_len, bool *is_empty){
*ret_priority = (ap_uint<PRIO_BIT>)(pq_nodes[1] >> DATA_BIT);
*ret_data = (ap_uint<DATA_BIT>)(pq_nodes[1] & DATA_MASK);
ap_uint<PQ_BIT> i = 1; // root node
ap_uint<PRIO_BIT> last_priority = (ap_uint<PRIO_BIT>)(pq_nodes[*pq_len] >> DATA_BIT); // Priority of last element
while (!(i >> (PQ_BIT-1))) {
ap_uint<PQ_BIT> c1 = i << 1; // child node (L)
ap_uint<PQ_BIT> c2 = c1 + 1; // child node (R)
if (c1 < *pq_len && (ap_uint<PRIO_BIT>)(pq_nodes[c1] >> DATA_BIT) <= last_priority) {
if (c2 < *pq_len && (ap_uint<PRIO_BIT>)(pq_nodes[c2] >> DATA_BIT) <= (ap_uint<PRIO_BIT>)(pq_nodes[c1] >> DATA_BIT)) {
pq_nodes[i] = pq_nodes[c2];
i = c2;
}
else {
pq_nodes[i] = pq_nodes[c1];
i = c1;
}
}
else {
if (c2 < *pq_len && (ap_uint<PRIO_BIT>)(pq_nodes[c2] >> DATA_BIT) <= last_priority) {
pq_nodes[i] = pq_nodes[c2];
i = c2;
}
else {
break;
}
}
}
pq_nodes[i] = pq_nodes[*pq_len];
(*pq_len)--;
if ((*pq_len) == 0) { *is_empty = true; }
}
#ifndef __ROUTER_HPP__
#define __ROUTER_HPP__
#include <iostream>
#define SOFTWARE
#ifdef SOFTWARE
#include "ap_int.h"
#else
#include <ap_int.h>
#endif
using namespace std;
#define ROUND_LIMIT 32768 // Max=65534(=2^16-2)
#define PRINT_BOARD
//#define PRINT_SEARCH // for router debug
#define MAX_LINES 256
#define MAX_PATH 128
#define MAX_CELLS 16384 // 128x128
#define PQ_BIT 12
#define MAX_PQ 4096
#define PRIO_BIT 16
#define DATA_BIT 16
#define ELEM_BIT 32 // ELEM_BIT = PRIO_BIT + DATA_BIT
#define DATA_MASK 65535 // 0000 FFFF
#define DATA_MAX 65535 // FFFF
#define PRIO_MAX 65535 // FFFF
/** top function (User can set "seed" value manually when calling this function.) **/
int router(short int size_x, short int size_y, short int line_num, short int board_str[], ap_uint<32> seed = 12345);
static ap_uint<32> lfsr;
void lfsr_random_init(ap_uint<32> seed);
ap_uint<32> lfsr_random();
ap_uint<PRIO_BIT> new_weight(ap_uint<16> x);
int search(short int size_x, short int size_y, short int *path_size, ap_uint<DATA_BIT> path[MAX_PATH], ap_uint<DATA_BIT> start, ap_uint<DATA_BIT> goal, ap_uint<PRIO_BIT> w[MAX_CELLS]);
void enqueue(ap_uint<ELEM_BIT> pq_nodes[MAX_PQ], ap_uint<PRIO_BIT> priority, ap_uint<DATA_BIT> data, ap_uint<PQ_BIT> *pq_len, bool *is_empty);
void dequeue(ap_uint<ELEM_BIT> pq_nodes[MAX_PQ], ap_uint<PRIO_BIT> *ret_priority, ap_uint<DATA_BIT> *ret_data, ap_uint<PQ_BIT> *pq_len, bool *is_empty);
#endif /* __ROUTER_HPP__ */
File added
File added
No preview for this file type
...@@ -7,16 +7,21 @@ ...@@ -7,16 +7,21 @@
#include<stdio.h> #include<stdio.h>
#include <list> #include <list>
#include <bits/stdc++.h> #include <bits/stdc++.h>
#include "router/router.hpp"
/* #include<stdlib.h> */ /* #include<stdlib.h> */
/* #include<string.h> */ /* #include<string.h> */
/* #include<math.h> */ /* #include<math.h> */
/* #include<time.h> */ /* #include<time.h> */
#define SPACE 1
short int connected[MAXLINE]={0}; //if line connected:2, if one end:1, otherwize:0 short int connected[MAXLINE]={0}; //if line connected:2, if one end:1, otherwize:0
short int board_beta[MAXSIZE][MAXSIZE]; //big board data short int board_beta[MAXSIZE][MAXSIZE]; //big board data
//edge:1~MAXLINE, line:-1~-MAXLINE, none:0, wall:SHRT_MIN //edge:1~MAXLINE, line:-1~-MAXLINE, none:0, wall:SHRT_MIN
short int rank[MAXBLOCK+1]; short int rank[MAXBLOCK+1];
short int done_block[MAXBLOCK+1]; short int done_block[MAXBLOCK+1];
short int board_str[900];
vector <int> mino_order;
void reset_board(void){ void reset_board(void){
int i,j; int i,j;
...@@ -91,17 +96,46 @@ int check_around(int x,int y){ ...@@ -91,17 +96,46 @@ int check_around(int x,int y){
return 0; return 0;
} }
} }
void del_mino(int mino){
int x,y;
x=block_data[mino][0][0];
y=block_data[mino][0][1];
for(int i=1;i<5;i++){
board_data[x+block_data[mino][i][0]][y+block_data[mino][i][1]]=0;
}
block_data[mino][0][0]=-1;
block_data[mino][0][1]=-1;
}
int check_put_mino(int i,int x, int y){// check block#i can put on x,y
for(int j=1;j<5;j++){
if(x+block_data[i][j][0]>19){
return 0;
}
if(y+block_data[i][j][1]>19){
return 0;
}
if(board_data[x+block_data[i][j][0]][y+block_data[i][j][1]]!=0){
return 0;
}
if(check_around(x+block_data[i][j][0],y+block_data[i][j][1])){
return 0;
}
}
return 1;
}
void data_mino(int i, int x,int y){ void data_mino(int i, int x,int y){
std::cout << "put mino "<< i << std::endl; std::cout << "put mino "<< i << std::endl;
for(int j=0;j<100;j++){ for(int j=0;j<100;j++){
for(int k=1;k<5;k++){ if(check_put_mino(i,x,y)){
if(board_data[x+block_data[i][k][0]][y+block_data[i][k][1]]!=0){
break;
}
if(check_around(x+block_data[i][k][0],y+block_data[i][k][1])) break;
if(k==4){
for(int l=1;l<5;l++){ for(int l=1;l<5;l++){
if(l==2 && block_data[i][l][2]==-1){
block_data[i][0][0]=x;
block_data[i][0][1]=y;
return;
}
if(block_data[i][l][2]!=0){ if(block_data[i][l][2]!=0){
board_data[x+block_data[i][l][0]][y+block_data[i][l][1]]=block_data[i][l][2]; board_data[x+block_data[i][l][0]][y+block_data[i][l][1]]=block_data[i][l][2];
}else{ }else{
...@@ -112,10 +146,8 @@ void data_mino(int i, int x,int y){ ...@@ -112,10 +146,8 @@ void data_mino(int i, int x,int y){
block_data[i][0][1]=y; block_data[i][0][1]=y;
return; return;
} }
} x+=(j%2)*SPACE;
y+=((j+1)%2)*SPACE;
x+=(j%2);
y+=((j+1)%2);
if(x>W || y>H) return; if(x>W || y>H) return;
} }
} }
...@@ -229,7 +261,7 @@ void put_mino(){ ...@@ -229,7 +261,7 @@ void put_mino(){
itr=order_w.insert(itr,next); itr=order_w.insert(itr,next);
itr++; itr++;
} }
if(map_w[i]==0) continue; if(map_w[i]==0|| map_w[i]==-1) continue;
itr=order_w.insert(itr,map_w[i]); itr=order_w.insert(itr,map_w[i]);
itr++; itr++;
} }
...@@ -354,7 +386,7 @@ void put_mino(){ ...@@ -354,7 +386,7 @@ void put_mino(){
itr=order_h.insert(itr,next); itr=order_h.insert(itr,next);
itr++; itr++;
} }
if(map_h[i]==0) continue; if(map_h[i]==0|| map_h[i]==-1) continue;
itr=order_h.insert(itr,map_h[i]); itr=order_h.insert(itr,map_h[i]);
itr++; itr++;
} }
...@@ -363,8 +395,8 @@ void put_mino(){ ...@@ -363,8 +395,8 @@ void put_mino(){
} }
printf("\n"); printf("\n");
done_block[next]=1; done_block[next]=1;
x++; //x++;
if(x==1)break; //if(x==1)break;
}//end of while ture for height }//end of while ture for height
printf("width is \n"); printf("width is \n");
...@@ -400,6 +432,7 @@ void put_mino(){ ...@@ -400,6 +432,7 @@ void put_mino(){
hight_c++; hight_c++;
} }
data_mino(next_put,width_c,hight_c); data_mino(next_put,width_c,hight_c);
mino_order.push_back(next_put);
}else{ }else{
for(int j=0;j<blocks;j++){ for(int j=0;j<blocks;j++){
if(put_block[order_h[j]]==0){ if(put_block[order_h[j]]==0){
...@@ -415,15 +448,67 @@ void put_mino(){ ...@@ -415,15 +448,67 @@ void put_mino(){
width_c++; width_c++;
} }
data_mino(next_put,width_c,hight_c); data_mino(next_put,width_c,hight_c);
mino_order.push_back(next_put);
} }
put_block[next_put]=1; put_block[next_put]=1;
print_answer();
}
//int next;
int mino_x,mino_y;
/*for(int i=0;i<blocks;i++){
next=mino_order[i];
mino_x=block_data[i][0][0];
mino_y=block_data[i][0][1];
del_mino(next);
if(i%2){
for(int j=mino_x-1;j>1;j--){
if(check_put_mino(next,j,mino_y)){
mino_x=j;
}else{
break;
}
}
}else{
for(int j=mino_y-1;j>1;j--){
if(check_put_mino(next,mino_x,j)){
mino_y=j;
}else{
break;
}
} }
}
data_mino(next,mino_x,mino_y);
}*/
}
void make_board_str(int size_x,int size_y){
for(int y = 0; y < size_y; y++) {
for(int x = 0; x < size_x; x++) {
int idx = y * size_x + x;
board_str[idx] = board_data[y][x];
}
}
}
void fix_to_board(int size_x, int size_y){
for(int y = 0; y < size_y; y++) {
for(int x = 0; x < size_x; x++) {
int idx = y * size_x + x;
board_data[y][x] = board_str[idx];
}
}
} }
void line(){ void line(){
make_board_str(20,20);
std::cout << lfsr <<std::endl;
int status = router(20, 20, line_num, board_str);
if(status){
std::cout << "success to line" << std::endl;
}else{
std::cout << "failed to line" << std::endl;
}
fix_to_board(20,20);
} }
void solve(void){ void solve(void){
......
File added
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment