Skip to content

Commit 1bd9d4f

Browse files
Merge pull request #3664 from alainmarcel/alainmarcel-patch-1
larger than 64 bit part select support
2 parents 07bab5f + 39c1a04 commit 1bd9d4f

File tree

18 files changed

+683
-218
lines changed

18 files changed

+683
-218
lines changed

src/DesignCompile/CompileExpression.cpp

Lines changed: 23 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -3702,107 +3702,32 @@ UHDM::any *CompileHelper::compilePartSelectRange(
37023702
UHDM::expr *rexp =
37033703
(expr *)compileExpression(component, fC, fC->Sibling(op), compileDesign,
37043704
reduce, pexpr, instance, muteErrors);
3705-
bool reduced = false;
3706-
if ((reduce == Reduce::Yes) && (lexp->UhdmType() == uhdmconstant) &&
3707-
(rexp->UhdmType() == uhdmconstant)) {
3708-
if (!name.empty()) {
3709-
any *v = getValue(name, component, compileDesign, reduce, instance,
3710-
fC->getFileId(), fC->Line(Constant_expression), pexpr,
3711-
muteErrors);
3712-
if (v && (v->UhdmType() == uhdmconstant)) {
3713-
constant *cv = (constant *)v;
3714-
Value *cvv =
3715-
m_exprBuilder.fromVpiValue(cv->VpiValue(), cv->VpiSize());
3716-
Value *left =
3717-
m_exprBuilder.fromVpiValue(lexp->VpiValue(), lexp->VpiSize());
3718-
Value *range =
3719-
m_exprBuilder.fromVpiValue(rexp->VpiValue(), rexp->VpiSize());
3720-
uint64_t l = left->getValueUL();
3721-
uint64_t r = range->getValueUL();
3722-
uint64_t res = 0;
3723-
if ((cvv->getType() == Value::Type::Hexadecimal) &&
3724-
(cvv->getSize() >
3725-
64 /* hex val stored as string above 64 bits */)) {
3726-
std::string val = cvv->getValueS();
3727-
std::string part;
3728-
if (fC->Type(op) == VObjectType::slIncPartSelectOp) {
3729-
int32_t steps = r / 4;
3730-
l = l / 4;
3731-
for (int32_t i = l; i < (int32_t)(l + steps); i++) {
3732-
int32_t index = ((int32_t)val.size()) - 1 - i;
3733-
if (index >= 0)
3734-
part += val[index];
3735-
else
3736-
part += '0';
3737-
}
3738-
} else {
3739-
int32_t steps = r / 4;
3740-
l = l / 4;
3741-
for (int32_t i = l; i > (int32_t)(l - steps); i--) {
3742-
int32_t index = ((int32_t)val.size()) - 1 - i;
3743-
if (index >= 0)
3744-
part += val[index];
3745-
else
3746-
part += '0';
3747-
}
3748-
}
3749-
if (NumUtils::parseHex(part, &res) == nullptr) {
3750-
res = 0;
3751-
}
3752-
} else {
3753-
uint64_t iv = cvv->getValueUL();
3754-
uint64_t mask = 0;
3755-
if (fC->Type(op) == VObjectType::slDecPartSelectOp) {
3756-
if (l >= r) {
3757-
for (uint64_t i = l; i > uint64_t(l - r); i--) {
3758-
mask |= ((uint64_t)1 << i);
3759-
}
3760-
res = iv & mask;
3761-
res = res >> (l - r);
3762-
} else {
3763-
res = 0;
3764-
}
3765-
} else {
3766-
for (uint64_t i = l; i < uint64_t(l + r); i++) {
3767-
mask |= ((uint64_t)1 << i);
3768-
}
3769-
res = iv & mask;
3770-
res = res >> l;
3771-
}
3772-
}
37733705

3774-
std::string sval = "UINT:" + std::to_string(res);
3775-
UHDM::constant *c = s.MakeConstant();
3776-
c->VpiValue(sval);
3777-
c->VpiDecompile(std::to_string(res));
3778-
c->VpiSize(r);
3779-
c->VpiConstType(vpiUIntConst);
3780-
result = c;
3781-
reduced = true;
3782-
}
3783-
}
3706+
UHDM::indexed_part_select *part_select = s.MakeIndexed_part_select();
3707+
part_select->Base_expr(lexp);
3708+
part_select->Width_expr(rexp);
3709+
if (fC->Type(op) == VObjectType::slIncPartSelectOp)
3710+
part_select->VpiIndexedPartSelectType(vpiPosIndexed);
3711+
else
3712+
part_select->VpiIndexedPartSelectType(vpiNegIndexed);
3713+
if (name == "CREATE_UNNAMED_PARENT") {
3714+
UHDM::ref_obj *ref = s.MakeRef_obj();
3715+
part_select->VpiParent(ref);
3716+
} else if (!name.empty()) {
3717+
UHDM::ref_obj *ref = s.MakeRef_obj();
3718+
ref->VpiName(name);
3719+
ref->VpiDefName(name);
3720+
ref->VpiParent(pexpr);
3721+
part_select->VpiParent(ref);
37843722
}
3723+
part_select->VpiConstantSelect(true);
3724+
result = part_select;
37853725

3786-
if (!reduced) {
3787-
UHDM::indexed_part_select *part_select = s.MakeIndexed_part_select();
3788-
part_select->Base_expr(lexp);
3789-
part_select->Width_expr(rexp);
3790-
if (fC->Type(op) == VObjectType::slIncPartSelectOp)
3791-
part_select->VpiIndexedPartSelectType(vpiPosIndexed);
3792-
else
3793-
part_select->VpiIndexedPartSelectType(vpiNegIndexed);
3794-
if (name == "CREATE_UNNAMED_PARENT") {
3795-
UHDM::ref_obj *ref = s.MakeRef_obj();
3796-
part_select->VpiParent(ref);
3797-
} else if (!name.empty()) {
3798-
UHDM::ref_obj *ref = s.MakeRef_obj();
3799-
ref->VpiName(name);
3800-
ref->VpiDefName(name);
3801-
ref->VpiParent(pexpr);
3802-
part_select->VpiParent(ref);
3803-
}
3804-
part_select->VpiConstantSelect(true);
3805-
result = part_select;
3726+
if ((reduce == Reduce::Yes) && (lexp->UhdmType() == uhdmconstant) &&
3727+
(rexp->UhdmType() == uhdmconstant)) {
3728+
bool invalidValue = false;
3729+
result = reduceExpr(result, invalidValue, component, compileDesign,
3730+
instance, BadPathId, 0, pexpr, muteErrors);
38063731
}
38073732
}
38083733
if (result != nullptr) {

tests/ElabCParam/ElabCParam.log

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ function 9
897897
gen_if 1
898898
gen_scope 16
899899
gen_scope_array 16
900-
indexed_part_select 2
900+
indexed_part_select 8
901901
int_typespec 33
902902
int_var 4
903903
io_decl 11
@@ -911,7 +911,7 @@ param_assign 30
911911
parameter 34
912912
range 18
913913
ref_module 5
914-
ref_obj 11
914+
ref_obj 17
915915
task 9
916916
=== UHDM Object Stats End ===
917917
[INF:UH0707] Elaborating UHDM...
@@ -932,7 +932,7 @@ function 18
932932
gen_if 1
933933
gen_scope 32
934934
gen_scope_array 32
935-
indexed_part_select 2
935+
indexed_part_select 8
936936
int_typespec 33
937937
int_var 4
938938
io_decl 22
@@ -946,7 +946,7 @@ param_assign 44
946946
parameter 34
947947
range 18
948948
ref_module 5
949-
ref_obj 17
949+
ref_obj 23
950950
task 18
951951
=== UHDM Object Stats End ===
952952
[INF:UH0708] Writing UHDM DB: ${SURELOG_DIR}/build/regression/ElabCParam/slpp_all/surelog.uhdm ...
@@ -2110,12 +2110,12 @@ design: (work@socket_1n)
21102110
\_module_inst: work@socket_1n (work@socket_1n), file:${SURELOG_DIR}/tests/ElabCParam/dut.sv, line:38:1, endln:51:10
21112111
|vpiRhs:
21122112
\_constant: , line:42:28, endln:42:45
2113-
|vpiDecompile:2
2114-
|vpiSize:8
2115-
|UINT:2
2113+
|vpiDecompile:4'b0010
2114+
|vpiSize:4
2115+
|BIN:0010
21162116
|vpiTypespec:
21172117
\_bit_typespec: , line:42:13, endln:42:22
2118-
|vpiConstType:9
2118+
|vpiConstType:3
21192119
|vpiLhs:
21202120
\_parameter: (work@socket_1n.BB), line:42:23, endln:42:25
21212121
|vpiDefName:work@socket_1n
@@ -2166,12 +2166,12 @@ design: (work@socket_1n)
21662166
|vpiOverriden:1
21672167
|vpiRhs:
21682168
\_constant: , line:25:37, endln:25:38
2169-
|vpiDecompile:2
2170-
|vpiSize:32
2171-
|UINT:2
2169+
|vpiDecompile:4'b0010
2170+
|vpiSize:4
2171+
|BIN:0010
21722172
|vpiTypespec:
21732173
\_int_typespec: , line:25:13, endln:25:25
2174-
|vpiConstType:9
2174+
|vpiConstType:3
21752175
|vpiLhs:
21762176
\_parameter: (work@socket_1n.gen_dfifo[0].fifo_d.ReqDepth), line:25:26, endln:25:34
21772177
|vpiDefName:work@fifo_sync
@@ -2201,12 +2201,12 @@ design: (work@socket_1n)
22012201
|vpiOverriden:1
22022202
|vpiRhs:
22032203
\_constant: , line:3:40, endln:3:41
2204-
|vpiDecompile:2
2205-
|vpiSize:32
2206-
|UINT:2
2204+
|vpiDecompile:4'b0010
2205+
|vpiSize:4
2206+
|BIN:0010
22072207
|vpiTypespec:
22082208
\_int_typespec: , line:3:13, endln:3:25
2209-
|vpiConstType:9
2209+
|vpiConstType:3
22102210
|vpiLhs:
22112211
\_parameter: (work@socket_1n.gen_dfifo[0].fifo_d.reqfifo.Depth), line:3:26, endln:3:31
22122212
|vpiDefName:work@prim_fifo_sync
@@ -2302,12 +2302,12 @@ design: (work@socket_1n)
23022302
|vpiOverriden:1
23032303
|vpiRhs:
23042304
\_constant: , line:25:37, endln:25:38
2305-
|vpiDecompile:2
2306-
|vpiSize:32
2307-
|UINT:2
2305+
|vpiDecompile:4'b0010
2306+
|vpiSize:4
2307+
|BIN:0010
23082308
|vpiTypespec:
23092309
\_int_typespec: , line:25:13, endln:25:25
2310-
|vpiConstType:9
2310+
|vpiConstType:3
23112311
|vpiLhs:
23122312
\_parameter: (work@socket_1n.gen_dfifo[1].fifo_d.ReqDepth), line:25:26, endln:25:34
23132313
|vpiDefName:work@fifo_sync
@@ -2337,12 +2337,12 @@ design: (work@socket_1n)
23372337
|vpiOverriden:1
23382338
|vpiRhs:
23392339
\_constant: , line:3:40, endln:3:41
2340-
|vpiDecompile:2
2341-
|vpiSize:32
2342-
|UINT:2
2340+
|vpiDecompile:4'b0010
2341+
|vpiSize:4
2342+
|BIN:0010
23432343
|vpiTypespec:
23442344
\_int_typespec: , line:3:13, endln:3:25
2345-
|vpiConstType:9
2345+
|vpiConstType:3
23462346
|vpiLhs:
23472347
\_parameter: (work@socket_1n.gen_dfifo[1].fifo_d.reqfifo.Depth), line:3:26, endln:3:31
23482348
|vpiDefName:work@prim_fifo_sync
@@ -2549,12 +2549,12 @@ design: (work@socket_1n)
25492549
\_module_inst: work@all_zero (work@all_zero), file:${SURELOG_DIR}/tests/ElabCParam/dut.sv, line:54:1, endln:67:10
25502550
|vpiRhs:
25512551
\_constant: , line:58:28, endln:58:45
2552-
|vpiDecompile:0
2553-
|vpiSize:8
2554-
|UINT:0
2552+
|vpiDecompile:4'b0000
2553+
|vpiSize:4
2554+
|BIN:0000
25552555
|vpiTypespec:
25562556
\_bit_typespec: , line:58:13, endln:58:22
2557-
|vpiConstType:9
2557+
|vpiConstType:3
25582558
|vpiLhs:
25592559
\_parameter: (work@all_zero.BB), line:58:23, endln:58:25
25602560
|vpiDefName:work@all_zero
@@ -2605,12 +2605,12 @@ design: (work@socket_1n)
26052605
|vpiOverriden:1
26062606
|vpiRhs:
26072607
\_constant: , line:25:37, endln:25:38
2608-
|vpiDecompile:0
2609-
|vpiSize:32
2610-
|UINT:0
2608+
|vpiDecompile:4'b0000
2609+
|vpiSize:4
2610+
|BIN:0000
26112611
|vpiTypespec:
26122612
\_int_typespec: , line:25:13, endln:25:25
2613-
|vpiConstType:9
2613+
|vpiConstType:3
26142614
|vpiLhs:
26152615
\_parameter: (work@all_zero.gen_dfifo[0].fifo_d.ReqDepth), line:25:26, endln:25:34
26162616
|vpiDefName:work@fifo_sync
@@ -2640,12 +2640,12 @@ design: (work@socket_1n)
26402640
|vpiOverriden:1
26412641
|vpiRhs:
26422642
\_constant: , line:3:40, endln:3:41
2643-
|vpiDecompile:0
2644-
|vpiSize:32
2645-
|UINT:0
2643+
|vpiDecompile:4'b0000
2644+
|vpiSize:4
2645+
|BIN:0000
26462646
|vpiTypespec:
26472647
\_int_typespec: , line:3:13, endln:3:25
2648-
|vpiConstType:9
2648+
|vpiConstType:3
26492649
|vpiLhs:
26502650
\_parameter: (work@all_zero.gen_dfifo[0].fifo_d.reqfifo.Depth), line:3:26, endln:3:31
26512651
|vpiDefName:work@prim_fifo_sync
@@ -2727,12 +2727,12 @@ design: (work@socket_1n)
27272727
|vpiOverriden:1
27282728
|vpiRhs:
27292729
\_constant: , line:25:37, endln:25:38
2730-
|vpiDecompile:0
2731-
|vpiSize:32
2732-
|UINT:0
2730+
|vpiDecompile:4'b0000
2731+
|vpiSize:4
2732+
|BIN:0000
27332733
|vpiTypespec:
27342734
\_int_typespec: , line:25:13, endln:25:25
2735-
|vpiConstType:9
2735+
|vpiConstType:3
27362736
|vpiLhs:
27372737
\_parameter: (work@all_zero.gen_dfifo[1].fifo_d.ReqDepth), line:25:26, endln:25:34
27382738
|vpiDefName:work@fifo_sync
@@ -2762,12 +2762,12 @@ design: (work@socket_1n)
27622762
|vpiOverriden:1
27632763
|vpiRhs:
27642764
\_constant: , line:3:40, endln:3:41
2765-
|vpiDecompile:0
2766-
|vpiSize:32
2767-
|UINT:0
2765+
|vpiDecompile:4'b0000
2766+
|vpiSize:4
2767+
|BIN:0000
27682768
|vpiTypespec:
27692769
\_int_typespec: , line:3:13, endln:3:25
2770-
|vpiConstType:9
2770+
|vpiConstType:3
27712771
|vpiLhs:
27722772
\_parameter: (work@all_zero.gen_dfifo[1].fifo_d.reqfifo.Depth), line:3:26, endln:3:31
27732773
|vpiDefName:work@prim_fifo_sync

0 commit comments

Comments
 (0)