Skip to content

Commit

Permalink
Merge branch 'lailongwei:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
lgc1112 authored Nov 24, 2023
2 parents 94ca0a8 + 4abcec5 commit 4d1fdcb
Show file tree
Hide file tree
Showing 280 changed files with 1,219 additions and 32,549 deletions.
32 changes: 25 additions & 7 deletions .github/workflows/linux-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,25 @@ jobs:
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."

- name: install deps
run: yum install -y openssl-devel wget tar gcc gcc-c++ libuuid libuuid-devel automake autoconf libtool make

- name : install cmake
run: wget https://github.com/Kitware/CMake/releases/download/v3.27.0/cmake-3.27.0-linux-x86_64.tar.gz && tar -zxvf cmake-3.27.0-linux-x86_64.tar.gz && mv cmake-3.27.0-linux-x86_64 /usr/local/cmake && ln -s /usr/local/cmake/bin/* /usr/local/bin/

- name: install git
run: |
yum install -y https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm
yum install -y git
echo "git version:`git --version`"
- name: Check out repository code
uses: actions/checkout@v3
with:
submodules: "true"

- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."

- name: install deps
run: yum install -y git openssl-devel wget tar gcc gcc-c++ libuuid libuuid-devel automake autoconf libtool make

- name : install cmake
run: wget https://github.com/Kitware/CMake/releases/download/v3.27.0/cmake-3.27.0-linux-x86_64.tar.gz && tar -zxvf cmake-3.27.0-linux-x86_64.tar.gz && mv cmake-3.27.0-linux-x86_64 /usr/local/cmake && ln -s /usr/local/cmake/bin/* /usr/local/bin/

- name: Compile core lib code
run: |
Expand All @@ -35,9 +43,19 @@ jobs:
- name: Compile test code
run: |
# make test config=debug64 -j4
make test config=debug64 -j4
make test config=release64 -j4
- name: Compile pyllbc lib code
run: |
make py_wrap config=debug64 -j4
make py_wrap config=release64 -j4
- name: Compile lullbc lib code
run: |
make lu_wrap config=debug64 -j4
make py_wrap config=release64 -j4
- name: Build all target by cmake
run: |
mkdir cmake_build
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/macos-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ jobs:
- name: Compile test code
run: |
# make test config=debug64 -j4
make test config=release64 -j4
- name: Build all target by cmake
Expand Down
18 changes: 15 additions & 3 deletions .github/workflows/windows-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,25 @@ jobs:
# msbuild.exe build/vs2019/llbc_vs2019.sln -p:Configuration=debug64 -p:Platform=x64 -t:testsuite
msbuild.exe build/vs2019/llbc_vs2019.sln -p:Configuration=release64 -p:Platform=x64 -t:testsuite
# - name: Compile pyllbc lib code
# run: |
# # msbuild.exe build/vs2019/llbc_vs2019.sln -p:Configuration=debug32 -p:Platform=x86 -t:pyllbc
# # msbuild.exe build/vs2019/llbc_vs2019.sln -p:Configuration=release32 -p:Platform=x86 -t:pyllbc
# # msbuild.exe build/vs2019/llbc_vs2019.sln -p:Configuration=debug64 -p:Platform=x64 -t:pyllbc
# msbuild.exe build/vs2019/llbc_vs2019.sln -p:Configuration=release64 -p:Platform=x64 -t:pyllbc
#
# - name: Compile lullbc lib code
# run: |
# # msbuild.exe build/vs2019/llbc_vs2019.sln -p:Configuration=debug32 -p:Platform=x86 -t:lullbc
# # msbuild.exe build/vs2019/llbc_vs2019.sln -p:Configuration=release32 -p:Platform=x86 -t:lullbc
# # msbuild.exe build/vs2019/llbc_vs2019.sln -p:Configuration=debug64 -p:Platform=x64 -t:lullbc
# msbuild.exe build/vs2019/llbc_vs2019.sln -p:Configuration=release64 -p:Platform=x64 -t:lullbc

- name: Build all target by cmake
run: |
mkdir cmake_build
cd cmake_build
cmake ..
cmake --build . --config Release -j
- run: echo "🍏 This job's status is ${{ job.status }}."


- run: echo "🍏 This job's status is ${{ job.status }}."
2 changes: 1 addition & 1 deletion llbc/include/llbc/common/BasicDataType.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ __LLBC_NS_BEGIN
typedef unsigned long ulong;
typedef unsigned long long uint64;
typedef long double ldouble;
typedef unsigned short wchar;
typedef char16_t wchar;
#else // LLBC_TARGET_PLATFORM_WIN32
typedef __int8 sint8;
typedef __int16 sint16;
Expand Down
4 changes: 2 additions & 2 deletions llbc/include/llbc/core/objectpool/ObjectPoolInstInl.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ LLBC_FORCE_INLINE void LLBC_ObjectPoolInst<ObjectType>::AllocateMemoryBlock()
memset(memBlock->buff, 0, _blockSize);
#endif

