Constraint solver : very slow for array randomization

Hi,

I am trying to constraint a dynamic array - this stores the different opcodes used for processing the input.
When all the *_min and *_max values are non-zero, the constraint solver is extremely slow.

Any suggestions on improving this constraint?

     opcode_t tmp_act_cmd_mem_opcode_grp[]; 
      int instr_cnt = ($urandom_range(8,256); // user can provide through $value$plusargs too        

      void'(std::randomize(tmp_act_cmd_mem_opcode_grp) with {
           tmp_act_cmd_mem_opcode_grp.size() == instr_cnt; 
          (tmp_act_cmd_mem_opcode_grp.sum() with (int'(item == NOP)))           inside {[0:255]};
          (tmp_act_cmd_mem_opcode_grp.sum() with (int'(item == MOVD)))          inside {[act_movd_cnt_min:act_movd_cnt_max]};
          (tmp_act_cmd_mem_opcode_grp.sum() with (int'(item == MOVI)))          inside {[act_movi_cnt_min:act_movi_cnt_max]};
          (tmp_act_cmd_mem_opcode_grp.sum() with (int'(item == UPD_HBOA)))      inside {[act_upd_hboa_cnt_min:act_upd_hboa_cnt_max]};
          (tmp_act_cmd_mem_opcode_grp.sum() with (int'(item == ADDI)))          inside {[act_addi_cnt_min:act_addi_cnt_max]};
          (tmp_act_cmd_mem_opcode_grp.sum() with (int'(item == ADDL)))          inside {[act_addl_cnt_min:act_addl_cnt_max]};
          (tmp_act_cmd_mem_opcode_grp.sum() with (int'(item == UPD_CSUM)))      inside {[act_upd_csum_cnt_min:act_upd_csum_cnt_max]};
          (tmp_act_cmd_mem_opcode_grp.sum() with (int'(item == LD_HDRLEN)))     inside {[act_ld_hdrlen_cnt_min:act_ld_hdrlen_cnt_max]};
          (tmp_act_cmd_mem_opcode_grp.sum() with (int'(item == MOVDM)))         inside {[act_movdm_cnt_min:act_movdm_cnt_max]};
          (tmp_act_cmd_mem_opcode_grp.sum() with (int'(item == CPY_HBOA)))      inside {[act_cpy_hboa_cnt_min:act_cpy_hboa_cnt_max]};
          foreach(tmp_act_cmd_mem_opcode_grp[j]) {
             tmp_act_cmd_mem_opcode_grp[j] inside  {[NOP:CPY_HBOA]};  
             if(j>=32) {
                tmp_act_cmd_mem_opcode_grp[j] !=  LD_HDRLEN;  // LD_HDRLEN should be within first 32 instructions
             } 
          }
      });

Thanks

In reply to kp:

You could try breaking this up into two separate randomization problems: 1) the count of each instruction 2) the distributions of instructions with the array

  typedef enum {
    NOP,MOVD,MOVI,UPD_HBOA,ADDI,ADDL,UPD_CSUM,LD_HDRLEN,MOVDM,CPY_HBOA
  } opcode_t;

  opcode_t Iterator;
  int unsigned opcode_count[opcode_t];
  int instr_count;
  opcode_t tmp_act_cmd_mem_opcode_grp[];
  initial begin
    Iterator = Iterator.first();
    do begin
      opcode_count[Iterator] = 0;
      Iterator = Iterator.next();
    end while (Iterator != Iterator.first());
    instr_count = $urandom_range(8,256);
    tmp_act_cmd_mem_opcode_grp = new[instr_count];
    assert(randomize(opcode_count) with 
           {opcode_count.sum() == instr_count;
            opcode_count[NOP]       inside {[0:255]};
            opcode_count[MOVD]      inside {[act_movd_cnt_min:act_movd_cnt_max]};
            opcode_count[OVI]       inside {[act_movi_cnt_min:act_movi_cnt_max]};
            opcode_count[UPD_HBOA]  inside {[act_upd_hboa_cnt_min:act_upd_hboa_cnt_max]};
            opcode_count[ADDI]      inside {[act_addi_cnt_min:act_addi_cnt_max]};
            opcode_count[ADDL]      inside {[act_addl_cnt_min:act_addl_cnt_max]};
            opcode_count[UPD_CSUM]  inside {[act_upd_csum_cnt_min:act_upd_csum_cnt_max]};
            opcode_count[LD_HDRLEN] inside {[act_ld_hdrlen_cnt_min:act_ld_hdrlen_cnt_max]};
            opcode_count[MOVDM]     inside {[act_movdm_cnt_min:act_movdm_cnt_max]};
            opcode_count[CPY_HBOA]  inside {[act_cpy_hboa_cnt_min:act_cpy_hboa_cnt_max]};
           });
     assert(randomize(tmp_act_cmd_mem_opcode_grp) with 
           {foreach(opcode_count[opcode])
              tmp_act_cmd_mem_opcode_grp.sum() with (int'(item == opcode) == opcode_count[opcode]);
            foreach(tmp_act_cmd_mem_opcode_grp[j])
              j>=32 -> tmp_act_cmd_mem_opcode_grp[j] !=  LD_HDRLEN;  // LD_HDRLEN should be within first 32 instructions
           }); 
  end

In reply to dave_59:

Thanks Dave, that helped