cornell-zhang/hcl-dialect

[Op] Support bitcast operation

Closed this issue · 0 comments

Bitcast is an operation that casts an integer or floating point value to an integer or floating point value of equal bit width. It is part of arith dialect, thus we do not need to implement it in the LLVM backend. For HLS backend, we can create a union to store the data in different types as shown in the following example.

void default_function(unsigned int A[10][10], float A_float32[10][10]) {
  int _top;
  A_float32_args: for (int args = 0; args < 10; ++args) {
    A_float32_args0: for (int args0 = 0; args0 < 10; ++args0) {
      union { uint32_t from; float to;} _converter;
      _converter.from = A[args][args0];
      A_float32[args][args0] = _converter.to;
    }
  }
}