@@ -217,9 +217,26 @@ sealed trait DFVal extends DFMember.Named:
217217 case DFVal .DesignParam (dfValRef = DFRef (dfVal)) =>
218218 stripAsIsAndDesignParam(dfVal)
219219 case _ => dfVal
220+ // TODO: maybe we need a better way to check equivalent expressions, with symbolic algebra comparison?
221+ // with such comparison, it is possible to simplify expressions at least in the common cases.
220222 (stripAsIsAndDesignParam(this ), stripAsIsAndDesignParam(that)) match
221- case (lhs : DFVal .CanBeExpr , rhs : DFVal .CanBeExpr ) => lhs.protIsSimilarTo(rhs)
222- case (lhs, rhs) => lhs == rhs
223+ // literal constants are considered to be similar to expressions if they are
224+ // at a higher level of hierarchy than the expression
225+ case (lhs : DFVal .Const , rhs : DFVal .CanBeExpr )
226+ if ! lhs.isGlobal && ! rhs.isGlobal &&
227+ lhs.getOwnerDesign.isOutsideOwner(rhs.getOwnerDesign) ||
228+ lhs.isGlobal && lhs.isAnonymous =>
229+ lhs.dfType.isSimilarTo(rhs.dfType) && lhs.getConstData.equals(rhs.getConstData)
230+ case (lhs : DFVal .CanBeExpr , rhs : DFVal .Const )
231+ if ! lhs.isGlobal && ! rhs.isGlobal &&
232+ rhs.getOwnerDesign.isOutsideOwner(lhs.getOwnerDesign) ||
233+ rhs.isGlobal && rhs.isAnonymous =>
234+ rhs.dfType.isSimilarTo(lhs.dfType) && rhs.getConstData.equals(lhs.getConstData)
235+ case (lhs : DFVal .CanBeExpr , rhs : DFVal .CanBeExpr ) =>
236+ lhs.protIsSimilarTo(rhs)
237+ case (lhs, rhs) => lhs == rhs
238+ end match
239+ end isSimilarTo
223240 protected def protGetConstData (using MemberGetSet ): Option [Any ]
224241 private var cachedConstDataReady : Boolean = false
225242 private var cachedConstData : Option [Any ] = None
@@ -599,7 +616,7 @@ object DFVal:
599616 case >> , << , ** , ror, rol, reverse, repeat
600617 case unary_-, unary_~, unary_!
601618 case rising, falling
602- case clog2, max, min, sel
619+ case clog2, max, min, abs, sel
603620 // special-case of initFile construct for vectors of bits
604621 case InitFile (format : InitFileFormat , path : String )
605622 object Op :
@@ -763,9 +780,9 @@ object DFVal:
763780 meta : Meta ,
764781 tags : DFTags
765782 ) extends Partial derives ReadWriter :
766- def elementWidth (using MemberGetSet ): Int = ( dfType : @ unchecked) match
767- case DFBits (_) => 1
768- case DFVector (cellType = cellType) => cellType.width
783+ def elementWidth (using MemberGetSet ): Int = dfType.runtimeChecked match
784+ case DFBits (_) | DFUInt (_) | DFSInt (_) => 1
785+ case DFVector (cellType = cellType) => cellType.width
769786 protected def protIsFullyAnonymous (using MemberGetSet ): Boolean =
770787 relValRef.get.isFullyAnonymous
771788 protected def protGetConstData (using MemberGetSet ): Option [Any ] =
@@ -789,9 +806,8 @@ object DFVal:
789806 case that : ApplyRange =>
790807 this .dfType.isSimilarTo(that.dfType) &&
791808 this .relValRef.get.isSimilarTo(that.relValRef.get) &&
792- this .idxHighRef.isSimilarTo(that.idxHighRef) && this .idxLowRef.isSimilarTo(
793- that.idxLowRef
794- )
809+ this .idxHighRef.isSimilarTo(that.idxHighRef) &&
810+ this .idxLowRef.isSimilarTo(that.idxLowRef)
795811 case _ => false
796812 protected def setMeta (meta : Meta ): this .type = copy(meta = meta).asInstanceOf [this .type ]
797813 protected def setTags (tags : DFTags ): this .type = copy(tags = tags).asInstanceOf [this .type ]
@@ -834,12 +850,15 @@ object DFVal:
834850 val data = relValData.asInstanceOf [(BitVector , BitVector )]
835851 if (data._2.bit(idxInt)) None
836852 else Some (data._1.bit(idxInt))
853+ case DFUInt (_) | DFSInt (_) =>
854+ relValData.asInstanceOf [Option [BigInt ]].map(_.testBit(idxInt))
837855 case DFVector (_, _) =>
838856 relValData.asInstanceOf [Vector [? ]](idxInt)
839857 case _ => ???
840858 Some (outData)
841859 case Some (_ : None .type ) => Some (None )
842860 case _ => None
861+ end match
843862 )
844863 end protGetConstData
845864 protected def `prot_=~` (that : DFMember )(using MemberGetSet ): Boolean = that match
@@ -1486,19 +1505,20 @@ object DFDesignBlock:
14861505 case Normal , Def , Simulation
14871506 case BlackBox (source : Source )
14881507 object InstMode :
1508+ import constraints .DeviceID .Vendor
14891509 object BlackBox :
14901510 enum Source derives CanEqual , ReadWriter :
14911511 case NA
14921512 case Files (path : List [String ])
14931513 case Library (libName : String , nameSpace : String )
1494- case Qsys ( typeName : String )
1514+ case VendorIP ( vendor : Vendor , typeName : String )
14951515
14961516 extension (dsn : DFDesignBlock )
14971517 def isDuplicate : Boolean = dsn.hasTagOf[DuplicateTag ]
14981518 def isBlackBox : Boolean = dsn.instMode.isInstanceOf [InstMode .BlackBox ]
1499- def isQsysIPBlackbox : Boolean = dsn.instMode match
1500- case InstMode .BlackBox (_ : InstMode .BlackBox .Source .Qsys ) => true
1501- case _ => false
1519+ def isVendorIPBlackbox : Boolean = dsn.instMode match
1520+ case InstMode .BlackBox (_ : InstMode .BlackBox .Source .VendorIP ) => true
1521+ case _ => false
15021522 def inSimulation : Boolean = dsn.instMode == InstMode .Simulation
15031523 def getCommonDesignWith (dsn2 : DFDesignBlock )(using MemberGetSet ): DFDesignBlock =
15041524 def getOwnerDesignChain (dsn : DFDesignBlock ): List [DFDesignBlock ] =
0 commit comments