Skip to content
๐Ÿชข Explicit Part-Selects

๐Ÿชข Explicit Part-Selects

TL:DR A part-select extracts or assigns a contiguous slice of bits from a vector.
Syntax: vector[high:low] โ€” must match the direction of the declaration.

โœ… Why Use Explicit Part-Selects?

BenefitDescription
๐Ÿงฉ Symbolic trace clarityMakes bit ranges visible and auditable
๐Ÿ“š Onboarding-friendlyEasier for new readers to follow intent
๐Ÿ” Refactor-safeProtects against silent errors if widths change
๐Ÿง  Directional safetyEnforces correct slicing semantics

๐Ÿงฉ Examples of Explicit Part-Selects

โœ… Extracting a slice

wire [15:0] word;
wire [3:0] nibble;

assign nibble = word[11:8];  // โœ… Extract middle nibble

โœ… Assigning to a slice

reg [15:0] word;
reg [3:0] nibble;

assign word[11:8] = nibble;  // โœ… Overwrite middle nibble

โœ… Safe inversion with part-select

input  [2:0] a, b;
output [5:0] out_not;

assign out_not[2:0] = ~a[2:0];  // โœ… Invert a explicitly
assign out_not[5:3] = ~b[2:0];  // โœ… Invert b explicitly

โš ๏ธ Common Pitfall: Implicit Width Assumptions

assign out_not[2:0] = ~a;  // โš ๏ธ Relies on knowing a is [2:0]
  • Works if a is [2:0], but less explicit
  • Risky if a changes width later

๐Ÿง  Directional Reminder

Declaration

wire [0:7] data;  // Ascending index

Legal part-select

data[0:3];  // โœ… Matches declaration direction

Illegal part-select

data[3:0];  // โŒ Direction mismatch
Last updated on