|  | 
 
 楼主|
发表于 2025-4-13 21:48:50
|
显示全部楼层 
| module onehot_unit_l1( input                        i0                ,
 input                        i1                ,
 input                        i2                ,
 output          is_onehot ,// 1 means already has onehot, so the others must be 0
 output          not_onehot           // 1 means 100% not onehot, noneed to check others
 );
 
 wire i0_inv;        not u_i0_inv (i0_inv,i0);
 wire i0_and;  and u_i0_and (i0_and,i0_inv,i1);
 
 wire i1_inv;        not u_i1_inv (i1_inv,i1);
 wire i1_and;  and u_i1_and (i1_and,i1_inv,i0);
 
 or u_is_onehot(is_onehot,i0_and,i1_and);
 
 and u_not_onehot(not_onehot,i0,i1);
 
 endmodule
 
 module onehot_unit(
 input                        i00                ,
 input                        i01                ,
 input                        i02                ,
 input                        i10                ,
 input                        i11                ,
 input                        i12                ,
 input                        i20                ,
 input                        i21                ,
 input                        i22                ,
 output                       is_onehot ,// 1 means already has onehot, so the others must be 0
 output                       not_onehot           // 1 means 100% not onehot, noneed to check others
 );
 
 wire i0, err0;
 wire i1, err1;
 wire i2, err2;
 wire s_onehot;
 wire s_nothot;
 
 wire has_err = err0 | err1 | err2 ;
 wire not_has_err =  ~has_err;
 assign is_onehot  = s_onehot & not_has_err;
 assign not_onehot = s_nothot &     has_err;
 
 onehot_unit_l1 U_L10(
 .i0          (i00    ),
 .i1          (i01    ),
 .i2          (i02    ),
 .is_onehot   (i0     ),
 .not_onehot  (err0   )
 );
 
 onehot_unit_l1 U_L11(
 .i0          (i10    ),
 .i1          (i11    ),
 .i2          (i12    ),
 .is_onehot   (i1     ),
 .not_onehot  (err1   )
 );
 
 onehot_unit_l1 U_L12(
 .i0          (i20    ),
 .i1          (i21    ),
 .i2          (i22    ),
 .is_onehot   (i2     ),
 .not_onehot  (err2   )
 );
 
 onehot_unit_l1 U_L2(
 .i0          (i0     ),
 .i1          (i1     ),
 .i2          (i2     ),
 .is_onehot   (s_onehot),
 .not_onehot  (s_nothot)
 );
 
 endmodule
 | 
 |