;
; hppa/core.jit
;
;
; $Id: core.jit 11521 2006-02-13 14:04:12Z rafl $
;

Parrot_end {
    jit_emit_end(NATIVECODE);
}

Parrot_set_i_ic {
    if (MAP[1]) {
        jit_emit_mov_ri_i(NATIVECODE, MAP[1], *INT_CONST[2]);
    }
    else {
        jit_emit_mov_ri_i(NATIVECODE, ISR1, *INT_CONST[2]);
        jit_emit_mov_mr_i(NATIVECODE, ROFFS_INT(1), ISR1); 
    }
}

Parrot_set_i_i {
    if (MAP[1] && MAP[2]) {
        jit_emit_mov_rr(NATIVECODE, MAP[1], MAP[2]);
    }
    else if (MAP[1]) {
        jit_emit_mov_rm_i(NATIVECODE, MAP[1], ROFFS_INT(2)); 
    } 
    else if (MAP[2]) {
        jit_emit_mov_mr_i(NATIVECODE, ROFFS_INT(1), MAP[2]); 
    }
    else {
        jit_emit_mov_rm_i(NATIVECODE, ISR1, ROFFS_INT(2)); 
        jit_emit_mov_mr_i(NATIVECODE, ROFFS_INT(1), ISR1); 
    }
}

TEMPLATE Parrot_binop_x_x {
    if (MAP[1] && MAP[2]) {
        jit_emit_<op>_rrr(NATIVECODE, MAP[1], MAP[1], MAP[2]);
    }
    else if (MAP[1]) {
        jit_emit_mov_rm<_N>(NATIVECODE, <s1>, ROFFS_<T>(2)); 
        jit_emit_<op>_rrr(NATIVECODE, MAP[1], MAP[1], <s1>);
    }
    else if (MAP[2]) {
        jit_emit_mov_rm<_N>(NATIVECODE, <s1>, ROFFS_<T>(1));
        jit_emit_<op>_rrr(NATIVECODE, <s1>, <s1>, MAP[2]);
        jit_emit_mov_mr<_N>(NATIVECODE, ROFFS_<T>(1), <s1>);
    }
    else {
        jit_emit_mov_rm<_N>(NATIVECODE, <s1>, ROFFS_<T>(1));
        jit_emit_mov_rm<_N>(NATIVECODE, <s2>, ROFFS_<T>(2));
        jit_emit_<op>_rrr(NATIVECODE, <s1>, <s2>, <s1>);
        jit_emit_mov_mr<_N>(NATIVECODE, ROFFS_<T>(1), <s1>);
    }
}

TEMPLATE Parrot_binop_x_x_x {
    if (MAP[1] && MAP[2] && MAP[3]) {
        jit_emit_<op>_rrr(NATIVECODE, MAP[1], MAP[2], MAP[3]);
    }
    else if (MAP[1] && MAP[2]) {
        jit_emit_mov_rm<_N>(NATIVECODE, <s1>, ROFFS_<T>(3)); 
        jit_emit_<op>_rrr(NATIVECODE, MAP[1], MAP[2], <s1>);
    }
    else if (MAP[1] && MAP[3]) {
        jit_emit_mov_rm<_N>(NATIVECODE, <s1>, ROFFS_<T>(2));
        jit_emit_<op>_rrr(NATIVECODE, MAP[1], <s1>, MAP[3]);
    }
    else if (MAP[2] && MAP[3]) {
        jit_emit_<op>_rrr(NATIVECODE, <s1>, MAP[2], MAP[3]);
        jit_emit_mov_mr<_N>(NATIVECODE, ROFFS_<T>(3), <s1>);
    }
    else if (MAP[1]) {
        jit_emit_mov_rm<_N>(NATIVECODE, <s1>, ROFFS_<T>(3));
        jit_emit_mov_rm<_N>(NATIVECODE, <s2>, ROFFS_<T>(2));
        jit_emit_<op>_rrr(NATIVECODE, MAP[1], <s2>, <s1>);
    }
    else if (MAP[2]) {
        jit_emit_mov_rm<_N>(NATIVECODE, <s1>, ROFFS_<T>(3));
        jit_emit_<op>_rrr(NATIVECODE, <s1>, MAP[2], <s1>);
        jit_emit_mov_mr<_N>(NATIVECODE, ROFFS_<T>(1), <s1>);
    }
    else if (MAP[3]) {
        jit_emit_mov_rm<_N>(NATIVECODE, <s1>, ROFFS_<T>(2));
        jit_emit_<op>_rrr(NATIVECODE, <s1>, <s1>, MAP[3]);
        jit_emit_mov_mr<_N>(NATIVECODE, ROFFS_<T>(1), <s1>);
    }
    else {
        jit_emit_mov_rm<_N>(NATIVECODE, <s1>, ROFFS_<T>(3));
        jit_emit_mov_rm<_N>(NATIVECODE, <s2>, ROFFS_<T>(2));
        jit_emit_<op>_rrr(NATIVECODE, <s1>, <s2>, <s1>);
        jit_emit_mov_mr<_N>(NATIVECODE, ROFFS_<T>(1), <s1>);
    }
}

