-
Notifications
You must be signed in to change notification settings - Fork 749
IRs for bitwise #1101
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
IRs for bitwise #1101
Conversation
ca3bbca to
46dcee5
Compare
|
It is an ugly version but workable. Still looking for a graceful way. |
| if (jit_reg_is_const(left) && jit_reg_is_const(right)) { | ||
| if (is_i32) { | ||
| int32 left_val = jit_cc_get_const_I32(cc, left); | ||
| int32 right_val = jit_cc_get_const_I32(cc, right); | ||
| res = NEW_CONST(I32, left_val * right_val); | ||
| } | ||
| else { | ||
| int64 left_val = jit_cc_get_const_I64(cc, left); | ||
| int64 right_val = jit_cc_get_const_I64(cc, right); | ||
| res = NEW_CONST(I64, left_val * right_val); | ||
| } | ||
| goto shortcut; | ||
| } |
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.
How about define these code piece to a macro, e.g. CHECK_CONST(left, right, op)?
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.
MACROs make debugging in GDB/LLDB hard. I prefer using them less
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.
Yes, how about adding a function to do that:
bool check_const_and_operate(JitReg left, JitReg right, ArithOp op, JitReg *p_res)
{
if (jit_reg_is_const(left) && jit_reg_is_const(right)) {
if (is_i32) {
int32 left_val = jit_cc_get_const_I32(cc, left);
int32 right_val = jit_cc_get_const_I32(cc, right);
int32 res_val;
switch (op) {
case ADD: res_val = left_val + right_val;
break;
...
}
res = NEW_CONST(I32, res_val);
}
else {
int64 left_val = jit_cc_get_const_I64(cc, left);
int64 right_val = jit_cc_get_const_I64(cc, right);
...
}
*p_res = res;
return true;
}
return false;
}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.
Sure. working on it.
| } | ||
| } | ||
|
|
||
| if (jit_reg_is_const(left)) { |
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.
This code piece can not be executed as the code above has handled all possible branches. How about moving the code into compile_int_div_no_check, it doesn't need to check exception again as possible exception checks have been done before calling it.
54c45c8 to
2097080
Compare
|
|
||
| DEF_UNI_INT_CONST_OPS(xor) | ||
| { | ||
| if (left == right) { |
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.
Had better compare with the actual const values but not JitReg ?
| DEF_UNI_INT_CONST_OPS(xor) | ||
| { | ||
| if (left == right) { | ||
| return is_i32 ? NEW_CONST(I32, 0) : NEW_CONST(I64, 0); |
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.
If left_val == 0, left xor right = right, do we want to add the optimization?
if (IS_CONST_ZERO(left)) return right;
if (IS_CONST_ZERO(right)) return left;
No description provided.