memBlock->seq = _blockCnt;
memBlock->seq = static_cast<int>(_blockCnt);
#if LLBC_64BIT_PROCESSOR
memBlock->unused = 0;
#endif // 64bit-processor
Expand All @@ -311,7 +311,7 @@ LLBC_FORCE_INLINE void LLBC_ObjectPoolInst<ObjectType>::AllocateMemoryBlock()
#if !LLBC_CFG_CORE_OBJECT_POOL_DEBUG
memUnit->unFlags.flagsVal = 0;
#endif // !LLBC_CFG_CORE_OBJECT_POOL_DEBUG
memUnit->seq = idx;
memUnit->seq = static_cast<int>(idx);

#if LLBC_CFG_CORE_OBJECT_POOL_DEBUG
memcpy(memUnit->buff,
Expand Down
4 changes: 2 additions & 2 deletions llbc/include/llbc/core/random/Random.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

#pragma once

#include <random>
#include "llbc/common/Common.h"
#include "llbc/core/random/mtrandom.h"

__LLBC_NS_BEGIN

Expand Down Expand Up @@ -90,7 +90,7 @@ class LLBC_EXPORT LLBC_Random
_RandomAccessIter Choice(const _RandomAccessIter &begin, const _RandomAccessIter &end);

private:
std::mt19937 _mtRand;
mtrandom _mtRand;
};

/**
Expand Down
12 changes: 6 additions & 6 deletions llbc/include/llbc/core/random/RandomInl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ inline LLBC_Random::LLBC_Random(int seed)

inline void LLBC_Random::Seed(int seed)
{
_mtRand.seed(seed);
_mtRand.reset(seed);
}

inline int LLBC_Random::Rand()
{
return static_cast<int>(_mtRand());
return static_cast<int>(_mtRand.rand());
}

inline int LLBC_Random::Rand(int end)
{
if (LIKELY(end != 0))
{
const long long randVal = llabs(static_cast<int>(_mtRand()));
const long long randVal = llabs(static_cast<int>(_mtRand.rand()));
if (end > 0)
return static_cast<int>(randVal % end);
else
Expand All @@ -58,7 +58,7 @@ inline int LLBC_Random::Rand(int begin, int end)
{
if (LIKELY(begin != end))
{
const long long randVal = llabs(static_cast<int>(_mtRand()));
const long long randVal = llabs(static_cast<int>(_mtRand.rand()));
if (begin < end)
return randVal % (end - begin) + begin;
else
Expand Down Expand Up @@ -98,12 +98,12 @@ LLBC_Random::Rand(const _Weights &weights)

inline double LLBC_Random::RandReal()
{
return (static_cast<double>(_mtRand()) + .5) * (1. / 4294967296.); // divided by 2^32
return _mtRand.real();
}

inline bool LLBC_Random::BoolJudge()
{
return _mtRand() % 2 == 1;
return _mtRand.rand() % 2 == 1;
}

template <typename _RandomAccessIter>
Expand Down
182 changes: 182 additions & 0 deletions llbc/include/llbc/core/random/mtrandom.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
//************************************************************************
// This is a slightly modified version of Equamen mersenne twister.
//
// Copyright (C) 2009 Chipset
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//************************************************************************

// Original Coyright (c) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura
//
// Functions for MT19937, with initialization improved 2002/2/10.
// Coded by Takuji Nishimura and Makoto Matsumoto.
// This is a faster version by taking Shawn Cokus's optimization,
// Matthe Bellew's simplification, Isaku Wada's real version.
// C++ version by Lyell Haynes (Equamen)
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. The names of its contributors may not be used to endorse or promote
// products derived from this software without specific prior written
// permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//

#pragma once

#include "llbc/common/Common.h"

__LLBC_NS_BEGIN

class mtrandom
{
public:
mtrandom() : left(1) { init(); }

explicit mtrandom(size_t seed) : left(1) { init(seed); }

mtrandom(size_t* init_key, int key_length) : left(1)
{
int i = 1, j = 0;
int k = N > key_length ? N : key_length;
init();
for (; k; --k)
{
state[i] = (state[i] ^ ((state[i - 1] ^ (state[i - 1] >> 30)) * 1664525UL)) + init_key[j] + j; // non linear
state[i] &= 4294967295UL; // for WORDSIZE > 32 machines
++i;
++j;
if (i >= N)
{
state[0] = state[N - 1];
i = 1;
}
if (j >= key_length)
j = 0;
}

for (k = N - 1; k; --k)
{
state[i] = (state[i] ^ ((state[i - 1] ^ (state[i - 1] >> 30)) * 1566083941UL)) - i; // non linear
state[i] &= 4294967295UL; // for WORDSIZE > 32 machines
++i;
if (i >= N)
{
state[0] = state[N - 1];
i = 1;
}
}

state[0] = 2147483648UL; // MSB is 1; assuring non-zero initial array
}

void reset(size_t rs)
{
init(rs);
next_state();
}

size_t rand()
{
size_t y;
if (0 == --left)
next_state();
y = *next++;
// Tempering
y ^= (y >> 11);
y ^= (y << 7) & 0x9d2c5680UL;
y ^= (y << 15) & 0xefc60000UL;
y ^= (y >> 18);
return y;
}

// generates double floating point numbers in the open interval(0, 1)
double real()
{
return (static_cast<double>(rand()) + .5) * (1. / 4294967296.); // divided by 2^32
}

// generates a random number on [0,1) with 53-bit resolution
double res53()
{
size_t a = rand() >> 5, b = rand() >> 6;
return (a * 67108864.0 + b) / 9007199254740992.0;
}

private:
void init(size_t seed = 19650218UL)
{
state[0] = seed & 4294967295UL;
for (int j = 1; j < N; ++j)
{
state[j] = (1812433253UL * (state[j - 1] ^ (state[j - 1] >> 30)) + j);
// See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier.
// In the previous versions, MSBs of the seed affect
// only MSBs of the array state[].
// 2002/01/09 modified by Makoto Matsumoto
state[j] &= 4294967295UL; // for >32 bit machines
}
}

void next_state()
{
size_t* p = state;
int i;

for (i = N - M + 1; --i; ++p)
* p = (p[M] ^ twist(p[0], p[1]));

for (i = M; --i; ++p)
* p = (p[M - N] ^ twist(p[0], p[1]));
*p = p[M - N] ^ twist(p[0], state[0]);
left = N;
next = state;
}

size_t mixbits(size_t u, size_t v) const
{
return (u & 2147483648UL) | (v & 2147483647UL);
}

size_t twist(size_t u, size_t v) const
{
return ((mixbits(u, v) >> 1) ^ (v & 1UL ? 2567483615UL : 0UL));
}

static const int N = 624, M = 397;
size_t state[N];
size_t left;
size_t* next;
};

__LLBC_NS_END
2 changes: 2 additions & 0 deletions llbc/src/common/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

__LLBC_NS_BEGIN

// The version number is automatically updated by the building_script
// and configured in cfg.py, please do not update it manually.
int LLBC_majorVersion = 1;
int LLBC_minorVersion = 1;
int LLBC_updateNo = 1;
Expand Down
6 changes: 3 additions & 3 deletions testsuite/common/TestCase_Com_StreamFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ int TestCase_Com_StreamFunc::RWPosTest()
for (int i = 0; i < 11; ++i)
{
const size_t oldWPos = stream.GetWritePos();
const size_t newWPos = i < 10 ? LLBC_Rand(stream.GetCap() * 2) : stream.GetCap();
const size_t newWPos = i < 10 ? LLBC_Rand(static_cast<int>(stream.GetCap()) * 2) : stream.GetCap();

const bool setWPosRet = stream.SetWritePos(newWPos);
LLBC_PrintLn(" - Set wpos %lu -> %lu, cap:%lu, ret:%s",
Expand All @@ -436,11 +436,11 @@ int TestCase_Com_StreamFunc::RWPosTest()
for (int i = 0; i < 11; ++i)
{
const size_t oldRPos = stream.GetReadPos();
const size_t newRPos = i < 10 ? LLBC_Rand(stream.GetCap() + 1) : stream.GetWritePos();
const size_t newRPos = i < 10 ? LLBC_Rand(static_cast<int>(stream.GetCap()) + 1) : stream.GetWritePos();

const bool setRPosRet = stream.SetReadPos(newRPos);
LLBC_PrintLn(" - Set rpos %lu -> %lu, rpos:%lu, ret:%s",
oldRPos, newRPos, stream.GetWritePos(), setRPosRet ? "true" : "false");;
oldRPos, newRPos, stream.GetWritePos(), setRPosRet ? "true" : "false");
LLBC_ErrorAndReturnIfNot(newRPos <= stream.GetWritePos() ? setRPosRet : !setRPosRet,
LLBC_FAILED);
}
Expand Down
Loading

0 comments on commit 4d1fdcb

Please sign in to comment.