Parrot_band_i_i {
    Parrot_binop_x_x s/<_N>/_i/ s/<op>/and/ s/<s1>/ISR1/ s/<s2>/ISR2/ s/<T>/INT/
}

Parrot_bor_i_i {
    Parrot_binop_x_x s/<_N>/_i/ s/<op>/or/ s/<s1>/ISR1/ s/<s2>/ISR2/ s/<T>/INT/
}

Parrot_bxor_i_i {
    Parrot_binop_x_x s/<_N>/_i/ s/<op>/xor/ s/<s1>/ISR1/ s/<s2>/ISR2/ s/<T>/INT/
}

Parrot_add_i_i {
    Parrot_binop_x_x s/<_N>/_i/ s/<op>/add/ s/<s1>/ISR1/ s/<s2>/ISR2/ s/<T>/INT/
}

Parrot_sub_i_i {
    Parrot_binop_x_x s/<_N>/_i/ s/<op>/sub/ s/<s1>/ISR1/ s/<s2>/ISR2/ s/<T>/INT/
}

Parrot_band_i_i_i {
    Parrot_binop_x_x_x s/<_N>/_i/ s/<op>/and/ s/<s1>/ISR1/ s/<s2>/ISR2/ s/<T>/INT/
}

Parrot_bor_i_i_i {
    Parrot_binop_x_x_x s/<_N>/_i/ s/<op>/or/ s/<s1>/ISR1/ s/<s2>/ISR2/ s/<T>/INT/
}

Parrot_bxor_i_i_i {
    Parrot_binop_x_x_x s/<_N>/_i/ s/<op>/xor/ s/<s1>/ISR1/ s/<s2>/ISR2/ s/<T>/INT/
}

Parrot_add_i_i_i {
    Parrot_binop_x_x_x s/<_N>/_i/ s/<op>/add/ s/<s1>/ISR1/ s/<s2>/ISR2/ s/<T>/INT/
}

Parrot_sub_i_i_i {
    Parrot_binop_x_x_x s/<_N>/_i/ s/<op>/sub/ s/<s1>/ISR1/ s/<s2>/ISR2/ s/<T>/INT/
}

TEMPLATE Parrot_ifunless_i_ic {
    if (!MAP[1]) {
        jit_emit_mov_rm_i(NATIVECODE, ISR1, ROFFS_INT(1));
    }
    jit_emit_bc(jit_info, ISR1, r0, <COND>, *INT_CONST[2]);
}

Parrot_if_i_ic {
    Parrot_ifunless_i_ic s/<COND>/emit_EQ/
}

Parrot_unless_i_ic {
    Parrot_ifunless_i_ic s/<COND>/emit_NE/
}
