Commit cd1f3f0c authored by Michael Beck's avatar Michael Beck
Browse files

sc_div() returns non-zero if divide without remainder

[r15301]
parent b2c0a7b7
......@@ -1579,9 +1579,9 @@ void sc_mul(const void *value1, const void *value2, void *buffer) {
}
}
void sc_div(const void *value1, const void *value2, void *buffer) {
int sc_div(const void *value1, const void *value2, void *buffer) {
/* temp buffer holding unused result of divmod */
char *unused_res = alloca(calc_buffer_size);
char *mod_res = alloca(calc_buffer_size);
CLEAR_BUFFER(calc_buffer);
carry_flag = 0;
......@@ -1589,13 +1589,14 @@ void sc_div(const void *value1, const void *value2, void *buffer) {
DEBUGPRINTF_COMPUTATION(("%s / ", sc_print_hex(value1)));
DEBUGPRINTF_COMPUTATION(("%s -> ", sc_print_hex(value2)));
_divmod(value1, value2, calc_buffer, unused_res);
_divmod(value1, value2, calc_buffer, mod_res);
DEBUGPRINTF_COMPUTATION(("%s\n", sc_print_hex(calc_buffer)));
if ((buffer != NULL) && (buffer != calc_buffer)) {
memcpy(buffer, calc_buffer, calc_buffer_size);
}
return sc_is_zero(mod_res);
}
void sc_mod(const void *value1, const void *value2, void *buffer) {
......
......@@ -87,23 +87,77 @@ enum base_t {
SC_BIN /**< binary output */
};
/*
* Interface
/**
* buffer = value1 + value2
*/
void sc_add(const void *value1, const void *value2, void *buffer);
/**
* buffer = value1 - value2
*/
void sc_sub(const void *value1, const void *value2, void *buffer);
/**
* buffer = -value
*/
void sc_neg(const void *value, void *buffer);
/**
* buffer = value1 & value2
*/
void sc_and(const void *value1, const void *value2, void *buffer);
/**
* buffer = value1 | value2
*/
void sc_or(const void *value1, const void *value2, void *buffer);
/**
* buffer = value1 ^ value2
*/
void sc_xor(const void *value1, const void *value2, void *buffer);
void sc_not(const void *value1, void *buffer);
/**
* buffer = ~value
*/
void sc_not(const void *value, void *buffer);
/**
* buffer = value1 * value2
*/
void sc_mul(const void *value1, const void *value2, void *buffer);
void sc_div(const void *value1, const void *value2, void *buffer);
/**
* buffer = value1 / value2
*
* @return non-zero if the remainder is null.
*/
int sc_div(const void *value1, const void *value2, void *buffer);
/**
* buffer = value1 % value2
*/
void sc_mod(const void *value1, const void *value2, void *buffer);
void sc_shl(const void *val1, const void *val2, int radius, int sign, void *buffer);
void sc_shr(const void *val1, const void *val2, int radius, int sign, void *buffer);
void sc_shrs(const void *val1, const void *val2, int radius, int sign, void *buffer);
void sc_rot(const void *val1, const void *val2, int radius, int sign, void *buffer);
/**
* buffer = value1 << value2
*/
void sc_shl(const void *value1, const void *value2, int radius, int sign, void *buffer);
/**
* buffer = value1 >>u value2
*/
void sc_shr(const void *value1, const void *value2, int radius, int sign, void *buffer);
/**
* buffer = value1 >>s value2
*/
void sc_shrs(const void *value1, const void *value2, int radius, int sign, void *buffer);
/**
* buffer = value1 <<>> value2
*/
void sc_rot(const void *value1, const void *value2, int radius, int sign, void *buffer);
/*
* function declarations
......@@ -127,6 +181,9 @@ long sc_val_to_long(const void *val);
void sc_min_from_bits(unsigned int num_bits, unsigned int sign, void *buffer);
void sc_max_from_bits(unsigned int num_bits, unsigned int sign, void *buffer);
/**
* Compares val1 and val2
*/
int sc_comp(const void *val1, const void *val2);
int sc_get_highest_set_bit(const void *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