-
Notifications
You must be signed in to change notification settings - Fork 275
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
fix rev16 instruction #1128
fix rev16 instruction #1128
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use extract
and express the semantics exactly as in the Reference Manual.
And thanks for fixing it.
Thanks for the fast and detailed response, would you think it a good idea that I change the | `REV, [|`Reg dest; src; cond; _|] ->
let s = exp_of_op src in
let i24 = int32 24 in
let i8 = int32 8 in
let umask = int32 0xff0000 in
let lmask = int32 0xff00 in
let rev =
let open Bil in
s lsl i24 lor
s lsr i24 lor
(s land umask) lsr i8 lor
(s land lmask) lsl i8
in |
Certainly, it is a good idea! |
Please check if the fix is valid and can be merged @ivg . |
@Phosphorus15, we use the |
lib/arm/arm_lifter.ml
Outdated
((extract 15 8 s) lsr i8) lor | ||
((extract 23 16 s) lsl i8) lor | ||
((extract 31 24 s) lsr i8) | ||
) in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Semanitcs notes:
The code is not well-typed and rev
is always 0
. The expression extract 7 0 s
has type i8
(i.e., an 8-bit word). Thus you're shifting 8-bit words left or right by eight bits (getting zeros always). When you lor
N 8-bit words, you will still get an 8-bit word. Finally, you assing the dest
variable (which is a 32-bit register) an 8-bit word. And booms.
Instead of using shifts and ors, you can use extract
and concat
which lets you express the semantics exactly as in the reference manual.
Style notes:
-
Do not leave
in
) in
,)
, or any other purely grammatical/service words on a single line. Each line of code, shall be a line of code. The exception isbegin/end
and other structural expressions, such as while, for, etc -
Do not put superfluous parentheses. They clutter the code and confuse as it is not clear what were the author's intentions.
In this case, parenthesis around extract are acceptable, but keep in mind that function applications bind tighter than infix operators. Since in this case the infix operator is fully made of ASCII characters, it is really easy to confuse it with function application especially when there is no syntax highlighting, e.g., extract 7 0 s lsl i8
is hard to parse without highlighting, thoug it has the same (extract 7 0 s) lsl i8
meaning.
lib/arm/arm_lifter.ml
Outdated
let rev = | ||
let open Bil in | ||
s lsl i24 lor | ||
s lsr i24 lor | ||
(s land umask) lsr i8 lor | ||
(s land lmask) lsl i8 | ||
(extract 23 16 s) lsr i8 lor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see the comment about REV16, it is also applicable here. And please, also just use a concatenation of 4 bytes, obtained with extract
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the inline comments.
Also, it is advised to run tests locally. E.g., make test
for unit tests (provided that you passed --with-tests
to the ./configure
script), and make check
for the functional tests. This will help you to catch bugs earlier and enable shorter iterations. And remove stress from Travis, which is currently on the edge of collapsing (in other words it doesn't really work).
lib/arm/arm_lifter.ml
Outdated
(s land umask) lsr i8 lor | ||
(s land lmask) lsl i8 | ||
in | ||
let rev = Bil.(concat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all, the code is not indented correctly. Second, and most importantly, you can use the [(^)] operator to make your code much more readable, e.g.,
let rev = Bil.(extract 7 0 s ^
extract 15 8 s ^
extract 23 16 s ^
extract 31 24 s) in
lib/arm/arm_lifter.ml
Outdated
exec [assn (Env.of_reg dest) rev] cond | ||
| `REV16, [|`Reg dest; src; cond; _|] -> | ||
let s = exp_of_op src in | ||
let i16 = int32 16 in | ||
let rev = Bil.(s lsl i16 lor s lsr i16) in | ||
let rev = Bil.(concat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the same is true for this snippet, use ^
for concatenation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now it looks awesome!
thanks for fixing it and making the code nicer, good job! |
* fix rev16 instruction * use extract in place of bitmask * use 'concat' and 'extract' syntax * use better sematics Co-authored-by: Ivan Gotovchits <ivg@ieee.org>
Hopefully this PR will fix #1127, not sure if this would affects related tests.