cornell-zhang / hcl-dialect

HeteroCL-MLIR dialect for accelerator design
https://cornell-zhang.github.io/heterocl/index.html
Other
40 stars 17 forks source link

[Op] Support bitcast operation #25

Closed chhzh123 closed 2 years ago

chhzh123 commented 2 years ago

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;
    }
  }
}