xls icon indicating copy to clipboard operation
xls copied to clipboard

[dslx] Allow struct parametrics to be types other than `u32`

Open cdleary opened this issue 2 years ago • 1 comments

Right now we evaluate all parametric expressions given to a struct as u32s, but that's technically too strict a limitation -- although we only allow u32s to appear in e.g. array dimensions when building a type, you could imagine a use case like the following:

  struct Point<N: u5, N_U32: u32 = {N as u32}> {                                                                                  
    x: uN[N_U32],                                                                                                                 
  }                                                                                                                               
                                                                                                                                  
  fn f(p: Point<u5:3>) -> uN[3] {                                                                                                 
    p.y                                                                                                                           
  } 

Note that the value given as N is not used in any type definition, just as a value that we do some computation from.

Note that I'm going to land a change that overly restricts them to all be u32s at first to fix #727, then we can loosen from there.

cdleary avatar May 23 '23 21:05 cdleary

Another usage for this is to be able to parameterize structs with struct parametric. For example -- for SRAMS (https://github.com/google/xls/blob/adb92be6099de5486b7810cdbb4935a67c16cd72/xls/examples/ram.x#L32-L36)

Grouping all the parameters in a struct can simply instantiation of a set of related structs

// Write: (address, data, mask) -> ()
pub struct WriteReq<PARAM: SramParams> {
  addr: bits[PARAM.ADDR_WIDTH],
  data: bits[PARAM.DATA_WIDTH],
  mask: bits[PARAM.NUM_PARTITIONS],
}

hongted avatar Feb 08 '24 02:02 hongted

Is there any progress made so far on this issue? Being able to parameterize Procs not just with simple types but also with structures and arrays would be great

rw1nkler avatar Apr 03 '24 08:04 rw1nkler