Skip to content

Sign extend signed integers - #238

Merged
sharksforarms merged 3 commits into
sharksforarms:masterfrom
korrat:sign-extend-signed-integers
Feb 25, 2022
Merged

Sign extend signed integers#238
sharksforarms merged 3 commits into
sharksforarms:masterfrom
korrat:sign-extend-signed-integers

Conversation

@korrat

@korrat korrat commented Oct 16, 2021

Copy link
Copy Markdown
Contributor

This PR changes the implementation of DekuRead for signed integer primitive types, so that reads with a bit size less than the size of the underlying type are sign extended.

Fixes #236.

@wcampbell0x2a

Copy link
Copy Markdown
Collaborator

Could you add tests to the tests directory? Just for proving these fields in structs and such.

@sharksforarms

Copy link
Copy Markdown
Owner

Could you add tests to the tests directory? Just for proving these fields in structs and such.

Since there's no change to attributes I think it's alright as is (current test cases were updated)

@sharksforarms

Copy link
Copy Markdown
Owner

Is there a way to reduce the duplication of code between signed/non-signed? I'm open to having this as a separate issue.

@sharksforarms

Copy link
Copy Markdown
Owner

Friendly ping @korrat are you still interested in pursuing this PR?

@korrat
korrat force-pushed the sign-extend-signed-integers branch from 4d118dc to 547d83c Compare January 23, 2022 07:52
@korrat

korrat commented Jan 23, 2022

Copy link
Copy Markdown
Contributor Author

Sorry, @sharksforarms, totally forgot about this one. I'm still interested in pursuing this PR.

Is there a way to reduce the duplication of code between signed/non-signed? I'm open to having this as a separate issue.

I've tried to merge the ImplDekuRead macros, but I'm having some trouble with the f32/f64, since they don't implement Shl/Shr. I can try again later in the week, but I think I would have to add a new macro for the floats. But perhaps that macro could be simpler.

Previously, the two macros to implement DekuRead for integer primitives
contained nearly identical code, with the exception of sign-extending
in the signed integer implementation.

With this commit, signed integers reuse the code of their unsigned
counterparts and add sign-extending on top.
@korrat

korrat commented Feb 15, 2022

Copy link
Copy Markdown
Contributor Author

Here's a proposal to reduce the duplication. Let me know if this is what you had in mind.

Alternatively, it should be possible to use a single implementation for the integer types and instead proxy the float implementations through unsigned integers, similarly to how it's done for the signed integers in this commit.

@korrat

korrat commented Feb 22, 2022

Copy link
Copy Markdown
Contributor Author

I can reproduce the compile error on master, so I think it is unrelated to the changes in this PR.

I think the error is related to rust-lang/rust#79609. Defining _Unwind_Resume, as suggested there, fixes the problem. Should I add a commit for the fix? Or would you prefer a different PR for that?

@sharksforarms

Copy link
Copy Markdown
Owner

Hey @korrat sorry for my delay. The PR looks good at first glance, I'll take some time this week to look at it. A separate PR would be appreciated!

@sharksforarms
sharksforarms merged commit f9013b8 into sharksforarms:master Feb 25, 2022
@sharksforarms

Copy link
Copy Markdown
Owner

Thanks! Released in 0.13.0

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.

Sign-extending signed integer types?

3 participants