/**
* Do sign extension if the mode is signed, otherwise to zero extension.
*/
-void sign_extend(char *calc_buffer, ir_mode *mode) {
- int bits = get_mode_size_bits(mode) - 1;
- int nibble = bits >> 2;
- int max = max_digit[bits & 3];
+void sign_extend(void *buffer, ir_mode *mode) {
+ char *calc_buffer = buffer;
+ int bits = get_mode_size_bits(mode) - 1;
+ int nibble = bits >> 2;
+ int max = max_digit[bits & 3];
int i;
if (mode_is_signed(mode)) {
unsigned char res;
/* the current scheme uses one byte to store a nibble */
- if (nibble_ofs >= len)
+ if (4 * nibble_ofs >= len)
return 0;
res = _val(val[nibble_ofs]);
- if (len > nibble_ofs + 1)
+ if (len > 4 * (nibble_ofs + 1))
res |= _val(val[nibble_ofs + 1]) << 4;
+ /* kick bits outsize */
+ if (len < 8*byte_ofs) {
+ res &= 0xFF >> (8*byte_ofs - len);
+ }
return res;
}
}
}
-int sc_div(const void *value1, const void *value2, void *buffer) {
+void sc_div(const void *value1, const void *value2, void *buffer) {
/* temp buffer holding unused result of divmod */
- char *mod_res = alloca(calc_buffer_size);
+ char *unused_res = alloca(calc_buffer_size);
CLEAR_BUFFER(calc_buffer);
carry_flag = 0;
DEBUGPRINTF_COMPUTATION(("%s / ", sc_print_hex(value1)));
DEBUGPRINTF_COMPUTATION(("%s -> ", sc_print_hex(value2)));
- _divmod(value1, value2, calc_buffer, mod_res);
+ _divmod(value1, value2, calc_buffer, unused_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) {
CLEAR_BUFFER(calc_buffer);
carry_flag = 0;
- DEBUGPRINTF_COMPUTATION(("%s ", sc_print_hex(value1)));
+ DEBUGPRINTF_COMPUTATION(("%s %% ", sc_print_hex(value1)));
DEBUGPRINTF_COMPUTATION(("%s -> ", sc_print_hex(value2)));
_divmod(value1, value2, unused_res, calc_buffer);