Skip to content

Commit 38f8829

Browse files
committed
utils/bitops: Add sc_buf2bv
Add sc_buf2bv to copy from a C buffer into an sc_bv. Signed-off-by: Edgar E. Iglesias <edgar@zeroasic.com>
1 parent 34a185a commit 38f8829

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

utils/bitops.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,17 @@ static void sc_bv2buf(unsigned char *buf, const sc_bv<width> &s, int bitlen)
8787
buf[i / 8] = s.range(i + 8 - 1, i).to_uint();
8888
}
8989
}
90+
91+
// Copy a C buffer into a sc_bv.
92+
template <int width>
93+
static void sc_buf2bv(unsigned char *buf, sc_bv<width> &s, int bitlen)
94+
{
95+
int i;
96+
97+
assert(width % 8 == 0);
98+
99+
for (i = 0; i < width && i < bitlen; i += 8) {
100+
s.range(i + 8 - 1, i) = buf[i / 8];
101+
}
102+
}
90103
#endif

0 commit comments

Comments
 (0)