google / xls

XLS: Accelerated HW Synthesis
http://google.github.io/xls/
Apache License 2.0
1.2k stars 175 forks source link

Multiplication of shorts is promoted to multiplication of ints #488

Open ericastor opened 3 years ago

ericastor commented 3 years ago

The initial XLS IR output from xlscc for multiplication of shorts first does a sign_ext to promote both inputs to ints, then multiplies them, then returns the lower 16 bits of the result. This makes the optimizer work harder than is necessary, and some targets might not be able to optimize it away.

#pragma hls_top
short foo(short a, short b){
    return a*b;
}
spurserh commented 3 years ago

Eric also pointed out that Clang produces the casts in its AST. It appears to be expected behavior: https://blog.llvm.org/2020/04/the-new-clang-extint-feature-provides.html

So, I figure that a fix probably needs to be XLS[cc] itself, recognizing and ignoring these extra casts.