Minor changes
[libfirm] / ir / tv / strcalc.c
index e893bc6..10bf885 100644 (file)
@@ -924,10 +924,11 @@ int sc_get_buffer_length(void) {
 /**
  * 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)) {
@@ -1267,13 +1268,17 @@ unsigned char sc_sub_bits(const void *value, int len, unsigned byte_ofs) {
        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;
 }
 
@@ -1579,9 +1584,9 @@ void sc_mul(const void *value1, const void *value2, void *buffer) {
        }
 }
 
-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;
@@ -1589,14 +1594,13 @@ int 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, 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) {