Skip to content

Conversation

@lum1n0us
Copy link
Contributor

No description provided.

@lum1n0us lum1n0us force-pushed the impl_bitwise branch 2 times, most recently from ca3bbca to 46dcee5 Compare April 19, 2022 12:12
@lum1n0us
Copy link
Contributor Author

It is an ugly version but workable. Still looking for a graceful way.

Comment on lines 212 to 224
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;
}
Copy link
Collaborator

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)?

Copy link
Contributor Author

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

Copy link
Collaborator

@wenyongh wenyongh Apr 20, 2022

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;
}

Copy link
Contributor Author

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)) {
Copy link
Collaborator

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.

@lum1n0us lum1n0us force-pushed the impl_bitwise branch 3 times, most recently from 54c45c8 to 2097080 Compare April 21, 2022 01:40

DEF_UNI_INT_CONST_OPS(xor)
{
if (left == right) {
Copy link
Collaborator

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);
Copy link
Collaborator

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;

@wenyongh wenyongh merged commit 0c2cac4 into bytecodealliance:dev/fast_jit Apr 21, 2022
@lum1n0us lum1n0us deleted the impl_bitwise branch May 10, 2022 14:42
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.

2 participants