mirror of
https://github.com/YosysHQ/yosys
synced 2025-09-12 04:31:29 +00:00
Make Const::Const(long long) constructor use packed bits internally if possible
This commit is contained in:
parent
31fc0f53e5
commit
e206b059f6
3 changed files with 52 additions and 1 deletions
|
@ -221,9 +221,34 @@ RTLIL::Const::Const(const std::string &str)
|
|||
tag = backing_tag::string;
|
||||
}
|
||||
|
||||
RTLIL::Const::Const(long long val) // default width 32
|
||||
{
|
||||
flags = RTLIL::CONST_FLAG_NONE;
|
||||
char bytes[] = {
|
||||
(char)(val >> 24), (char)(val >> 16), (char)(val >> 8), (char)val
|
||||
};
|
||||
new ((void*)&str_) std::string(bytes, 4);
|
||||
tag = backing_tag::string;
|
||||
}
|
||||
|
||||
RTLIL::Const::Const(long long val, int width)
|
||||
{
|
||||
flags = RTLIL::CONST_FLAG_NONE;
|
||||
if ((width & 7) == 0) {
|
||||
new ((void*)&str_) std::string();
|
||||
tag = backing_tag::string;
|
||||
std::string& str = get_str();
|
||||
int bytes = width >> 3;
|
||||
signed char sign_byte = val < 0 ? -1 : 0;
|
||||
str.resize(bytes, sign_byte);
|
||||
bytes = std::min<int>(bytes, sizeof(val));
|
||||
for (int i = 0; i < bytes; i++) {
|
||||
str[str.size() - 1 - i] = val;
|
||||
val = val >> 8;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
new ((void*)&bits_) bitvectype();
|
||||
tag = backing_tag::bits;
|
||||
bitvectype& bv = get_bits();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue