-
Notifications
You must be signed in to change notification settings - Fork 274
bitreverse_exprt: Expression to reverse the order of bits #6581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
unsigned char __builtin_bitreverse8(char, char); | ||
|
||
int main() | ||
{ | ||
return __builtin_bitreverse8(1, 2); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CORE | ||
bitreverse-typeconflict.c | ||
file bitreverse-typeconflict.c line 5 function main: error: __builtin_bitreverse8 expects one operand | ||
^EXIT=6$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include <assert.h> | ||
#include <stdint.h> | ||
|
||
#define test_bit_reverse(W) \ | ||
uint##W##_t test_bit_reverse##W(uint##W##_t v) \ | ||
{ \ | ||
uint##W##_t result = 0; \ | ||
int i; \ | ||
for(i = 0; i < W; i++) \ | ||
{ \ | ||
if(v & (1ULL << i)) \ | ||
result |= 1ULL << (W - i - 1); \ | ||
} \ | ||
return result; \ | ||
} \ | ||
int dummy_for_semicolon##W | ||
|
||
test_bit_reverse(8); | ||
test_bit_reverse(16); | ||
test_bit_reverse(32); | ||
test_bit_reverse(64); | ||
|
||
#ifndef __clang__ | ||
unsigned char __builtin_bitreverse8(unsigned char); | ||
unsigned short __builtin_bitreverse16(unsigned short); | ||
unsigned int __builtin_bitreverse32(unsigned int); | ||
unsigned long long __builtin_bitreverse64(unsigned long long); | ||
#endif | ||
|
||
void check_8(void) | ||
{ | ||
uint8_t op; | ||
assert(__builtin_bitreverse8(op) == test_bit_reverse8(op)); | ||
assert(__builtin_bitreverse8(1) == 0x80); | ||
} | ||
|
||
void check_16(void) | ||
{ | ||
uint16_t op; | ||
assert(__builtin_bitreverse16(op) == test_bit_reverse16(op)); | ||
assert(__builtin_bitreverse16(1) == 0x8000); | ||
} | ||
|
||
void check_32(void) | ||
{ | ||
uint32_t op; | ||
assert(__builtin_bitreverse32(op) == test_bit_reverse32(op)); | ||
assert(__builtin_bitreverse32(1) == 0x80000000); | ||
} | ||
|
||
void check_64(void) | ||
{ | ||
uint64_t op; | ||
assert(__builtin_bitreverse64(op) == test_bit_reverse64(op)); | ||
assert(__builtin_bitreverse64(1) == 0x8000000000000000ULL); | ||
} | ||
|
||
int main(void) | ||
{ | ||
check_8(); | ||
check_16(); | ||
check_32(); | ||
check_64(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CORE thorough-paths | ||
bitreverse.c | ||
|
||
^VERIFICATION SUCCESSFUL$ | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ Author: Daniel Kroening, [email protected] | |
#include "arrays.h" | ||
|
||
class array_comprehension_exprt; | ||
class bitreverse_exprt; | ||
class bswap_exprt; | ||
class byte_extract_exprt; | ||
class byte_update_exprt; | ||
|
@@ -192,6 +193,7 @@ class boolbvt:public arrayst | |
virtual bvt convert_power(const binary_exprt &expr); | ||
virtual bvt convert_function_application( | ||
const function_application_exprt &expr); | ||
virtual bvt convert_bitreverse(const bitreverse_exprt &expr); | ||
|
||
virtual exprt make_bv_expr(const typet &type, const bvt &bv); | ||
virtual exprt make_free_bv_expr(const typet &type); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/*******************************************************************\ | ||
|
||
Module: | ||
|
||
Author: Michael Tautschnig | ||
|
||
\*******************************************************************/ | ||
|
||
#include "boolbv.h" | ||
|
||
#include <util/bitvector_expr.h> | ||
|
||
bvt boolbvt::convert_bitreverse(const bitreverse_exprt &expr) | ||
{ | ||
const std::size_t width = boolbv_width(expr.type()); | ||
if(width == 0) | ||
return conversion_failed(expr); | ||
|
||
bvt bv = convert_bv(expr.op(), width); | ||
|
||
std::reverse(bv.begin(), bv.end()); | ||
|
||
return bv; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.