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

Make polymorhic bitvector #127

Merged
merged 4 commits into from
Mar 18, 2020
Merged

Make polymorhic bitvector #127

merged 4 commits into from
Mar 18, 2020

Conversation

cdonovick
Copy link
Collaborator

Addresses #122

Adds polymorphic types which allows "run-time polymorphism"

Enables the following:

val = BitVector[size](...)
cond = Bit(...) # may be symbolic
s_val = SIntVector[size](val)
u_val = UIntVector[size](val)
c_val = cond.ite(s_val, u_val)
res = c_val < 1

where the final statement is effectively transformed to following by the type system

m0 = type(s_val).__lt__
m1 = type(u_val).__lt__ 
if m0 is m1:
    res = m0(c_val, 1) # doesn't matter which is called
else:
    res = cond.ite(m0(c_val, 1), m1(c_val, 1))

@cdonovick
Copy link
Collaborator Author

Discovered some bugs closing for now

@cdonovick cdonovick closed this Mar 11, 2020
@cdonovick cdonovick reopened this Mar 11, 2020
@rdaly525
Copy link
Collaborator

Looks good, but could you add the following chained ite's to your tests?

ite(Poly[A ,B], A)
ite(Poly[A, B], B)
ite(Poly[A, B], C)
ite(A, Poly[A, B])
ite(B, Poly[A, B])
ite(C, Poly[A, B])
ite(Poly[A, B], Poly[A,B])
ite(Poly[A, B], Poly[A, B, C])
ite(Poly[A, B, C], Poly[A, B])

@cdonovick
Copy link
Collaborator Author

None of those are valid but I'll add tests for chaining.

@rdaly525
Copy link
Collaborator

Poly[A,B] is just indicating the psuedo-code type of the argument. These should all be valid.


def _rand_bv(width):
return BitVector[width](random.randint(0, (1 << width) - 1))

def _rand_signed(width):
return SIntVector[width](random.randint(0, (1 << width) - 1))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use T.random(width) here

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and above)


m0 = inspect.getattr_static(T0, k)
m1 = inspect.getattr_static(T1, k)
namespace[k] = build_VCall(select, m0, m1)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be the magic, a PolyType store's it's select condition, operators are dispatched based on that condition when invoked.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory this might work with magma types?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually not quite, Poly would need to implement the magma protocol, but then I think it could work, maybe just by concatenating the bits of the two subtypes together as the bits representation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I plan on handling magma with my MagmaBV proposal. phanrahan/magma#587

MagmaBV will use the same machinery to build ites as BitVector / SMTBitVector and implement the magma protocol.

Copy link
Owner

@leonardt leonardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cdonovick
Copy link
Collaborator Author

Worth noting that this is going to generate a lot of terms of the form:

cond.ite(
    f(cond.ite(a,  b), *fargs),
    g(cond.ite(a,  b), *gargs),
)
# as an optimization on RTL we will want to transform this to:
cond.ite(
    f(a, *fargs),
    g(b, *gargs),
)

This transformation really shouldn't be too hard as its so structured. Further simplifying things fargs will almost always be exactly the same gargs.

@rdaly525
Copy link
Collaborator

Before this can be merged, this should be run with lassen. I think there is a bug somewhere in the ALU that this will address.

@cdonovick
Copy link
Collaborator Author

@rdaly525 is that bug in rtl generation? Cause this won't fix anything with magma.

@rdaly525
Copy link
Collaborator

Just make sure that lassen unit tests still pass before merging this PR.

@cdonovick
Copy link
Collaborator Author

Passes all tests on lassen StanfordAHA/lassen#166

@cdonovick cdonovick merged commit d5029d8 into master Mar 18, 2020
@cdonovick cdonovick deleted the poly branch March 18, 2020 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants