Skip to content

[DSLX] In struct parametrics parametric argument types other than u32 should be allowed, including s32 #1841

@dank-openai

Description

@dank-openai

Describe the bug

This does not work:

pub struct FixedPoint<NUM_BITS: u32, BINARY_EXPONENT: s32> { 
    data: uN[NUM_BITS], 
}
#[test]
fn test_neg_exp() {
    let a = FixedPoint<u32:2, s32:-1> { data: u8:0 };
}

because BINARY_EXPONENT is s32. It works if I change it to u32. I really do want a signed value, so this is not acceptable.

Error message, referring to BINARY_EXPONENT when I create a:

sN[32] vs uN[32]: Dimension s32:-1 must be a `u32` (soon to be `usize`, see https://github.com/google/xls/issues/450 for details).

Note that other parametric argument types which are useful to implementers are also disallowed, e.g. bool would have been useful to me to make a signed magnitude workaround:

pub struct FixedPoint<NUM_BITS: u32, EXPONENT_IS_NEGATIVE:bool, BINARY_UEXPONENT: u32>

but the above is also not allowed.

To Reproduce

Use the code above, try to compile.

Expected behavior

That I can make BINARY_EXPONENT signed without issues.

This would be very handy for making an open source fixed point library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    dslxDSLX (domain specific language) implementation / front-end

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions