Skip to content

Commit

Permalink
core: BitVector now returns 0 if bitsize is 0, use different way to c…
Browse files Browse the repository at this point in the history
…heck for 0xff... for simplify visitor ; cmake: remove llvm external project, hardcode 64-bit backend for llvm bootstrap script
  • Loading branch information
wisk committed May 31, 2016
1 parent 5ac9e6c commit f848cfe
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
9 changes: 0 additions & 9 deletions CMakeLists.txt
Expand Up @@ -124,16 +124,7 @@ endif()
## LLVM

if (MEDUSA_BUILD_WITH_LLVM)
ExternalProject_add(llvm
PREFIX llvm
GIT_REPOSITORY https://github.com/llvm-mirror/llvm
GIT_TAG origin/release_37

SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/llvm"
INSTALL_DIR "${CMAKE_BINARY_DIR}"
)

ExternalProject_get_property(llvm INSTALL_DIR)
#set(LLVM_ROOT ${INSTALL_DIR})
#set(LLVM_ROOT_DEBUG ${INSTALL_DIR})
#set(LLVM_ROOT_RELEASE ${INSTALL_DIR})
Expand Down
10 changes: 5 additions & 5 deletions bootstrap_use_llvm.bat
@@ -1,18 +1,18 @@
cd deps
"C:\Program Files (x86)\Git\bin\git.exe" clone https://github.com/llvm-mirror/llvm
"C:\Program Files\Git\bin\git.exe" clone https://github.com/llvm-mirror/llvm
cd llvm
"C:\Program Files (x86)\Git\bin\git.exe" checkout release_37
"C:\Program Files\Git\bin\git.exe" checkout release_37
mkdir build_vs14_x64_debug
mkdir build_vs14_x64_release

cd build_vs14_x64_debug
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=../install_vs14_x64_debug -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_BUILD_EXAMPLES:BOOL=FALSE ..
cmake -G"Visual Studio 14 Win64" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=../install_vs14_x64_debug -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_BUILD_EXAMPLES:BOOL=FALSE ..
msbuild INSTALL.vcxproj /p:Configuration=Debug
cd ..

cd build_vs14_x64_release
cmake -DCMAKE_BUILD_TYPE=release -DCMAKE_INSTALL_PREFIX:PATH=../install_vs14_x64_release -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_BUILD_EXAMPLES:BOOL=FALSE ..
cmake -G"Visual Studio 14 Win64" -DCMAKE_BUILD_TYPE=release -DCMAKE_INSTALL_PREFIX:PATH=../install_vs14_x64_release -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_BUILD_EXAMPLES:BOOL=FALSE ..
msbuild INSTALL.vcxproj /p:Configuration=Release
cd ..

cd ..
cd ..\..
2 changes: 1 addition & 1 deletion samples
12 changes: 8 additions & 4 deletions src/core/expression_visitor.cpp
Expand Up @@ -1966,9 +1966,13 @@ Expression::SPType SimplifyVisitor::VisitBinaryOperation(BinaryOperationExpressi
return (spBv != nullptr && spBv->GetInt().GetUnsignedValue() == 0x1);
};

auto TestMinusOne = [](BitVectorExpression::SPType spBv)
auto TestAllOnes = [](BitVectorExpression::SPType spBv)
{
return (spBv != nullptr && spBv->GetInt().GetSignedValue() == -1);
if (spBv == nullptr)
return false;
BitVector Mask(spBv->GetBitSize(), 0);
Mask -= BitVector(spBv->GetBitSize(), 1);
return spBv->GetInt().GetUnsignedValue() == Mask.GetUnsignedValue();
};

switch (spBinOpExpr->GetOperation())
Expand Down Expand Up @@ -2007,9 +2011,9 @@ Expression::SPType SimplifyVisitor::VisitBinaryOperation(BinaryOperationExpressi
// a & -1 = a // -1 & b = b
case OperationExpression::OpAnd:
{
if (TestMinusOne(spBvLeft))
if (TestAllOnes(spBvLeft))
return spRight;
if (TestMinusOne(spBvRight))
if (TestAllOnes(spBvRight))
return spLeft;
break;
}
Expand Down
6 changes: 6 additions & 0 deletions src/core/types.cpp
Expand Up @@ -44,6 +44,9 @@ void BitVector::BitCast(u16 NewBitSize)

ap_int BitVector::GetSignedValue(void) const
{
if (m_BitSize == 0)
return 0;

// If the value is positive, we don't need to do anything
if (!((GetUnsignedValue() >> (m_BitSize - 1)) & 1))
return m_Value;
Expand All @@ -55,6 +58,9 @@ ap_int BitVector::GetSignedValue(void) const

ap_uint BitVector::GetUnsignedValue(void) const
{
if (m_BitSize == 0)
return 0;

// If the value is positive, we don't need to do anything
if (!m_Value.backend().sign())
return m_Value;
Expand Down

0 comments on commit f848cfe

Please sign in to comment.