0

我在谷歌上搜索过,但我没有找到这个警告的原因Wint-in-bool-context

编译器给了我以下警告:

In file included from /tools/Xilinx/Vivado/2020.1/include/ap_common.h:641,
                 from /tools/Xilinx/Vivado/2020.1/include/ap_int.h:54,
                 from src/matrix_mult.h:35,
                 from src/host.cpp:33:
/tools/Xilinx/Vivado/2020.1/include/etc/ap_private.h: In instantiation of 'void ap_private<_AP_W, _AP_S, true>::clearUnusedBits() volatile [with int _AP_W = 32; bool _AP_S = true]':
/tools/Xilinx/Vivado/2020.1/include/etc/ap_private.h:1485:1:   required from 'ap_private<_AP_W, _AP_S, true>& ap_private<_AP_W, _AP_S, true>::operator=(int) [with int _AP_W = 32; bool _AP_S = true]'
/tools/Xilinx/Vivado/2020.1/include/ap_int.h:160:3:   required from 'ap_int<_AP_W>::ap_int(int) [with int _AP_W = 32]'
src/host.cpp:50:30:   required from here
/tools/Xilinx/Vivado/2020.1/include/etc/ap_private.h:2144:28: warning: enum constant in boolean context [-Wint-in-bool-context]
 2144 |             : (excess_bits ? (((uint64_t)VAL) << (excess_bits)) >> (excess_bits)
      |               ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2145 |                            : (uint64_t)VAL));

这是与此警告相关的代码行(host.cpp 第 50 行):

#include <ap_int.h>; //This is a library for arbitrary precision integers Xilinx HLS

int M,N

static void initialise(ap_int<32> *A)
{
     for (int i = 0; i < M; i++) {
          for (int j = 0; j < N; j++) {
               A[i * N + j] =  1; // _this is line 50_
          }
     }
}

int main(int argc, char **argv) {
  N = atoi(argv[0]); //user input the matrix sizes during run
  M = atoi(argv[1]);
std::vector<ap_int<32>,aligned_allocator<ap_int<32>> A(N*M);

initialise(A.data());

目标是创建 32 位整数值向量来存储 N*M 大小的矩阵。

4

1 回答 1

1

-Wint-in-bool-context就像听起来一样。您正在使用一个整数值并允许它隐含地表现得像 a bool(例如,任何非零值都是true)。

在您的(有限)代码段中,很可能是因为excess_bits是一个整数值而不是bool。要使此类警告静音,请改为显式强制转换,或执行计算结果为布尔表达式的检查 - 例如:

              : (static_cast<bool>(excess_bits) ? (((uint64_t)VAL) << (excess_bits)) >> (excess_bits)
//              ^~~~~~~~~~~~~~~~~~~           ~ Tell compiler we want a bool

或者

              : ((excess_bits != 0) ? (((uint64_t)VAL) << (excess_bits)) >> (excess_bits)

您提供的第二个片段不太清楚,因为我们没有错误、确切的违规行或ap_int<32>. 如果我不得不猜测,分配

B.data()[i * n + j] =  0x00000001;

可能应该分配true而不是数值;但这只是一个猜测,因为这里没有给出上下文。

于 2021-01-28T18:43:22.393 回答