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
64790ad7
Commit
64790ad7
authored
Jan 25, 2015
by
Christoph Mallon
Browse files
bitfiddle: Remove the unused function add_saturated().
parent
8aa9e4d9
Changes
1
Hide whitespace changes
Inline
Sidebyside
ir/adt/bitfiddle.h
View file @
64790ad7
...
...
@@ 19,38 +19,6 @@
#include
"compiler.h"
/**
* Add saturated.
* @param x Summand 1.
* @param y Summand 2.
* @return x + y or INT_MAX/INT_MIN if an overflow occurred and x,y was
* positive/negative.
*
* @note See hacker's delight, page 27.
*/
static
inline
int
add_saturated
(
int
x
,
int
y
)
{
int
sum
=
x
+
y
;
/*
An overflow occurs, if the sign of the both summands is equal
and the one of the sum is different from the summand's one.
The sign bit is 1, if an overflow occurred, 0 otherwise.
int overflow = ~(x ^ y) & (sum ^ x);
*/
int
overflow
=
(
x
^
sum
)
&
(
y
^
sum
);
/*
The infinity to use.
Make a mask of the sign bit of x and y (they are the same if an
overflow occurred).
INT_MIN == ~INT_MAX, so if the sign was negative, INT_MAX becomes
INT_MIN.
*/
int
inf
=
(
x
>>
(
sizeof
(
x
)
*
8

1
))
^
INT_MAX
;
return
overflow
<
0
?
inf
:
sum
;
}
/**
* Compute the count of set bits in a 32bit word.
* @param x A 32bit word.
...
...
Write
Preview
Supports
Markdown
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