Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Zwinkau
libfirm
Commits
ab1b5847
Commit
ab1b5847
authored
Aug 01, 2007
by
Michael Beck
Browse files
fixed broken get_tarval_sub_bits() implementation: now correctly clip number of bits
[r15417]
parent
bddef28a
Changes
3
Hide whitespace changes
Inline
Side-by-side
ir/tv/strcalc.c
View file @
ab1b5847
...
...
@@ -1268,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
;
}
...
...
ir/tv/strcalc.h
View file @
ab1b5847
...
...
@@ -189,6 +189,14 @@ int sc_get_lowest_set_bit(const void *value);
int
sc_is_zero
(
const
void
*
value
);
int
sc_is_negative
(
const
void
*
value
);
int
sc_had_carry
(
void
);
/**
* Return the bits of a tarval at a given byte-offset.
*
* @param value the value
* @param len number of valid bits in the value
* @param byte_ofs the byte offset
*/
unsigned
char
sc_sub_bits
(
const
void
*
value
,
int
len
,
unsigned
byte_ofs
);
/**
...
...
ir/tv/tv.c
View file @
ab1b5847
...
...
@@ -1479,7 +1479,7 @@ char *get_tarval_bitpattern(tarval *tv) {
unsigned
char
get_tarval_sub_bits
(
tarval
*
tv
,
unsigned
byte_ofs
)
{
switch
(
get_mode_arithmetic
(
tv
->
mode
))
{
case
irma_twos_complement
:
return
sc_sub_bits
(
tv
->
value
,
tv
->
length
,
byte_ofs
);
return
sc_sub_bits
(
tv
->
value
,
get_mode_size_bits
(
tv
->
mode
)
,
byte_ofs
);
case
irma_ieee754
:
return
fc_sub_bits
(
tv
->
value
,
get_mode_size_bits
(
tv
->
mode
),
byte_ofs
);
default:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment