Skip to content

Commit 67ea010

Browse files
authored
Merge pull request #273 from SChernykh/ci-test
Added CI tests
2 parents 901f8ef + 3f69ad7 commit 67ea010

File tree

3 files changed

+241
-1
lines changed

3 files changed

+241
-1
lines changed

.github/workflows/c-cpp.yml

+223
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
name: C/C++ CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build-alpine:
7+
8+
timeout-minutes: 15
9+
runs-on: ubuntu-22.04
10+
11+
strategy:
12+
matrix:
13+
config:
14+
- {arch: x86_64, branch: latest-stable}
15+
- {arch: x86, branch: latest-stable}
16+
- {arch: aarch64, branch: latest-stable}
17+
- {arch: armhf, branch: latest-stable}
18+
- {arch: armv7, branch: latest-stable}
19+
- {arch: ppc64le, branch: latest-stable}
20+
- {arch: riscv64, branch: edge}
21+
- {arch: s390x, branch: latest-stable}
22+
23+
steps:
24+
- name: Setup Alpine Linux
25+
uses: jirutka/setup-alpine@v1
26+
with:
27+
arch: ${{ matrix.config.arch }}
28+
branch: ${{ matrix.config.branch }}
29+
30+
- name: Install dependencies
31+
shell: alpine.sh --root {0}
32+
run: |
33+
apk add git cmake gcc g++ make
34+
35+
- name: Checkout repository
36+
uses: actions/checkout@v3
37+
with:
38+
submodules: true
39+
40+
- name: Build RandomX
41+
shell: alpine.sh {0}
42+
run: |
43+
mkdir build
44+
cd build
45+
cmake ..
46+
make -j$(nproc)
47+
48+
- name: Run tests
49+
shell: alpine.sh {0}
50+
run: |
51+
build/randomx-tests
52+
53+
build-ubuntu:
54+
55+
timeout-minutes: 5
56+
runs-on: ${{ matrix.config.os }}
57+
58+
strategy:
59+
matrix:
60+
config:
61+
- {os: ubuntu-20.04, c: gcc-11, cpp: g++-11}
62+
- {os: ubuntu-22.04, c: gcc-12, cpp: g++-12}
63+
64+
steps:
65+
- name: Install dependencies
66+
run: |
67+
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
68+
sudo apt update
69+
sudo apt install -y git build-essential cmake ${{ matrix.config.c }} ${{ matrix.config.cpp }}
70+
71+
- name: Checkout repository
72+
uses: actions/checkout@v3
73+
with:
74+
submodules: true
75+
76+
- name: Build RandomX
77+
run: |
78+
mkdir build
79+
cd build
80+
cmake ..
81+
make -j$(nproc)
82+
83+
- name: Run tests
84+
run: |
85+
build/randomx-tests
86+
87+
build-windows-msys2:
88+
89+
timeout-minutes: 15
90+
runs-on: windows-latest
91+
92+
strategy:
93+
matrix:
94+
config:
95+
- {c: "gcc", cxx: "g++"}
96+
- {c: "clang", cxx: "clang++"}
97+
98+
defaults:
99+
run:
100+
shell: msys2 {0}
101+
102+
steps:
103+
- name: Checkout repository
104+
uses: actions/checkout@v3
105+
with:
106+
submodules: recursive
107+
108+
- name: Setup MSYS2
109+
uses: eine/setup-msys2@v2
110+
with:
111+
update: true
112+
install: mingw-w64-x86_64-toolchain mingw-w64-x86_64-clang mingw-w64-x86_64-lld mingw-w64-x86_64-cmake make
113+
114+
- name: Build RandomX
115+
run: |
116+
mkdir build
117+
cd build
118+
cmake .. -G "Unix Makefiles" -DCMAKE_C_COMPILER=${{ matrix.config.c }} -DCMAKE_CXX_COMPILER=${{ matrix.config.cxx }}
119+
make -j$(nproc)
120+
121+
- name: Run tests
122+
run: |
123+
build/randomx-tests.exe
124+
125+
build-windows-msbuild:
126+
127+
timeout-minutes: 5
128+
runs-on: windows-${{ matrix.config.os }}
129+
130+
strategy:
131+
matrix:
132+
config:
133+
- {arch: x64, os: 2019, vs: Visual Studio 16 2019, msbuild: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\MSBuild\\Current\\Bin\\amd64\\"}
134+
- {arch: x64, os: 2022, vs: Visual Studio 17 2022, msbuild: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\Msbuild\\Current\\Bin\\amd64\\"}
135+
- {arch: Win32, os: 2019, vs: Visual Studio 16 2019, msbuild: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\MSBuild\\Current\\Bin\\"}
136+
- {arch: Win32, os: 2022, vs: Visual Studio 17 2022, msbuild: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\Msbuild\\Current\\Bin\\"}
137+
138+
steps:
139+
- name: Checkout repository
140+
uses: actions/checkout@v3
141+
with:
142+
submodules: recursive
143+
144+
- name: Setup cmake
145+
uses: lukka/get-cmake@latest
146+
147+
- name: Build RandomX
148+
run: |
149+
mkdir build
150+
cd build
151+
cmake .. -G "${{ matrix.config.vs }}" -A ${{ matrix.config.arch }}
152+
& "${{ matrix.config.msbuild }}msbuild" -v:m /m /p:Configuration=Release randomx-tests.vcxproj
153+
154+
- name: Run tests
155+
run: |
156+
build/Release/randomx-tests.exe
157+
158+
build-macos:
159+
160+
timeout-minutes: 5
161+
runs-on: ${{ matrix.os }}
162+
163+
strategy:
164+
matrix:
165+
os: [macos-11, macos-12, macos-13]
166+
167+
steps:
168+
- name: Checkout repository
169+
uses: actions/checkout@v3
170+
with:
171+
submodules: recursive
172+
173+
- name: Install dependencies
174+
run: HOMEBREW_NO_AUTO_UPDATE=1 brew install cmake
175+
176+
- name: Build RandomX
177+
run: |
178+
mkdir build
179+
cd build
180+
cmake ..
181+
make -j3
182+
183+
- name: Run tests
184+
run: |
185+
build/randomx-tests
186+
187+
build-freebsd:
188+
189+
timeout-minutes: 15
190+
runs-on: ${{ matrix.os.host }}
191+
192+
strategy:
193+
matrix:
194+
os:
195+
- name: freebsd
196+
architecture: x86-64
197+
version: '13.2'
198+
host: ubuntu-22.04
199+
200+
- name: freebsd
201+
architecture: arm64
202+
version: '13.2'
203+
host: ubuntu-22.04
204+
205+
steps:
206+
- name: Checkout repository
207+
uses: actions/checkout@v3
208+
with:
209+
submodules: recursive
210+
211+
- name: Build RandomX
212+
uses: cross-platform-actions/[email protected]
213+
with:
214+
operating_system: ${{ matrix.os.name }}
215+
architecture: ${{ matrix.os.architecture }}
216+
version: ${{ matrix.os.version }}
217+
shell: bash
218+
run: |
219+
sudo pkg install -y cmake
220+
mkdir build && cd build
221+
cmake ..
222+
make -j2
223+
./randomx-tests

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function(add_flag flag)
9696
endfunction()
9797

9898
# x86-64
99-
if(ARCH_ID STREQUAL "x86_64" OR ARCH_ID STREQUAL "x86-64" OR ARCH_ID STREQUAL "amd64")
99+
if ((CMAKE_SIZEOF_VOID_P EQUAL 8) AND (ARCH_ID STREQUAL "x86_64" OR ARCH_ID STREQUAL "x86-64" OR ARCH_ID STREQUAL "amd64"))
100100
list(APPEND randomx_sources
101101
src/jit_compiler_x86.cpp)
102102

src/randomx.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3636
#include "cpu.hpp"
3737
#include <cassert>
3838
#include <limits>
39+
40+
#if defined(__SSE__) || defined(__SSE2__) || (defined(_M_IX86_FP) && (_M_IX86_FP > 0))
41+
#define USE_CSR_INTRINSICS
42+
#include <xmmintrin.h>
43+
#else
3944
#include <cfenv>
45+
#endif
4046

4147
extern "C" {
4248

@@ -356,8 +362,14 @@ extern "C" {
356362
assert(machine != nullptr);
357363
assert(inputSize == 0 || input != nullptr);
358364
assert(output != nullptr);
365+
366+
#ifdef USE_CSR_INTRINSICS
367+
const unsigned int fpstate = _mm_getcsr();
368+
#else
359369
fenv_t fpstate;
360370
fegetenv(&fpstate);
371+
#endif
372+
361373
alignas(16) uint64_t tempHash[8];
362374
int blakeResult = blake2b(tempHash, sizeof(tempHash), input, inputSize, nullptr, 0);
363375
assert(blakeResult == 0);
@@ -370,7 +382,12 @@ extern "C" {
370382
}
371383
machine->run(&tempHash);
372384
machine->getFinalResult(output, RANDOMX_HASH_SIZE);
385+
386+
#ifdef USE_CSR_INTRINSICS
387+
_mm_setcsr(fpstate);
388+
#else
373389
fesetenv(&fpstate);
390+
#endif
374391
}
375392

376393
void randomx_calculate_hash_first(randomx_vm* machine, const void* input, size_t inputSize) {

0 commit comments

Comments
 (0)