Commit 753094fe authored by Michael Beck's avatar Michael Beck
Browse files

tarval_divmod added

[r15669]
parent 64780046
......@@ -1622,6 +1622,18 @@ void sc_mod(const void *value1, const void *value2, void *buffer) {
}
}
void sc_divmod(const void *value1, const void *value2, void *div_buffer, void *mod_buffer) {
CLEAR_BUFFER(calc_buffer);
carry_flag = 0;
DEBUGPRINTF_COMPUTATION(("%s %% ", sc_print_hex(value1)));
DEBUGPRINTF_COMPUTATION(("%s -> ", sc_print_hex(value2)));
_divmod(value1, value2, div_buffer, mod_buffer);
DEBUGPRINTF_COMPUTATION(("%s:%s\n", sc_print_hex(div_buffer), sc_print_hex(mod_buffer)));
}
void sc_shl(const void *val1, const void *val2, int radius, int sign, void *buffer) {
long offset = sc_val_to_long(val2);
......
......@@ -137,6 +137,12 @@ void sc_div(const void *value1, const void *value2, void *buffer);
*/
void sc_mod(const void *value1, const void *value2, void *buffer);
/**
* div_buffer = value1 / value2
* mod_buffer = value1 % value2
*/
void sc_divmod(const void *value1, const void *value2, void *div_buffer, void *mod_buffer);
/**
* buffer = value1 << value2
*/
......
......@@ -1133,6 +1133,33 @@ tarval *tarval_mod(tarval *a, tarval *b) {
return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
}
/*
* integer division AND remainder
* overflow is impossible, but look out for division by zero
*/
tarval *tarval_divmod(tarval *a, tarval *b, tarval **mod) {
int len = sc_get_buffer_length();
char *div_res = alloca(len);
char *mod_res = alloca(len);
assert(a);
assert(b);
assert((a->mode == b->mode) && mode_is_int(a->mode));
if (get_mode_n_vector_elems(a->mode) > 1) {
/* vector arithmetic not implemented yet */
return tarval_bad;
}
/* x/0 error */
if (b == get_mode_null(b->mode)) return tarval_bad;
/* modes of a,b are equal */
sc_divmod(a->value, b->value, div_res, mod_res);
*mod = get_tarval(mod_res, len, a->mode);
return get_tarval(div_res, len, a->mode);
}
/*
* absolute value
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment