@@ -4573,6 +4573,7 @@ void UhdmImporter::import_case_stmt_sync(const case_stmt* uhdm_case, RTLIL::Sync
45734573 // First, collect all assignments from all case items
45744574 std::map<std::string, std::vector<std::pair<RTLIL ::SigSpec, RTLIL ::SigSpec>>> signal_assignments;
45754575 std::vector<RTLIL ::SigSpec> case_conditions;
4576+ RTLIL ::SigSpec all_non_default_conditions; // Track all non-default conditions
45764577
45774578 // Process each case item
45784579 if (auto case_items = uhdm_case->Case_items ()) {
@@ -4582,6 +4583,7 @@ void UhdmImporter::import_case_stmt_sync(const case_stmt* uhdm_case, RTLIL::Sync
45824583 for (auto case_item : *case_items) {
45834584 // Get case expressions (values to match)
45844585 RTLIL ::SigSpec case_condition;
4586+ bool is_default = false ;
45854587
45864588 if (auto exprs = case_item->VpiExprs ()) {
45874589 // Build equality comparison for this case
@@ -4603,8 +4605,19 @@ void UhdmImporter::import_case_stmt_sync(const case_stmt* uhdm_case, RTLIL::Sync
46034605 log_flush ();
46044606 }
46054607 }
4608+
4609+ // Add this condition to the combined non-default conditions
4610+ if (!case_condition.empty ()) {
4611+ if (all_non_default_conditions.empty ()) {
4612+ all_non_default_conditions = case_condition;
4613+ } else {
4614+ // OR with other non-default conditions
4615+ all_non_default_conditions = create_or_cell (all_non_default_conditions, case_condition);
4616+ }
4617+ }
46064618 } else {
46074619 // This is a default case
4620+ is_default = true ;
46084621 log (" Default case\n " );
46094622 log_flush ();
46104623 }
@@ -4618,7 +4631,23 @@ void UhdmImporter::import_case_stmt_sync(const case_stmt* uhdm_case, RTLIL::Sync
46184631 RTLIL ::SigSpec prev_condition = current_condition;
46194632
46204633 // Set condition for nested statements
4621- if (!case_condition.empty ()) {
4634+ if (is_default) {
4635+ // For default case, use the negation of all other conditions
4636+ if (!all_non_default_conditions.empty ()) {
4637+ // Create NOT of all non-default conditions
4638+ RTLIL ::Wire* not_wire = module ->addWire (NEW_ID , 1 );
4639+ module ->addNotGate (NEW_ID , all_non_default_conditions, not_wire);
4640+ RTLIL ::SigSpec default_condition (not_wire);
4641+
4642+ if (current_condition.empty ()) {
4643+ current_condition = default_condition;
4644+ } else {
4645+ // AND with existing condition
4646+ current_condition = create_and_cell (current_condition, default_condition);
4647+ }
4648+ log (" Using negation of all non-default conditions for default case\n " );
4649+ }
4650+ } else if (!case_condition.empty ()) {
46224651 if (current_condition.empty ()) {
46234652 current_condition = case_condition;
46244653 } else {
0 commit comments