Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bit splitting in Calyx. #497

Closed
cgyurgyik opened this issue May 1, 2021 · 7 comments
Closed

Bit splitting in Calyx. #497

cgyurgyik opened this issue May 1, 2021 · 7 comments
Labels
C: Library Calyx's standard library good first issue Good issue to start contributing on Calyx S: Available Can be worked upon

Comments

@cgyurgyik
Copy link
Collaborator

cgyurgyik commented May 1, 2021

Sometimes we only want to access a certain subset of the bits in a multi-bit bus. std_slice provides limited functionality in this regard.

For example, in SV, we could access the ith bit of in with: in[i].
Following this, a Calyx interface for a single-bit split primitive might look like:

module std_split #(
  parameter WIDTH,
  parameter INDEX_SIZE
) (
  input wire logic [WIDTH-1:0]      in,
  input wire logic [INDEX_SIZE-1:0] index,
  output logic out;
);
  assign out = in[index];

  `ifdef VERILATOR
    always_comb begin
      if (index < 0 || index > (WIDTH - 1))
        $error(
          "std_split: Index is outside the bounds of the WIDTH.\n",
          "WIDTH: %0d", WIDTH,
          "index: %0d", index
        );
    end
  `endif
endmodule

This would require N individual std_splits to access each bit in a N-bit bus.

For example, we could also add an OUT_WIDTH if we want to split off a subset of bits with size > 1. We would then also need to provide a begin_index and end_index.

This also begs the question, perhaps we should differentiate between "compile-time"* splits and "runtime" splits? For example,
if I know I will always want to access the first and second bit, then this would simply be a two wire split off the bus. I would imagine this is a bit more complicated when the index (or indices) are determined at runtime.

*There's probably better terminology that fits here

@cgyurgyik cgyurgyik added the S: Discussion needed Issues blocked on discussion label May 1, 2021
@sampsyo
Copy link
Contributor

sampsyo commented May 2, 2021

Yes! It does seem like static vs. dynamic slices should probably be different primitives altogether. Static slices would get their indices as meta-level parameters, while dynamic slices would get their inputs as input wires. A good reason to separate them is that their costs are very different: static slices are effectively "free" in hardware, while dynamic slices are not.

@cgyurgyik cgyurgyik added S: Available Can be worked upon and removed S: Discussion needed Issues blocked on discussion labels May 8, 2021
@rachitnigam
Copy link
Contributor

Would it suffice to make std_slice take a begin_index and end_index instead of just the out_index? For reference, std_slice does this:

  assign out = in[OUT_WIDTH-1:0];

@rachitnigam
Copy link
Contributor

@cgyurgyik can add some context on where you were trying to use this?

@cgyurgyik
Copy link
Collaborator Author

cgyurgyik commented Aug 27, 2021

I don't recall (TCAM maybe?), but I imagine it would be useful to make certain wires of a bus available statically. I mean a concrete example would be ISA parser, but I don't think Calyx will target that.

For example,

[0][0][1][1] // Some 4-bit value
|    |     |

a = std_reg(2);
b = std_reg(2);

a = bit_slice(0, 2); // Statically known
b = bit_slice(2, 4);

Edit: A next step would be allowing arbitrary splicing, e.g. a=bit_slice(0, 3, 4) // Bits 0, 3, and 4.

@rachitnigam rachitnigam added the good first issue Good issue to start contributing on Calyx label Sep 20, 2021
@rachitnigam rachitnigam added the C: Library Calyx's standard library label Oct 1, 2022
@anthonyabeo
Copy link
Collaborator

@rachitnigam I will like to tackle this issue. I suppose the plan is to go with your suggestion here?

@sampsyo
Copy link
Contributor

sampsyo commented Jan 22, 2024

Hi, @anthonyabeo—I think that would be a good place to start! We would probably want to create a new, different primitive (to avoid conflicts with code that currently uses std_slice), and then consider migrating code over to it that could use the new primitive?

@anthonyabeo
Copy link
Collaborator

@sampsyo sure, that sounds good. I'll put something together and revert.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: Library Calyx's standard library good first issue Good issue to start contributing on Calyx S: Available Can be worked upon
Projects
None yet
Development

No branches or pull requests

4 participants