nissy-core

The "engine" of nissy, including the H48 optimal solver.
git clone https://git.tronto.net/nissy-core
Download | Log | Files | Refs | README | LICENSE

commit fc41f7917531693680b5baf71ffe38c47333fe84
parent fe534f1497da6447153064d7bba00243000f803b
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Mon,  6 Apr 2026 15:55:33 +0200

Make the project build with Microsoft's broken C compiler.

MSVC is not fully C11-compliant, even when compiling with /std:c11.
Some changes were needed to make the codebase compatible. Notably, the
notation a[static N] and a[n] for function parameters of array type is
not supported, so that had to be hidden behind a macro.  Atomic types
are also an experimental feature, apparently, but at least they work
with the correct compiler flag.

One thing that MSVC does well, however, is warning on integer conversions
on /W4 level. I am not sure if Clang and GCC have something similar,
so I took this chance to fix some of these.

Diffstat:
M.gitignore | 1+
MREADME.md | 39+++++++++++++++++++++++++++++++--------
Mbuild.bat | 148++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
Msrc/arch/avx2.h | 12++++++------
Msrc/arch/common.h | 14+++++++-------
Msrc/arch/neon.h | 10+++++-----
Msrc/arch/portable.h | 10+++++-----
Msrc/core/cube.h | 8++++----
Msrc/core/moves.h | 30+++++++++++++++---------------
Msrc/core/transform.h | 17+++++++++--------
Msrc/nissy.c | 32++++++++++++++++----------------
Msrc/nissy.h | 33++++++++++++++++++++++-----------
Msrc/solvers/coord/common.h | 42++++++++++++++++++++++--------------------
Msrc/solvers/coord/gendata.h | 51+++++++++++++++++++++++++++------------------------
Msrc/solvers/coord/htr.h | 4++--
Msrc/solvers/coord/multisolve.h | 32++++++++++++++++----------------
Msrc/solvers/coord/solve.h | 36++++++++++++++++++------------------
Msrc/solvers/coord/types_macros.h | 4++--
Msrc/solvers/coord/utils.h | 4++--
Msrc/solvers/dispatch.h | 4++--
Msrc/solvers/distribution.h | 14+++++++-------
Msrc/solvers/h48/coordinate.h | 8++++----
Msrc/solvers/h48/distribution_h48.h | 6+++---
Msrc/solvers/h48/gendata_cocsep.h | 21++++++++++-----------
Msrc/solvers/h48/gendata_eoesep.h | 62++++++++++++++++++++++++++++++++------------------------------
Msrc/solvers/h48/gendata_h48.h | 36++++++++++++++++++------------------
Msrc/solvers/h48/map.h | 28++++++++++++++--------------
Msrc/solvers/h48/solve.h | 68++++++++++++++++++++++++++++++++++----------------------------------
Msrc/solvers/h48/utils.h | 10+++++-----
Msrc/solvers/solutions.h | 82++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/solvers/tables.h | 26+++++++++++++-------------
Msrc/utils/compilers.h | 17++++++++++++++---
Msrc/utils/dbg_log.h | 3+--
Msrc/utils/math.h | 6+++---
Msrc/utils/wrapthread.h | 4++--
Mtest/001_pieces/pieces_tests.c | 2+-
Mtest/010_math_permtoindex/permtoindex_tests.c | 4++--
Mtest/011_math_indextoperm/indextoperm_tests.c | 2+-
Mtest/012_math_permsign/permsign_tests.c | 4++--
Mtest/013_math_digitstosumzero/digitstosumzero_tests.c | 6+++---
Mtest/014_math_sumzerotodigits/sumzerotodigits.c | 6+++---
Mtest/033_inverse_move/inverse_move_tests.c | 2+-
Mtest/061_inverse_trans/inverse_trans_tests.c | 2+-
Mtest/062_transform_move/transform_move_tests.c | 4++--
Mtest/075_set_eo/set_eo_tests.c | 2+-
Mtest/076_copy_co/copy_co_tests.c | 2+-
Mtest/090_allowedmoves/allowedmoves_tests.c | 6+++---
Mtest/114_cocsep_ttrep/cocsep_ttrep_tests.c | 4++--
Mtest/115_gendata_eoesep/gendata_eoesep_tests.c | 2+-
Mtest/121_h48map/h48map_tests.c | 10+++++-----
Mtest/122_gendata_h48short/gendata_h48short_tests.c | 10+++++-----
Mtest/131_coorddata_dr/coorddata_dr.c | 6+++---
Mtest/132_coorddata_dreo/coorddata_dreo.c | 6+++---
Mtest/133_coordata_drfinnoe/coorddata_drfinnoe.c | 6+++---
Mtest/140_appendsolution/appendsolution_tests.c | 20++++++++++----------
Mtest/test.h | 3++-
Mtools/420_solvetest_h48_symmetric/solvetest.c | 2+-
Mtools/solvetest.h | 4++--
Mtools/tool.h | 9++++-----
59 files changed, 565 insertions(+), 481 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -33,6 +33,7 @@ tools/results .vscode *.a *.o +*.obj *.so */*.so *.s diff --git a/README.md b/README.md @@ -39,14 +39,26 @@ is going to configure `nissy` to use at most 3 threads, and build it with ### Windows -It is possible to build this project on Windows using `build.bat`. The -[Clang](https://clang.llvm.org/) compiler must be installed, and the -command prompt must be correctly configured to run it. +It is possible to build this project on Windows using `build.bat`, using +either MSVC (default) or [Clang](https://clang.llvm.org/). In either case, +the command prompt must be correctly configured to run the compiler from +the command line. -We suggest installing Clang via the Visual Studio Installer, selecting -the "C++ development" pack, as well as the "clang" and "Windows SDK 11" -components. It is advised to use "x64 Native Tools Command Prompt for -VS 2022" instead of a regular command prompt to run the build script. +For Clang, we suggest installing it via the Visual Studio Installer, +selecting the "C++ development" pack, as well as the "clang" and "Windows +SDK 11" components. It is advised to use "x64 Native Tools Command Prompt +for VS 2022" instead of a regular command prompt to run the build script. + + +You can specify the compiler to use by setting the +`CC` environment variable to either `clang` or `msvc`. For example: + +``` +> SET CC=clang +> build.bat test +``` + +Will run all the tests using clang. The `build.bat` script has the same syntax as the `build.sh` script, but not all options are available. For example @@ -64,9 +76,20 @@ can be used to build the basic shell, while Builds and runs the unit tests. See `build.bat help` for a list of all available options. -Note: The build script for Windows does not support all the options +#### Caveats for building on Windows + +* The build script for Windows does not support all the options available with build.sh. If you want to tune the build options, you'll have to manually edit the build script. +* If you are building on an old x86-64 machine that does not support AVX2 +instructions, you will have to manually set the architecture to `PORTABLE` +with `SET ARCH=PORTABLE`. +* Build on Windows on ARM has not been tested at all. +* When building with MSVC, the option `/experimental:c11atomics` is used. +Despite atomic types being part of the C11 standard for 15 years now, +they have only [recently been +implemented](https://devblogs.microsoft.com/cppblog/c11-atomics-in-visual-studio-2022-version-17-5-preview-2), +and Microsoft still considers them an experimental feature. Impressive! ## Running tests diff --git a/build.bat b/build.bat @@ -1,49 +1,96 @@ @echo off -if [%1]==[/d] ( +SET DEBUG=0 +if "%1"=="/d" ( SET DEBUG=1 shift -) else ( - SET DEBUG=0 ) +if "%1"=="test" (SET DEBUG=1) -SET CC=clang -SET CXX=clang++ -SET THREADS=16 -SET SANITIZE= - -SET ARCH=PORTABLE -clang -march=native -dM -E - < NUL | findstr /C:"__AVX2__" >NUL 2>&1 -if %ERRORLEVEL% EQU 0 ( - SET ARCH=AVX2 - SET ARCHOPTS=-mavx2 - goto :ArchDone -) -clang -march=native -dM -E - < NUL | findstr /C:"__ARM_NEON" >NUL 2>&1 -if %ERRORLEVEL% EQU 0 ( - SET ARCH=NEON - goto :ArchDone -) -:ArchDone - +:: Detect architecture, or use user-specified one +if "%ARCH%"=="" goto :detect_arch +if "%ARCH%"=="PORTABLE" goto :arch_done +if "%ARCH%"=="AVX2" goto :arch_done +if "%ARCH%"=="NEON" goto :arch_done -SET DFLAGS=-g3 -DDEBUG -SET WARNINGS=-Wno-deprecated-declarations -SET VARIABLES=-DTHREADS=%THREADS% -D%ARCH% -SET OFLAGS=-O3 +echo Unsupported architecture '%ARCH%' +exit /b 1 -SET CFLAGS=-std=c11 %ARCHOPTS% %WARNINGS% %VARIABLES% +:detect_arch + if "%PROCESSOR_ARCHITECTURE%"=="AMD64" ( + SET ARCH=AVX2 + ) else if "%PROCESSOR_ARCHITECTURE%"=="ARM64" ( + SET ARCH=NEON + ) else ( + SET ARCH=PORTABLE + ) +:arch_done -SET STACKSIZE=-Wl,-stack:16777216 -SET LFLAGS=%STACKSIZE% +:: Default value for maximum number of threads +SET THREADS=16 -:: Python libraries - change to match your local installation +:: Detect Python libraries path for /f "delims=" %%i in ('python -c "import sys; print(sys.base_prefix)"') do set PYPATH=%%i -::SET PYPATH=%userprofile%\AppData\Local\Programs\Python\Python313 - SET PYINCLUDE=%PYPATH%\include SET PYLIBS=%PYPATH%\libs +:: Select compiler from possibly user-set %CC% variable +:: Currently we only support clang and MSVC +if "%CC%"=="" goto :set_msvc +if /I "%CC%"=="cl" goto :set_msvc +if /I "%CC%"=="msvc" goto :set_msvc +if /I "%CC%"=="clang" goto :set_clang + +echo Unsupported compiler '%CC%' +exit /b 1 + +:set_msvc + SET CC=cl + SET CXX=cl + + SET DFLAGS=/Zi /DDEBUG + SET WARNINGS=/W4 /wd4100 /wd4324 /wd4505 /wd4996 + SET VARIABLES=/DTHREADS=%THREADS% /D%ARCH% + SET OFLAGS=/O2 + + if %DEBUG%==1 (SET ODFLAGS=%DFLAGS%) else (SET ODFLAGS=%OFLAGS%) + if "%ARCH%"=="AVX2" (SET ARCHOPTS=/arch:AVX2) else (SET ARCHOPTS=) + + SET CFLAGS=/std:c11 /experimental:c11atomics /nologo %ARCHOPTS% %WARNINGS% %VARIABLES% + SET LFLAGS=/F 16777216 + + SET CC_NISSY=%CC% %CFLAGS% %ODFLAGS% /c src\nissy.c + SET CC_SHELL=%CC% %CFLAGS% %ODFALGS% %LFLAGS% nissy.obj shell\shell.c /Fe:run.exe + SET CC_PYTHON=%CC% %CFLAGS% %LFLAGS% /I"%PYINCLUDE%" /LD /Fe:python\nissy.pyd python\nissy_module.c nissy.obj /link /LIBPATH:"%PYLIBS%" python3.lib + SET CC_TEST=%CC% %CFLAGS% %ODFLAGS% %LFLAGS% /Fe:runtest.exe nissy.obj + SET CC_TOOL=%CC% %CFLAGS% %ODFLAGS% %LFLAGS% /Fe:runtool.exe nissy.obj + SET CC_CXX=%CXX% /EHsc /nologo %ARCHOPTS% %ODFLAGS% %LFLAGS% /std:c++20 /Fe:runcpp.exe nissy_c.obj cpp\nissy.cpp +goto :compiler_done + +:set_clang + SET CC=clang + SET CXX=clang++ + + SET DFLAGS=-g3 -DDEBUG + SET WARNINGS=-Wall -Wextra -Wno-unused-function -Wno-unused-parameter -Wno-deprecated-declarations + SET VARIABLES=-DTHREADS=%THREADS% -D%ARCH% + SET OFLAGS=-O3 + + if %DEBUG%==1 (SET ODFLAGS=%DFLAGS%) else (SET ODFLAGS=%OFLAGS%) + if "%ARCH%"=="AVX2" (SET ARCHOPTS=-mavx2) else (SET ARCHOPTS=) + + SET CFLAGS=-std=c11 %ARCHOPTS% %WARNINGS% %VARIABLES% + SET LFLAGS=-Wl,-stack:16777216 + + SET CC_NISSY=%CC% %CFLAGS% %ODFLAGS% -c src\nissy.c -o nissy.obj + SET CC_SHELL=%CC% %CFLAGS% %ODFLAGS% %LFLAGS% nissy.obj shell\shell.c -o run.exe + SET CC_PYTHON=%CC% %CFLAGS% %LFLAGS% -I%PYINCLUDE% -L%PYLIBS% -shared -lpython3 python\nissy_module.c nissy.obj -o python\nissy.pyd + SET CC_TEST=%CC% %CFLAGS% %ODFLAGS% %LFLAGS% -o runtest.exe nissy.obj + SET CC_TOOL=%CC% %CFLAGS% %ODFLAGS% %LFLAGS% -o runtool.exe nissy.obj + SET CC_CXX=%CXX% %ARCHOPTS% %ODFLAGS% %LFLAGS% -std=c++20 -o runcpp.exe nissy_c.obj cpp\nissy.cpp +:compiler_done + +:: Select compilation target from command line argument SET TARGET=%1 if not defined TARGET SET TARGET=nissy SET EXPR=%2 @@ -53,7 +100,6 @@ for %%a in (nissy python shell test config help clean tool cpp solvetest) do ( exit /b ) ) - echo Target '%TARGET%' unavailable, run 'build help' for info exit /b 1 @@ -66,7 +112,7 @@ exit /b 1 echo. echo Possible values for TARGET (defaults to 'nissy' if unspecified): echo. - echo nissy Build the nissy.o object file. + echo nissy Build the nissy.obj object file. echo python Build the Python module for nissy. echo NOTE: Python development headers must be installed in echo order to build the Python module. The path of these @@ -98,32 +144,26 @@ exit /b exit /b :build_nissy - call:odflags @echo on - %CC% %CFLAGS% %ODFLAGS% -c src\nissy.c || exit /b 1 + %CC_NISSY% || exit /b 1 @echo off exit /b :build_shell call:build_nissy || exit /b 1 - call:odflags @echo on - %CC% %CFLAGS% %ODFLAGS% %LFLAGS% nissy.o shell\shell.c -o run.exe ^ - || exit /b 1 + %CC_SHELL% || exit /b 1 @echo off exit /b :build_python call:build_nissy || exit /b 1 - call:odflags @echo on - %CC% %CFLAGS% %LFLAGS% -I%PYINCLUDE% -L%PYLIBS% -shared -lpython3 ^ - python\nissy_module.c nissy.o -o python\nissy.pyd || exit /b 1 + %CC_PYTHON% || exit /b 1 @echo off exit /b :build_test - SET DEBUG=1 call:build_nissy || exit /b 1 if not defined EXPR ( SET WILDCARD=* @@ -139,7 +179,7 @@ exit /b :build_clean @echo on - del *.o *.so *.a *.ilk *.pdb *.exe + del *.o *.obj *.so *.a *.ilk *.pdb *.exe @echo off exit /b @@ -173,9 +213,11 @@ exit /b exit /b 1 ) call:build_nissy || exit /b 1 + copy nissy.obj nissy_c.obj @echo on - %CXX% %ODFLAGS% -std=c++20 -o runcpp.exe cpp\nissy.cpp nissy.o %EXPR% ^ - || exit /b 1 + %CC_CXX% %EXPR% || exit /b 1 + del nissy.obj + copy nissy_c.obj nissy.obj runcpp @echo off exit /b @@ -189,8 +231,7 @@ exit /b exit /b :build_single_test - call:odflags - %CC% %CFLAGS% %ODFLAGS% %LFLAGS% nissy.o %1\*.c -o runtest.exe || exit /b 1 + %CC_TEST% %1\*.c || exit /b 1 set error=0 for %%c in ( %1\*.in ) do ( if %error%==1 exit /b 1 @@ -213,21 +254,12 @@ exit /b :build_single_tool @echo on - %CC% %CFLAGS% %ODFLAGS% %LFLAGS% nissy.o tools\%toolname%\*.c ^ - -o runtool.exe || exit /b 1 + %CC_TOOL% tools\%toolname%\*.c || exit /b 1 @echo off runtool %3 %4 %5 %6 %7 %8 %9 || exit /b 1 @echo. @echo (On Windows, the output of a tool is not saved to any file.) exit /b -:odflags - if %DEBUG%==1 ( - SET ODFLAGS=%DFLAGS% - ) else ( - SET ODFLAGS=%OFLAGS% - ) -exit /b - :error exit /b 1 \ No newline at end of file diff --git a/src/arch/avx2.h b/src/arch/avx2.h @@ -37,11 +37,11 @@ popcount_u32(uint32_t x) STATIC_INLINE int popcount_u64(uint64_t x) { - return _mm_popcnt_u64(x); + return (int)_mm_popcnt_u64(x); } STATIC void -pieces(cube_t cube[static 1], uint8_t c[static 8], uint8_t e[static 12]) +pieces(cube_t cube[NON_NULL], uint8_t c[SIZE(8)], uint8_t e[SIZE(12)]) { uint8_t aux[32]; @@ -167,7 +167,7 @@ coord_co(cube_t c) } STATIC_INLINE void -copy_co(cube_t cube[static 1], cube_t co) +copy_co(cube_t cube[NON_NULL], cube_t co) { cube_t coclean; @@ -274,19 +274,19 @@ invcoord_esep(uint64_t esep) } STATIC_INLINE void -copy_corners(cube_t dest[static 1], cube_t src) +copy_corners(cube_t dest[NON_NULL], cube_t src) { *dest = _mm256_blend_epi32(*dest, src, 0x0F); } STATIC_INLINE void -copy_edges(cube_t dest[static 1], cube_t src) +copy_edges(cube_t dest[NON_NULL], cube_t src) { *dest = _mm256_blend_epi32(*dest, src, 0xF0); } STATIC_INLINE void -set_eo(cube_t cube[static 1], uint64_t eo) +set_eo(cube_t cube[NON_NULL], uint64_t eo) { uint64_t eo12, eotop, eobot; __m256i veo; diff --git a/src/arch/common.h b/src/arch/common.h @@ -15,7 +15,7 @@ STATIC_INLINE int popcount_u32(uint32_t); STATIC_INLINE int popcount_u64(uint64_t); -STATIC void pieces(cube_t [static 1], uint8_t [static 8], uint8_t [static 12]); +STATIC void pieces(cube_t [NON_NULL], uint8_t [SIZE(8)], uint8_t [SIZE(12)]); STATIC_INLINE bool equal(cube_t, cube_t); STATIC_INLINE cube_t invertco(cube_t); STATIC_INLINE cube_t compose_edges(cube_t, cube_t); @@ -35,12 +35,12 @@ STATIC_INLINE cube_t invcoord_epudsep(uint64_t); STATIC_INLINE bool is_eo_even(cube_t); -STATIC_INLINE void copy_corners(cube_t [static 1], cube_t); -STATIC_INLINE void copy_co(cube_t [static 1], cube_t); -STATIC_INLINE void copy_edges(cube_t [static 1], cube_t); -STATIC_INLINE void set_eo(cube_t [static 1], uint64_t); +STATIC_INLINE void copy_corners(cube_t [NON_NULL], cube_t); +STATIC_INLINE void copy_co(cube_t [NON_NULL], cube_t); +STATIC_INLINE void copy_edges(cube_t [NON_NULL], cube_t); +STATIC_INLINE void set_eo(cube_t [NON_NULL], uint64_t); -STATIC_INLINE void invcoord_esep_array(uint64_t, uint64_t, uint8_t[static 12]); +STATIC_INLINE void invcoord_esep_array(uint64_t, uint64_t, uint8_t[SIZE(12)]); STATIC_INLINE cube_t invcoord_eoesep(uint64_t); STATIC_INLINE uint64_t coord_epudsep_array(const uint8_t [8]); STATIC_INLINE void invcoord_epudsep_array(uint64_t, uint8_t [8]); @@ -53,7 +53,7 @@ STATIC_INLINE uint64_t coord_epe(cube_t); STATIC_INLINE cube_t invcoord_epe(uint64_t); STATIC_INLINE void -invcoord_esep_array(uint64_t set1, uint64_t set2, uint8_t mem[static 12]) +invcoord_esep_array(uint64_t set1, uint64_t set2, uint8_t mem[SIZE(12)]) { uint64_t bit1, bit2, i, j, jj, k, l, s, v, w, is1; uint8_t slice[3] = {0}; diff --git a/src/arch/neon.h b/src/arch/neon.h @@ -59,7 +59,7 @@ popcount_u64(uint64_t x) } STATIC void -pieces(cube_t cube[static 1], uint8_t c[static 8], uint8_t e[static 12]) +pieces(cube_t cube[NON_NULL], uint8_t c[SIZE(8)], uint8_t e[SIZE(12)]) { // First 8 bytes of the corner vector are copied from the c array vst1_u8(c, cube->corner); @@ -244,7 +244,7 @@ coord_co(cube_t c) } STATIC_INLINE void -copy_co(cube_t cube[static 1], cube_t co) +copy_co(cube_t cube[NON_NULL], cube_t co) { uint8x8_t coclean; @@ -340,19 +340,19 @@ coord_esep(cube_t c) } STATIC_INLINE void -copy_corners(cube_t dst[static 1], cube_t src) +copy_corners(cube_t dst[NON_NULL], cube_t src) { dst->corner = src.corner; } STATIC_INLINE void -copy_edges(cube_t dst[static 1], cube_t src) +copy_edges(cube_t dst[NON_NULL], cube_t src) { dst->edge = src.edge; } STATIC_INLINE void -set_eo(cube_t cube[static 1], uint64_t eo) +set_eo(cube_t cube[NON_NULL], uint64_t eo) { // Temp array to store the NEON vector uint8_t mem[16]; diff --git a/src/arch/portable.h b/src/arch/portable.h @@ -46,7 +46,7 @@ popcount_u64(uint64_t x) } STATIC void -pieces(cube_t cube[static 1], uint8_t c[static 8], uint8_t e[static 12]) +pieces(cube_t cube[NON_NULL], uint8_t c[SIZE(8)], uint8_t e[SIZE(12)]) { memcpy(c, cube->corner, 8); memcpy(e, cube->edge, 12); @@ -166,7 +166,7 @@ inverse(cube_t cube) } STATIC_INLINE void -copy_co(cube_t cube[static 1], cube_t co) +copy_co(cube_t cube[NON_NULL], cube_t co) { uint8_t c; size_t i; @@ -291,19 +291,19 @@ invcoord_esep(uint64_t esep) } STATIC_INLINE void -copy_corners(cube_t dest[static 1], cube_t src) +copy_corners(cube_t dest[NON_NULL], cube_t src) { memcpy(&dest->corner, src.corner, sizeof(src.corner)); } STATIC_INLINE void -copy_edges(cube_t dest[static 1], cube_t src) +copy_edges(cube_t dest[NON_NULL], cube_t src) { memcpy(&dest->edge, src.edge, sizeof(src.edge)); } STATIC_INLINE void -set_eo(cube_t cube[static 1], uint64_t eo) +set_eo(cube_t cube[NON_NULL], uint64_t eo) { uint8_t i, sum, flip; diff --git a/src/core/cube.h b/src/core/cube.h @@ -1,6 +1,6 @@ STATIC bool cube_true(cube_t); -STATIC cube_t cubefromarray(uint8_t [static 8], uint8_t [static 12]); +STATIC cube_t cubefromarray(uint8_t [SIZE(8)], uint8_t [SIZE(12)]); STATIC bool isconsistent(oriented_cube_t); STATIC bool issolvable(oriented_cube_t); STATIC bool issolved(oriented_cube_t); @@ -10,7 +10,7 @@ STATIC void getcube_fix(long long *, long long *, STATIC cube_t getcube(uint64_t, uint64_t, uint64_t, uint64_t); STATIC oriented_cube_t readcube(const char *); -STATIC int64_t writecube(oriented_cube_t, size_t n, char [n]); +STATIC int64_t writecube(oriented_cube_t, size_t n, char *); STATIC uint8_t readco(const char *); STATIC uint8_t readcp(const char *); STATIC uint8_t readeo(const char *); @@ -29,7 +29,7 @@ cube_true(cube_t cube) } STATIC cube_t -cubefromarray(uint8_t c[static 8], uint8_t e[static 12]) +cubefromarray(uint8_t c[SIZE(8)], uint8_t e[SIZE(12)]) { return STATIC_CUBE( c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], @@ -304,7 +304,7 @@ readcube(const char *buf) } STATIC int64_t -writecube(oriented_cube_t cube, size_t buf_size, char buf[buf_size]) +writecube(oriented_cube_t cube, size_t buf_size, char *buf) { int i; uint8_t corner[8], edge[12]; diff --git a/src/core/moves.h b/src/core/moves.h @@ -4,15 +4,15 @@ STATIC uint8_t readmove(char); STATIC int64_t readmoves(const char *, size_t, size_t, size_t *, size_t *, uint8_t *, uint8_t *); -STATIC int64_t readmoves_struct(const char *, moves_struct_t [static 1]); +STATIC int64_t readmoves_struct(const char *, moves_struct_t [NON_NULL]); STATIC int64_t countmoves(const char *); STATIC bool moves_struct_equal( - const moves_struct_t [static 1], const moves_struct_t [static 1]); + const moves_struct_t [NON_NULL], const moves_struct_t [NON_NULL]); STATIC long long comparemoves(const char *, const char *); STATIC uint8_t readmodifier(char); STATIC int64_t writemoves(size_t, const uint8_t *, size_t, char *); STATIC int64_t writemoves_struct( - const moves_struct_t [static 1], size_t, char *); + const moves_struct_t [NON_NULL], size_t, char *); STATIC_INLINE bool allowednextmove(uint8_t, uint8_t); STATIC bool allowedmoves(size_t, const uint8_t *); @@ -36,9 +36,9 @@ STATIC bool are_lastmoves_singlecw(size_t, const uint8_t*); STATIC int64_t move_variations(const char *, const char *, size_t, char *); STATIC int64_t move_variations_lastqt( - const moves_struct_t [static 1], size_t, char *); + const moves_struct_t [NON_NULL], size_t, char *); STATIC int64_t move_variations_unniss( - const moves_struct_t [static 1], size_t, char *); + const moves_struct_t [NON_NULL], size_t, char *); #define FOREACH_READMOVE(ARG_BUF, ARG_MOVE, ARG_C, ARG_MAX, \ RET_ERROR, ARG_ACTION) \ @@ -167,7 +167,7 @@ readmoves( } STATIC int64_t -readmoves_struct(const char *moves, moves_struct_t ret[static 1]) +readmoves_struct(const char *moves, moves_struct_t ret[NON_NULL]) { return readmoves(moves, NISSY_SIZE_MOVES, NISSY_SIZE_MOVES, &ret->nnormal, &ret->ninverse, ret->normal, ret->inverse); @@ -190,8 +190,8 @@ countmoves(const char *buf) STATIC bool moves_struct_equal( - const moves_struct_t ms1[static 1], - const moves_struct_t ms2[static 1] + const moves_struct_t ms1[NON_NULL], + const moves_struct_t ms2[NON_NULL] ) { size_t i; @@ -281,7 +281,7 @@ writemoves_error: STATIC int64_t writemoves_struct( - const moves_struct_t moves[static 1], + const moves_struct_t moves[NON_NULL], size_t buf_size, char *buf ) @@ -612,7 +612,7 @@ move_variations( STATIC int64_t move_variations_lastqt( - const moves_struct_t s[static 1], + const moves_struct_t s[NON_NULL], size_t result_size, char *result ) @@ -623,10 +623,10 @@ move_variations_lastqt( size_t u; moves_struct_t ss; - in1 = s->nnormal-1; - in2 = s->nnormal-2; - ii1 = s->ninverse-1; - ii2 = s->ninverse-2; + in1 = (uint8_t)(s->nnormal-1); + in2 = (uint8_t)(s->nnormal-2); + ii1 = (uint8_t)(s->ninverse-1); + ii2 = (uint8_t)(s->ninverse-2); n1 = in1 >= 0 ? s->normal[in1] : UINT8_ERROR; n2 = in2 >= 0 ? s->normal[in2] : UINT8_ERROR; @@ -686,7 +686,7 @@ lastqt_error: STATIC int64_t move_variations_unniss( - const moves_struct_t s[static 1], + const moves_struct_t s[NON_NULL], size_t result_size, char *result ) diff --git a/src/core/transform.h b/src/core/transform.h @@ -17,9 +17,9 @@ invertco(compose(compose(TRANS_CUBE_ ## T, c), \ TRANS_CUBE_ ## T ## _INVERSE)) -STATIC uint8_t readtrans(const char [static NISSY_SIZE_TRANSFORMATION]); -STATIC uint8_t readrotation(const char [static 2]); -STATIC void writetrans(uint8_t, char [static NISSY_SIZE_TRANSFORMATION]); +STATIC uint8_t readtrans(const char [SIZE(NISSY_SIZE_TRANSFORMATION)]); +STATIC uint8_t readrotation(const char [SIZE(2)]); +STATIC void writetrans(uint8_t, char [SIZE(NISSY_SIZE_TRANSFORMATION)]); STATIC cube_t transform_edges(cube_t, uint8_t); STATIC cube_t transform_corners(cube_t, uint8_t); @@ -29,7 +29,7 @@ STATIC_INLINE uint8_t inverse_trans(uint8_t); STATIC uint64_t symmetry_mask(cube_t); STATIC uint8_t -readtrans(const char buf[static NISSY_SIZE_TRANSFORMATION]) +readtrans(const char buf[SIZE(NISSY_SIZE_TRANSFORMATION)]) { uint8_t t; @@ -41,7 +41,7 @@ readtrans(const char buf[static NISSY_SIZE_TRANSFORMATION]) } STATIC uint8_t -readrotation(const char buf[static 2]) +readrotation(const char buf[SIZE(2)]) { char trans_str[NISSY_SIZE_TRANSFORMATION]; @@ -53,7 +53,7 @@ readrotation(const char buf[static 2]) } STATIC void -writetrans(uint8_t t, char buf[static NISSY_SIZE_TRANSFORMATION]) +writetrans(uint8_t t, char buf[SIZE(NISSY_SIZE_TRANSFORMATION)]) { if (t >= 48) memcpy(buf, "error trans", 11); @@ -407,12 +407,13 @@ inverse_trans(uint8_t t) STATIC uint64_t symmetry_mask(cube_t cube) { - uint64_t t, ret; + uint64_t ret; + uint8_t t; cube_t transformed; for (t = 0, ret = 0; t < NTRANS; t++) { transformed = transform(cube, t); - ret |= ((uint64_t)equal(cube, transformed)) << t; + ret |= ((uint64_t)equal(cube, transformed)) << (uint64_t)t; } return ret; diff --git a/src/nissy.c b/src/nissy.c @@ -12,8 +12,8 @@ #include "core/core.h" #include "solvers/solvers.h" -STATIC long long write_result(oriented_cube_t, char [static NISSY_SIZE_CUBE]); -STATIC long long nissy_dataid(const char *, char [static NISSY_SIZE_DATAID]); +STATIC long long write_result(oriented_cube_t, char [SIZE(NISSY_SIZE_CUBE)]); +STATIC long long nissy_dataid(const char *, char [SIZE(NISSY_SIZE_DATAID)]); STATIC long long nissy_gendata_unsafe( const char *, unsigned long long, unsigned char *); @@ -28,7 +28,7 @@ struct { }; STATIC long long -write_result(oriented_cube_t cube, char result[static NISSY_SIZE_CUBE]) +write_result(oriented_cube_t cube, char result[SIZE(NISSY_SIZE_CUBE)]) { writecube(cube, NISSY_SIZE_CUBE, result); @@ -42,8 +42,8 @@ write_result(oriented_cube_t cube, char result[static NISSY_SIZE_CUBE]) long long nissy_inverse( - const char cube[static NISSY_SIZE_CUBE], - char result[static NISSY_SIZE_CUBE] + const char cube[], + char result[] ) { oriented_cube_t c, res; @@ -77,9 +77,9 @@ nissy_inverse_error: long long nissy_applymoves( - const char cube[static NISSY_SIZE_CUBE], + const char cube[], const char *moves, - char result[static NISSY_SIZE_CUBE] + char result[] ) { oriented_cube_t c, res; @@ -116,9 +116,9 @@ nissy_applymoves_error: long long nissy_applytrans( - const char cube[static NISSY_SIZE_CUBE], - const char transformation[static NISSY_SIZE_TRANSFORMATION], - char result[static NISSY_SIZE_CUBE] + const char cube[], + const char transformation[], + char result[] ) { oriented_cube_t c, res; @@ -181,7 +181,7 @@ nissy_getcube( long long co, long long orient, const char *options, - char result[static NISSY_SIZE_CUBE] + char result[] ) { int i; @@ -197,7 +197,7 @@ nissy_getcube( getcube_options[i].fix(&ep, &eo, &cp, &co, &orient); oc.cube = getcube(ep, eo, cp, co); - oc.orientation = orient; + oc.orientation = (uint8_t)orient; if (!isconsistent(oc)) { LOG("[getcube] Error: could not get cube with ep=%lld, " @@ -210,7 +210,7 @@ nissy_getcube( } STATIC long long -nissy_dataid(const char *solver, char dataid[static NISSY_SIZE_DATAID]) +nissy_dataid(const char *solver, char dataid[SIZE(NISSY_SIZE_DATAID)]) { solver_dispatch_t dispatch; @@ -226,7 +226,7 @@ nissy_dataid(const char *solver, char dataid[static NISSY_SIZE_DATAID]) long long nissy_solverinfo( const char *solver, - char dataid[static NISSY_SIZE_DATAID] + char dataid[] ) { long long err; @@ -295,7 +295,7 @@ nissy_checkdata( long long nissy_solve( - const char cube[static NISSY_SIZE_CUBE], + const char cube[], const char *solver, unsigned nissflag, unsigned minmoves, @@ -307,7 +307,7 @@ nissy_solve( const unsigned char *data, unsigned sols_size, char *sols, - long long stats[static NISSY_SIZE_SOLVE_STATS], + long long stats[], int (*poll_status)(void *), void *poll_status_data ) diff --git a/src/nissy.h b/src/nissy.h @@ -149,7 +149,9 @@ Compute the inverse of the given cube. Parameters: cube - The cube to be inverted. + Required size: NISSY_SIZE_CUBE. result - The return parameter for the resulting cube. + Required size: NISSY_SIZE_CUBE. Return values: NISSY_OK - The cube was inverted succesfully. @@ -161,8 +163,8 @@ Return values: */ long long nissy_inverse( - const char cube[static NISSY_SIZE_CUBE], - char result[static NISSY_SIZE_CUBE] + const char cube[], /* NISSY_SIZE_CUBE */ + char result[] /* NISSY_SIZE_CUBE */ ); /* @@ -170,8 +172,10 @@ Apply the given sequence of moves on the given cube. Parameters: cube - The cube to move. + Required size: NISSY_SIZE_CUBE. moves - The moves to apply to the cube. Must be a NULL-terminated string. result - The return parameter for the resulting cube. + Required size: NISSY_SIZE_CUBE. Return values: NISSY_OK - The moves were applied succesfully. @@ -184,9 +188,9 @@ Return values: */ long long nissy_applymoves( - const char cube[static NISSY_SIZE_CUBE], + const char cube[], /* NISSY_SIZE_CUBE */ const char *moves, - char result[static NISSY_SIZE_CUBE] + char result[] /* NISSY_SIZE_CUBE */ ); /* @@ -194,8 +198,11 @@ Apply the single given transformation to the given cube. Parameters: cube - The cube to be transformed. + Required size: NISSY_SIZE_CUBE. transformation - The transformation in "(rotation|mirrored) __" format. + Required size: NISSY_SIZE_TRANSFORMATION. result - The return parameter for the resulting cube. + Required size: NISSY_SIZE_CUBE. Return values: NISSY_OK - The transformation was performed succesfully. @@ -206,9 +213,9 @@ Return values: */ long long nissy_applytrans( - const char cube[static NISSY_SIZE_CUBE], - const char transformation[static NISSY_SIZE_TRANSFORMATION], - char result[static NISSY_SIZE_CUBE] + const char cube[], /* NISSY_SIZE_CUBE */ + const char transformation[], /* NISSY_SIZE_TRANSFORMATION */ + char result[] /* NISSY_SIZE_CUBE */ ); /* @@ -256,6 +263,7 @@ Parameters: orient - The orientation of the cube, 0 <= orient < 24 options - Other options. result - The return parameter for the resulting cube. + Required size: NISSY_SIZE_CUBE. Return values: NISSY_OK - The cube was generated succesfully. @@ -270,7 +278,7 @@ nissy_getcube( long long co, long long orient, const char *options, - char result[static NISSY_SIZE_CUBE] + char result[] /* NISSY_SIZE_CUBE */ ); /* @@ -283,6 +291,7 @@ Parameters: solvers may use equivalent data. This identifier can be used e.g. as a filename or database key to save and retrieve the correct data for each solver, without duplication. + Required size: NISSY_SIZE_DATAID. Return values: NISSY_ERROR_INVALID_SOLVER - The given solver is not known. @@ -293,7 +302,7 @@ Return values: long long nissy_solverinfo( const char *solver, - char dataid[static NISSY_SIZE_DATAID] + char dataid[] /* NISSY_SIZE_DATAID */ ); /* @@ -350,6 +359,7 @@ Solve the given cube using the given solver and options. Parameters: cube - The cube to solver. + Required size: NISSY_SIZE_CUBE. solver - The name of the solver. See doc/solvers.md for a list. nissflag - The flags for NISS (linear, inverse, mixed, or combinations; see the constants at the top of this file). @@ -370,6 +380,7 @@ Parameters: separated by a '\n' (newline) and a '\0' (NULL character) terminates the list. stats - An array to store some statistics about the solve. + Required size: NISSY_SIZE_SOLVE_STATS. poll_status - A callback function that should return the current requested status for the solver (e.g. run, stop, pause, resume; see the constants at the top of this file). The @@ -391,7 +402,7 @@ Return values: */ long long nissy_solve( - const char cube[static NISSY_SIZE_CUBE], + const char cube[], /* NISSY_SIZE_CUBE */ const char *solver, unsigned nissflag, unsigned minmoves, @@ -403,7 +414,7 @@ nissy_solve( const unsigned char *data, unsigned sols_size, char *sols, - long long stats[static NISSY_SIZE_SOLVE_STATS], + long long stats[], /* NISSY_SIZE_SOLVE_STATS */ int (*poll_status)(void *), void *poll_status_data ); diff --git a/src/solvers/coord/common.h b/src/solvers/coord/common.h @@ -1,16 +1,16 @@ STATIC uint64_t coord_coord_generic( - const coord_t [static 1], cube_t, const unsigned char *); + const coord_t [NON_NULL], cube_t, const unsigned char *); STATIC cube_t coord_cube_generic( - const coord_t [static 1], uint64_t, const unsigned char *); + const coord_t [NON_NULL], uint64_t, const unsigned char *); STATIC bool coord_isnasty_generic( - const coord_t [static 1], uint64_t, const unsigned char *); -STATIC size_t coord_gendata_generic(const coord_t [static 1], unsigned char *); + const coord_t [NON_NULL], uint64_t, const unsigned char *); +STATIC size_t coord_gendata_generic(const coord_t [NON_NULL], unsigned char *); -STATIC bool solution_lastqt_cw(const solution_moves_t [static 1]); -STATIC bool coord_can_switch(const coord_t [static 1], const unsigned char *, +STATIC bool solution_lastqt_cw(const solution_moves_t [NON_NULL]); +STATIC bool coord_can_switch(const coord_t [NON_NULL], const unsigned char *, size_t, const uint8_t *); STATIC bool coord_is_solved( - const coord_t [static 1], uint64_t, const unsigned char *); + const coord_t [NON_NULL], uint64_t, const unsigned char *); STATIC cube_t coordinate_merge_ce(cube_t, cube_t); STATIC cube_t coordinate_merge_ec(cube_t, cube_t); @@ -18,7 +18,7 @@ STATIC cube_t coordinate_merge_cpco(cube_t, cube_t); STATIC uint64_t coord_coord_generic( - const coord_t coord[static 1], + const coord_t coord[NON_NULL], cube_t c, const unsigned char *data ) @@ -36,7 +36,7 @@ coord_coord_generic( STATIC cube_t coord_cube_generic( - const coord_t coord[static 1], + const coord_t coord[NON_NULL], uint64_t i, const unsigned char *data ) @@ -54,7 +54,7 @@ coord_cube_generic( STATIC bool coord_isnasty_generic( - const coord_t coord[static 1], + const coord_t coord[NON_NULL], uint64_t i, const unsigned char *data ) @@ -73,11 +73,12 @@ coord_isnasty_generic( STATIC size_t coord_gendata_generic( - const coord_t coord[static 1], + const coord_t coord[NON_NULL], unsigned char *data ) { - uint64_t i, j, n, t, nasty; + uint64_t i, j, n, nasty; + uint8_t t; unsigned char *datanoinfo; uint32_t *classttrep, *rep; size_t coord_datasize; @@ -122,16 +123,17 @@ coord_gendata_generic( } for (t = 0; t < NTRANS; t++) { - if (!((UINT64_C(1) << t) & coord->trans_mask)) + if (!((UINT64_C(1) << (uint64_t)t) & coord->trans_mask)) continue; j = coord->sym.coord(transform(c, t)); - classttrep[j] = + classttrep[j] = (uint32_t)( (n << COORD_CLASS_SHIFT) | (nasty << COORD_ISNASTY_SHIFT) | - (inverse_trans(t) << COORD_TTREP_SHIFT); + (inverse_trans(t) << COORD_TTREP_SHIFT) + ); } - rep[n++] = i; + rep[n++] = (uint32_t)i; } writetableinfo(&info, coord_datasize, data); @@ -144,21 +146,21 @@ coord_gendata_generic( } STATIC bool -solution_lastqt_cw(const solution_moves_t s[static 1]) +solution_lastqt_cw(const solution_moves_t s[NON_NULL]) { return are_lastmoves_singlecw(s->nmoves, s->moves) && are_lastmoves_singlecw(s->npremoves, s->premoves); } STATIC bool -solution_always_valid(const solution_moves_t s[static 1]) +solution_always_valid(const solution_moves_t s[NON_NULL]) { return true; } STATIC bool coord_can_switch( - const coord_t coord[static 1], + const coord_t coord[NON_NULL], const unsigned char *data, size_t n, const uint8_t *moves @@ -192,7 +194,7 @@ coord_can_switch( STATIC bool coord_is_solved( - const coord_t coord[static 1], + const coord_t coord[NON_NULL], uint64_t i, const unsigned char *data ) diff --git a/src/solvers/coord/gendata.h b/src/solvers/coord/gendata.h @@ -1,21 +1,21 @@ -STATIC size_t gendata_coord(const coord_t [static 1], unsigned char *); +STATIC size_t gendata_coord(const coord_t [NON_NULL], unsigned char *); STATIC size_t gendata_multicoord( - const multicoord_t [static 1], unsigned char *); + const multicoord_t [NON_NULL], unsigned char *); STATIC long long gendata_coord_dispatch(const char *, unsigned long long, unsigned char *); STATIC tableinfo_t genptable_coord( - const coord_t [static 1], const unsigned char *, unsigned char *); + const coord_t [NON_NULL], const unsigned char *, unsigned char *); STATIC uint64_t genptable_coord_init_solved( - const coord_t [static 1], const unsigned char *, unsigned char *); + const coord_t [NON_NULL], const unsigned char *, unsigned char *); STATIC bool switch_to_fromnew(uint64_t, uint64_t, uint64_t); -STATIC uint64_t genptable_coord_fillneighbors(const coord_t [static 1], +STATIC uint64_t genptable_coord_fillneighbors(const coord_t [NON_NULL], const unsigned char *, uint64_t, uint8_t, unsigned char *); -STATIC uint64_t genptable_coord_fillfromnew(const coord_t [static 1], +STATIC uint64_t genptable_coord_fillfromnew(const coord_t [NON_NULL], const unsigned char *, uint64_t, uint8_t, unsigned char *); STATIC uint8_t get_coord_pval( - const coord_t [static 1], const unsigned char *, uint64_t); + const coord_t [NON_NULL], const unsigned char *, uint64_t); STATIC void set_coord_pval( - const coord_t [static 1], unsigned char *, uint64_t, uint8_t); + const coord_t [NON_NULL], unsigned char *, uint64_t, uint8_t); STATIC long long gendata_coord_dispatch( @@ -40,7 +40,7 @@ gendata_coord_dispatch( } STATIC size_t -gendata_coord(const coord_t coord[static 1], unsigned char *buf) +gendata_coord(const coord_t coord[NON_NULL], unsigned char *buf) { uint64_t coord_dsize, tablesize, ninfo; unsigned char *pruningbuf, *coord_data; @@ -96,7 +96,7 @@ gendata_coord_error: } STATIC size_t -gendata_multicoord(const multicoord_t mcoord[static 1], unsigned char *buf) +gendata_multicoord(const multicoord_t mcoord[NON_NULL], unsigned char *buf) { unsigned char *b; size_t i, s, ret; @@ -141,12 +141,13 @@ gendata_multicoord(const multicoord_t mcoord[static 1], unsigned char *buf) STATIC tableinfo_t genptable_coord( - const coord_t coord[static 1], + const coord_t coord[NON_NULL], const unsigned char *data, unsigned char *table ) { - uint64_t tablesize, i, d, tot, t, nm; + uint64_t tablesize, i, tot, t, nm; + uint8_t d; tableinfo_t info; tablesize = DIV_ROUND_UP(coord->max, 2); @@ -170,7 +171,7 @@ genptable_coord( tot = info.distribution[0] = genptable_coord_init_solved(coord, data, table); - nm = popcount_u32(coord->moves_mask_gendata); + nm = popcount_u64(coord->moves_mask_gendata); for (d = 1; tot < coord->max && d < 15; d++) { t = 0; if (switch_to_fromnew(tot, coord->max, nm)) { @@ -204,7 +205,7 @@ genptable_coord( STATIC uint64_t genptable_coord_init_solved( - const coord_t coord[static 1], + const coord_t coord[NON_NULL], const unsigned char *coord_data, unsigned char *table ) @@ -238,7 +239,7 @@ switch_to_fromnew(uint64_t done, uint64_t max, uint64_t nm) STATIC uint64_t genptable_coord_fillneighbors( - const coord_t coord[static 1], + const coord_t coord[NON_NULL], const unsigned char *data, uint64_t i, uint8_t d, @@ -247,20 +248,21 @@ genptable_coord_fillneighbors( { bool isnasty; uint8_t m; - uint64_t ii, j, t, tot; + uint64_t ii, j, tot; + uint8_t t; cube_t c, moved; c = coord->cube(i, data); tot = 0; for (m = 0; m < NMOVES; m++) { - if (!((UINT32_C(1) << (uint32_t)m) & + if (!((UINT64_C(1) << (uint64_t)m) & coord->moves_mask_gendata)) continue; moved = move(c, m); ii = coord->coord(moved, data); isnasty = coord->isnasty(ii, data); for (t = 0; t < NTRANS && (t == 0 || isnasty); t++) { - if (!((UINT64_C(1) << t) & coord->trans_mask)) + if (!((UINT64_C(1) << (uint64_t)t) & coord->trans_mask)) continue; j = coord->coord(transform(moved, t), data); @@ -276,7 +278,7 @@ genptable_coord_fillneighbors( STATIC uint64_t genptable_coord_fillfromnew( - const coord_t coord[static 1], + const coord_t coord[NON_NULL], const unsigned char *data, uint64_t i, uint8_t d, @@ -285,14 +287,15 @@ genptable_coord_fillfromnew( { bool found; uint8_t m; - uint64_t tot, t, ii, j, nsim, sim[NTRANS]; + uint64_t tot, j, ii, nsim, sim[NTRANS]; + uint8_t t; cube_t c; tot = 0; c = coord->cube(i, data); for (t = 0, nsim = 0; t < NTRANS; t++) { - if (!((UINT64_C(1) << t) & coord->trans_mask)) + if (!((UINT64_C(1) << (uint64_t)t) & coord->trans_mask)) continue; ii = coord->coord(transform(c, t), data); @@ -305,7 +308,7 @@ genptable_coord_fillfromnew( for (j = 0, found = false; j < nsim && !found; j++) { c = coord->cube(sim[j], data); for (m = 0; m < NMOVES; m++) { - if (!((UINT32_C(1) << (uint32_t)m) & + if (!((UINT64_C(1) << (uint64_t)m) & coord->moves_mask_gendata)) continue; ii = coord->coord(move(c, m), data); @@ -331,7 +334,7 @@ genptable_coord_fillfromnew( STATIC uint8_t get_coord_pval( - const coord_t coord[static 1], + const coord_t coord[NON_NULL], const unsigned char *table, uint64_t i ) @@ -341,7 +344,7 @@ get_coord_pval( STATIC void set_coord_pval( - const coord_t coord[static 1], + const coord_t coord[NON_NULL], unsigned char *table, uint64_t i, uint8_t val diff --git a/src/solvers/coord/htr.h b/src/solvers/coord/htr.h @@ -4,7 +4,7 @@ STATIC bool coordinate_htr_isnasty(uint64_t, const unsigned char *); STATIC size_t coordinate_htr_gendata(unsigned char *); STATIC bool htr_checkmoves(bool *, uint8_t, const uint8_t *); -STATIC bool htr_solution_prune(const solution_moves_t [static 1]); +STATIC bool htr_solution_prune(const solution_moves_t [NON_NULL]); STATIC bool is_cp_htr(uint64_t, const unsigned char *); STATIC coord_t coordinate_htr = { @@ -97,7 +97,7 @@ htr_checkmoves(bool *f, uint8_t n, const uint8_t *moves) } STATIC bool -htr_solution_prune(const solution_moves_t s[static 1]) +htr_solution_prune(const solution_moves_t s[NON_NULL]) { bool f; diff --git a/src/solvers/coord/multisolve.h b/src/solvers/coord/multisolve.h @@ -16,20 +16,20 @@ typedef struct { const unsigned char *ptable[MAX_MULTICOORD_NCOORDS]; } dfsarg_solve_multicoord_t; -STATIC int64_t solve_multicoord(oriented_cube_t, multicoord_t [static 1], +STATIC int64_t solve_multicoord(oriented_cube_t, multicoord_t [NON_NULL], uint8_t, uint8_t, uint8_t, uint64_t, uint8_t, uint8_t, uint64_t, const unsigned char *, size_t, char *, int (*)(void *), void *); STATIC long long solve_multicoord_dispatch(oriented_cube_t, const char *, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned long long, const unsigned char *, unsigned, char *, - long long [static NISSY_SIZE_SOLVE_STATS], int (*)(void *), void *); + long long [SIZE(NISSY_SIZE_SOLVE_STATS)], int (*)(void *), void *); STATIC bool multicoord_solution_admissible( - const dfsarg_solve_multicoord_t [static 1]); -STATIC bool multicoord_dfs_stop(const dfsarg_solve_multicoord_t [static 1]); -STATIC int64_t solve_multicoord_dfs(dfsarg_solve_multicoord_t [static 1]); + const dfsarg_solve_multicoord_t [NON_NULL]); +STATIC bool multicoord_dfs_stop(const dfsarg_solve_multicoord_t [NON_NULL]); +STATIC int64_t solve_multicoord_dfs(dfsarg_solve_multicoord_t [NON_NULL]); STATIC bool -multicoord_solution_admissible(const dfsarg_solve_multicoord_t arg[static 1]) +multicoord_solution_admissible(const dfsarg_solve_multicoord_t arg[NON_NULL]) { uint8_t n, i; const coord_t *c; @@ -49,7 +49,7 @@ multicoord_solution_admissible(const dfsarg_solve_multicoord_t arg[static 1]) } STATIC bool -multicoord_dfs_stop(const dfsarg_solve_multicoord_t arg[static 1]) +multicoord_dfs_stop(const dfsarg_solve_multicoord_t arg[NON_NULL]) { uint8_t pval, i; uint64_t cval; @@ -69,11 +69,10 @@ multicoord_dfs_stop(const dfsarg_solve_multicoord_t arg[static 1]) } STATIC int64_t -solve_multicoord_dfs(dfsarg_solve_multicoord_t arg[static 1]) +solve_multicoord_dfs(dfsarg_solve_multicoord_t arg[NON_NULL]) { uint8_t m, l, i; - uint32_t mm; - uint64_t coord; + uint64_t mm, coord; int64_t n, ret; const coord_t *c; cube_t backup_cube, backup_inverse; @@ -108,7 +107,7 @@ solve_multicoord_dfs_notsolved: arg->solution_moves->nmoves++; for (m = 0; m < NMOVES; m++) { - if (!(mm & (UINT32_C(1) << (uint32_t)m))) + if (!(mm & (UINT64_C(1) << (uint64_t)m))) continue; arg->solution_moves->moves[l] = m; @@ -141,7 +140,7 @@ solve_multicoord_dispatch( const unsigned char *data, unsigned solutions_size, char *sols, - long long stats[static NISSY_SIZE_SOLVE_STATS], + long long stats[SIZE(NISSY_SIZE_SOLVE_STATS)], int (*poll_status)(void *), void *poll_status_data ) @@ -163,15 +162,16 @@ solve_multicoord_dispatch( return NISSY_ERROR_INVALID_SOLVER; } - return solve_multicoord(oc, mcoord, trans, minmoves, - maxmoves, maxsolutions, optimal, threads, data_size, data, - solutions_size, sols, poll_status, poll_status_data); + return solve_multicoord(oc, mcoord, trans, (uint8_t)minmoves, + (uint8_t)maxmoves, (uint8_t)maxsolutions, (uint8_t)optimal, + (uint8_t)threads, data_size, data, solutions_size, sols, + poll_status, poll_status_data); } STATIC int64_t solve_multicoord( oriented_cube_t oc, - multicoord_t mcoord [static 1], + multicoord_t mcoord [NON_NULL], uint8_t trans, uint8_t minmoves, uint8_t maxmoves, diff --git a/src/solvers/coord/solve.h b/src/solvers/coord/solve.h @@ -13,20 +13,20 @@ typedef struct { const unsigned char *ptable; } dfsarg_solve_coord_t; -STATIC int64_t solve_coord(oriented_cube_t, coord_t [static 1], uint8_t, +STATIC int64_t solve_coord(oriented_cube_t, coord_t [NON_NULL], uint8_t, uint8_t, uint8_t, uint8_t, uint64_t, uint8_t, uint8_t, uint64_t, const unsigned char *, size_t, char *, int (*)(void *), void *); STATIC long long solve_coord_dispatch(oriented_cube_t, const char *, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned long long, const unsigned char *, unsigned, char *, - long long [static NISSY_SIZE_SOLVE_STATS], int (*)(void *), void *); -STATIC bool coord_solution_admissible(const dfsarg_solve_coord_t [static 1]); -STATIC bool coord_continue_onnormal(const dfsarg_solve_coord_t [static 1]); -STATIC bool coord_continue_oninverse(const dfsarg_solve_coord_t [static 1]); -STATIC int64_t solve_coord_dfs(dfsarg_solve_coord_t [static 1]); + long long [SIZE(NISSY_SIZE_SOLVE_STATS)], int (*)(void *), void *); +STATIC bool coord_solution_admissible(const dfsarg_solve_coord_t [NON_NULL]); +STATIC bool coord_continue_onnormal(const dfsarg_solve_coord_t [NON_NULL]); +STATIC bool coord_continue_oninverse(const dfsarg_solve_coord_t [NON_NULL]); +STATIC int64_t solve_coord_dfs(dfsarg_solve_coord_t [NON_NULL]); STATIC bool -coord_solution_admissible(const dfsarg_solve_coord_t arg[static 1]) +coord_solution_admissible(const dfsarg_solve_coord_t arg[NON_NULL]) { uint8_t n; @@ -39,7 +39,7 @@ coord_solution_admissible(const dfsarg_solve_coord_t arg[static 1]) } STATIC bool -coord_continue_onnormal(const dfsarg_solve_coord_t arg[static 1]) +coord_continue_onnormal(const dfsarg_solve_coord_t arg[NON_NULL]) { uint8_t flag, nn, ni, swbound_n, swbound_i, pval; uint64_t coord; @@ -93,7 +93,7 @@ coord_continue_onnormal(const dfsarg_solve_coord_t arg[static 1]) } STATIC bool -coord_continue_oninverse(const dfsarg_solve_coord_t arg[static 1]) +coord_continue_oninverse(const dfsarg_solve_coord_t arg[NON_NULL]) { uint8_t flag, nn, ni, swbound_n, swbound_i, pval; uint64_t coord; @@ -147,12 +147,11 @@ coord_continue_oninverse(const dfsarg_solve_coord_t arg[static 1]) } STATIC int64_t -solve_coord_dfs(dfsarg_solve_coord_t arg[static 1]) +solve_coord_dfs(dfsarg_solve_coord_t arg[NON_NULL]) { bool lastbackup; uint8_t m, l, nnbackup, nibackup, nmoves; - uint32_t mm; - uint64_t coord; + uint64_t mm, coord; int64_t n, ret; cube_t backup_cube, backup_inverse; @@ -190,7 +189,7 @@ solve_coord_dfs(dfsarg_solve_coord_t arg[static 1]) arg->lastisnormal = true; for (m = 0; m < NMOVES; m++) { - if (!(mm & (UINT32_C(1) << (uint32_t)m))) + if (!(mm & (UINT64_C(1) << (uint64_t)m))) continue; arg->solution_moves->moves[l] = m; @@ -221,7 +220,7 @@ solve_coord_dfs(dfsarg_solve_coord_t arg[static 1]) arg->lastisnormal = false; for (m = 0; m < NMOVES; m++) { - if (!(mm & (UINT32_C(1) << (uint32_t)m))) + if (!(mm & (UINT64_C(1) << (uint64_t)m))) continue; arg->solution_moves->premoves[l] = m; @@ -258,7 +257,7 @@ solve_coord_dispatch( const unsigned char *data, unsigned solutions_size, char *sols, - long long stats[static NISSY_SIZE_SOLVE_STATS], + long long stats[SIZE(NISSY_SIZE_SOLVE_STATS)], int (*poll_status)(void *), void *poll_status_data ) @@ -280,15 +279,16 @@ solve_coord_dispatch( return NISSY_ERROR_INVALID_SOLVER; } - return solve_coord(oc, coord, trans, nissflag, minmoves, maxmoves, - maxsolutions, optimal, threads, data_size, data, + return solve_coord(oc, coord, trans, (uint8_t)nissflag, + (uint8_t)minmoves, (uint8_t)maxmoves, (uint8_t)maxsolutions, + (uint8_t)optimal, (uint8_t)threads, data_size, data, solutions_size, sols, poll_status, poll_status_data); } STATIC int64_t solve_coord( oriented_cube_t oc, - coord_t coord [static 1], + coord_t coord [NON_NULL], uint8_t trans, uint8_t nissflag, uint8_t minmoves, diff --git a/src/solvers/coord/types_macros.h b/src/solvers/coord/types_macros.h @@ -27,8 +27,8 @@ typedef struct { uint64_t moves_mask_gendata; uint64_t moves_mask_solve; uint64_t trans_mask; - bool (*is_admissible)(const solution_moves_t[static 1]); - bool (*solution_prune)(const solution_moves_t[static 1]); + bool (*is_admissible)(const solution_moves_t[NON_NULL]); + bool (*solution_prune)(const solution_moves_t[NON_NULL]); bool (*is_solvable)(cube_t); /* if is_solved is null, coord == 0 is used */ bool (*is_solved)(uint64_t, const unsigned char *); diff --git a/src/solvers/coord/utils.h b/src/solvers/coord/utils.h @@ -2,7 +2,7 @@ STATIC coord_t *parse_coord(size_t, const char *); STATIC multicoord_t *parse_multicoord(size_t, const char *); STATIC void parse_coord_and_trans( const char *, coord_t **, multicoord_t **, uint8_t *); -STATIC long long dataid_coord(const char *, char [static NISSY_SIZE_DATAID]); +STATIC long long dataid_coord(const char *, char [SIZE(NISSY_SIZE_DATAID)]); STATIC coord_t * parse_coord(size_t n, const char *coord) @@ -60,7 +60,7 @@ parse_coord_and_trans( } STATIC long long -dataid_coord(const char *ca, char dataid[static NISSY_SIZE_DATAID]) +dataid_coord(const char *ca, char dataid[SIZE(NISSY_SIZE_DATAID)]) { coord_t *c; multicoord_t *mc; diff --git a/src/solvers/dispatch.h b/src/solvers/dispatch.h @@ -1,7 +1,7 @@ typedef struct { const char *solvername; const char *prefix; - long long (*dataid)(const char *, char [static NISSY_SIZE_DATAID]); + long long (*dataid)(const char *, char [SIZE(NISSY_SIZE_DATAID)]); long long (*gendata)( const char *, unsigned long long, unsigned char *); long long (*checkdata)( @@ -9,7 +9,7 @@ typedef struct { long long (*solve)(oriented_cube_t, const char *, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned long long, const unsigned char *, unsigned, char *, - long long [static NISSY_SIZE_SOLVE_STATS], + long long [SIZE(NISSY_SIZE_SOLVE_STATS)], int (*)(void *), void *); } solver_dispatch_t; diff --git a/src/solvers/distribution.h b/src/solvers/distribution.h @@ -12,9 +12,9 @@ typedef struct { STATIC wrapthread_return_t getdistribution_runthread(void *); STATIC void getdistribution(const unsigned char *, - uint64_t [static INFO_DISTRIBUTION_LEN], const tableinfo_t [static 1]); -STATIC bool distribution_equal(const uint64_t [static INFO_DISTRIBUTION_LEN], - const uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t); + uint64_t [SIZE(INFO_DISTRIBUTION_LEN)], const tableinfo_t [NON_NULL]); +STATIC bool distribution_equal(const uint64_t [SIZE(INFO_DISTRIBUTION_LEN)], + const uint64_t [SIZE(INFO_DISTRIBUTION_LEN)], uint8_t); STATIC wrapthread_return_t getdistribution_runthread(void *arg) @@ -39,8 +39,8 @@ getdistribution_runthread(void *arg) STATIC void getdistribution( const unsigned char *table, - uint64_t distr[static INFO_DISTRIBUTION_LEN], - const tableinfo_t info[static 1] + uint64_t distr[SIZE(INFO_DISTRIBUTION_LEN)], + const tableinfo_t info[NON_NULL] ) { getdistribution_data_t targ[THREADS]; wrapthread_define_var_thread_t(thread[THREADS]); @@ -80,8 +80,8 @@ getdistribution( STATIC bool distribution_equal( - const uint64_t expected[static INFO_DISTRIBUTION_LEN], - const uint64_t actual[static INFO_DISTRIBUTION_LEN], + const uint64_t expected[SIZE(INFO_DISTRIBUTION_LEN)], + const uint64_t actual[SIZE(INFO_DISTRIBUTION_LEN)], uint8_t maxvalue ) { diff --git a/src/solvers/h48/coordinate.h b/src/solvers/h48/coordinate.h @@ -1,13 +1,13 @@ STATIC_INLINE uint64_t coord_h48( - cube_t, const uint32_t [static COCSEP_TABLESIZE], uint8_t); + cube_t, const uint32_t [SIZE(COCSEP_TABLESIZE)], uint8_t); STATIC_INLINE uint64_t coord_h48_edges(cube_t, uint64_t, uint8_t, uint8_t); STATIC_INLINE cube_t invcoord_h48( - uint64_t, const cube_t [static COCSEP_CLASSES], uint8_t); + uint64_t, const cube_t [SIZE(COCSEP_CLASSES)], uint8_t); STATIC_INLINE uint64_t coord_h48( cube_t c, - const uint32_t cocsepdata[static COCSEP_TABLESIZE], + const uint32_t cocsepdata[SIZE(COCSEP_TABLESIZE)], uint8_t h ) { @@ -47,7 +47,7 @@ returned cube is a transformed cube of one that gives the correct value. STATIC_INLINE cube_t invcoord_h48( uint64_t i, - const cube_t crep[static COCSEP_CLASSES], + const cube_t crep[SIZE(COCSEP_CLASSES)], uint8_t h ) { diff --git a/src/solvers/h48/distribution_h48.h b/src/solvers/h48/distribution_h48.h @@ -6,7 +6,7 @@ to have some duplication than to make these functions needlessly generic. STATIC wrapthread_return_t getdistribution_h48_runthread(void *); STATIC void getdistribution_h48(const unsigned char *, - uint64_t [static INFO_DISTRIBUTION_LEN], const tableinfo_t [static 1]); + uint64_t [SIZE(INFO_DISTRIBUTION_LEN)], const tableinfo_t [NON_NULL]); STATIC wrapthread_return_t getdistribution_h48_runthread(void *arg) @@ -39,8 +39,8 @@ getdistribution_h48_runthread(void *arg) STATIC void getdistribution_h48( const unsigned char *table, - uint64_t distr[static INFO_DISTRIBUTION_LEN], - const tableinfo_t info[static 1] + uint64_t distr[SIZE(INFO_DISTRIBUTION_LEN)], + const tableinfo_t info[NON_NULL] ) { getdistribution_data_t targ[THREADS]; wrapthread_define_var_thread_t(thread[THREADS]); diff --git a/src/solvers/h48/gendata_cocsep.h b/src/solvers/h48/gendata_cocsep.h @@ -1,13 +1,13 @@ STATIC size_t gendata_cocsep(unsigned char *, uint64_t *, cube_t *); -STATIC uint32_t gendata_cocsep_dfs(cocsep_dfs_arg_t [static 1]); +STATIC uint32_t gendata_cocsep_dfs(cocsep_dfs_arg_t [NON_NULL]); STATIC_INLINE bool gendata_cocsep_get_visited( - const uint8_t [static COCSEP_VISITEDSIZE], uint64_t); + const uint8_t [SIZE(COCSEP_VISITEDSIZE)], uint64_t); STATIC_INLINE void gendata_cocsep_set_visited( - uint8_t [static COCSEP_VISITEDSIZE], uint64_t); + uint8_t [SIZE(COCSEP_VISITEDSIZE)], uint64_t); STATIC_INLINE int8_t get_h48_cdata( - cube_t, const uint32_t [static COCSEP_TABLESIZE], uint32_t *); + cube_t, const uint32_t [SIZE(COCSEP_TABLESIZE)], uint32_t *); STATIC size_t gendata_cocsep( @@ -79,11 +79,10 @@ gendata_cocsep_return_size: } STATIC uint32_t -gendata_cocsep_dfs(cocsep_dfs_arg_t arg[static 1]) +gendata_cocsep_dfs(cocsep_dfs_arg_t arg[NON_NULL]) { - uint8_t m; + uint8_t m, t; uint32_t cc, class, ttrep, depth, olddepth, tinv; - uint64_t t; uint64_t i, j; cube_t d; cocsep_dfs_arg_t nextarg; @@ -105,7 +104,7 @@ gendata_cocsep_dfs(cocsep_dfs_arg_t arg[static 1]) d = transform_corners(arg->cube, t); j = coord_cocsep(d); if (i == j && arg->selfsim != NULL) - arg->selfsim[*arg->n] |= UINT64_C(1) << t; + arg->selfsim[*arg->n] |= UINT64_C(1) << (uint64_t)t; if (COCLASS(arg->buf32[j]) != UINT32_C(0xFFFF)) continue; gendata_cocsep_set_visited(arg->visited, j); @@ -135,7 +134,7 @@ gendata_cocsep_dfs(cocsep_dfs_arg_t arg[static 1]) STATIC_INLINE bool gendata_cocsep_get_visited( - const uint8_t a[static COCSEP_VISITEDSIZE], + const uint8_t a[SIZE(COCSEP_VISITEDSIZE)], uint64_t i ) { @@ -144,7 +143,7 @@ gendata_cocsep_get_visited( STATIC_INLINE void gendata_cocsep_set_visited( - uint8_t a[static COCSEP_VISITEDSIZE], + uint8_t a[SIZE(COCSEP_VISITEDSIZE)], uint64_t i ) { @@ -154,7 +153,7 @@ gendata_cocsep_set_visited( STATIC_INLINE int8_t get_h48_cdata( cube_t cube, - const uint32_t cocsepdata[static COCSEP_TABLESIZE], + const uint32_t cocsepdata[SIZE(COCSEP_TABLESIZE)], uint32_t *cdata ) { diff --git a/src/solvers/h48/gendata_eoesep.h b/src/solvers/h48/gendata_eoesep.h @@ -1,25 +1,25 @@ -STATIC uint64_t coord_eoesep_sym(cube_t, const uint32_t [static ESEP_MAX]); +STATIC uint64_t coord_eoesep_sym(cube_t, const uint32_t [SIZE(ESEP_MAX)]); STATIC size_t gendata_esep_classes( - uint32_t [static ESEP_MAX], uint16_t [static ESEP_CLASSES]); + uint32_t [SIZE(ESEP_MAX)], uint16_t [SIZE(ESEP_CLASSES)]); STATIC size_t gendata_eoesep(unsigned char *, uint8_t); -STATIC uint32_t gendata_eoesep_bfs(uint8_t, uint8_t [static EOESEP_BUF], - uint32_t [static ESEP_MAX], uint16_t [static ESEP_CLASSES]); -STATIC uint32_t gendata_eoesep_fromnew(uint8_t, uint8_t [static EOESEP_BUF], - uint32_t [static ESEP_MAX], uint16_t [static ESEP_CLASSES]); -STATIC uint32_t gendata_eoesep_fromdone(uint8_t, uint8_t [static EOESEP_BUF], - uint32_t [static ESEP_MAX], uint16_t [static ESEP_CLASSES]); +STATIC uint32_t gendata_eoesep_bfs(uint8_t, uint8_t [SIZE(EOESEP_BUF)], + uint32_t [SIZE(ESEP_MAX)], uint16_t [SIZE(ESEP_CLASSES)]); +STATIC uint32_t gendata_eoesep_fromnew(uint8_t, uint8_t [SIZE(EOESEP_BUF)], + uint32_t [SIZE(ESEP_MAX)], uint16_t [SIZE(ESEP_CLASSES)]); +STATIC uint32_t gendata_eoesep_fromdone(uint8_t, uint8_t [SIZE(EOESEP_BUF)], + uint32_t [SIZE(ESEP_MAX)], uint16_t [SIZE(ESEP_CLASSES)]); STATIC uint32_t gendata_eoesep_marksim(uint64_t, uint8_t, - uint8_t [static EOESEP_BUF], uint32_t [static ESEP_MAX]); + uint8_t [SIZE(EOESEP_BUF)], uint32_t [SIZE(ESEP_MAX)]); STATIC bool gendata_eoesep_next(cube_t, uint8_t, - uint8_t [static EOESEP_BUF], uint32_t [static ESEP_MAX]); + uint8_t [SIZE(EOESEP_BUF)], uint32_t [SIZE(ESEP_MAX)]); STATIC uint8_t get_eoesep_pval( - const uint8_t [static DIV_ROUND_UP(EOESEP_TABLESIZE, 2)], uint64_t); + const uint8_t [SIZE(DIV_ROUND_UP(EOESEP_TABLESIZE, 2))], uint64_t); STATIC uint8_t get_eoesep_pval_cube(const unsigned char *, cube_t); STATIC void set_eoesep_pval( - uint8_t [static DIV_ROUND_UP(EOESEP_TABLESIZE, 2)], uint64_t, uint8_t); + uint8_t [SIZE(DIV_ROUND_UP(EOESEP_TABLESIZE, 2))], uint64_t, uint8_t); STATIC uint64_t -coord_eoesep_sym(cube_t c, const uint32_t esep_classes[static ESEP_MAX]) +coord_eoesep_sym(cube_t c, const uint32_t esep_classes[SIZE(ESEP_MAX)]) { uint8_t ttrep; uint32_t edata, class; @@ -36,8 +36,8 @@ coord_eoesep_sym(cube_t c, const uint32_t esep_classes[static ESEP_MAX]) STATIC size_t gendata_esep_classes( - uint32_t esep_classes[static ESEP_MAX], - uint16_t rep[static ESEP_CLASSES] + uint32_t esep_classes[SIZE(ESEP_MAX)], + uint16_t rep[SIZE(ESEP_CLASSES)] ) { bool visited[ESEP_MAX]; @@ -59,7 +59,7 @@ gendata_esep_classes( esep_classes[j] = cl | ti; visited[j] = true; } - rep[class] = i; + rep[class] = (uint16_t)i; class++; } @@ -121,8 +121,8 @@ STATIC uint32_t gendata_eoesep_bfs( uint8_t d, uint8_t buf8[EOESEP_BUF], - uint32_t esep_classes[static ESEP_MAX], - uint16_t rep[static ESEP_CLASSES] + uint32_t esep_classes[SIZE(ESEP_MAX)], + uint16_t rep[SIZE(ESEP_CLASSES)] ) { if (d < 9) @@ -135,12 +135,13 @@ STATIC uint32_t gendata_eoesep_fromdone( uint8_t d, uint8_t buf8[EOESEP_BUF], - uint32_t esep_classes[static ESEP_MAX], - uint16_t rep[static ESEP_CLASSES] + uint32_t esep_classes[SIZE(ESEP_MAX)], + uint16_t rep[SIZE(ESEP_CLASSES)] ) { uint8_t pval; - uint64_t i, esep, eo, coord, done; + uint32_t done; + uint64_t i, esep, eo, coord; done = 0; for (i = 0; i < ESEP_CLASSES; i++) { @@ -164,12 +165,13 @@ STATIC uint32_t gendata_eoesep_fromnew( uint8_t d, uint8_t buf8[EOESEP_BUF], - uint32_t esep_classes[static ESEP_MAX], - uint16_t rep[static ESEP_CLASSES] + uint32_t esep_classes[SIZE(ESEP_MAX)], + uint16_t rep[SIZE(ESEP_CLASSES)] ) { uint8_t pval; - uint64_t i, esep, eo, coord, done; + uint32_t done; + uint64_t i, esep, eo, coord; cube_t c; done = 0; @@ -196,8 +198,8 @@ STATIC uint32_t gendata_eoesep_marksim( uint64_t i, uint8_t d, - uint8_t buf8[static EOESEP_BUF], - uint32_t esep_classes[static ESEP_MAX] + uint8_t buf8[SIZE(EOESEP_BUF)], + uint32_t esep_classes[SIZE(ESEP_MAX)] ) { uint8_t t, m, pval; @@ -227,8 +229,8 @@ STATIC bool gendata_eoesep_next( cube_t c, uint8_t d, - uint8_t buf8[static EOESEP_BUF], - uint32_t esep_classes[static ESEP_MAX] + uint8_t buf8[SIZE(EOESEP_BUF)], + uint32_t esep_classes[SIZE(ESEP_MAX)] ) { uint8_t m, t, pval; @@ -251,7 +253,7 @@ gendata_eoesep_next( STATIC uint8_t get_eoesep_pval( - const uint8_t table[static DIV_ROUND_UP(EOESEP_TABLESIZE, 2)], + const uint8_t table[SIZE(DIV_ROUND_UP(EOESEP_TABLESIZE, 2))], uint64_t i ) { @@ -270,7 +272,7 @@ get_eoesep_pval_cube(const unsigned char *data, cube_t c) STATIC void set_eoesep_pval( - uint8_t table[static DIV_ROUND_UP(EOESEP_TABLESIZE, 2)], + uint8_t table[SIZE(DIV_ROUND_UP(EOESEP_TABLESIZE, 2))], uint64_t i, uint8_t val ) diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h @@ -1,15 +1,15 @@ STATIC long long gendata_h48_dispatch( const char *, unsigned long long, unsigned char *); -STATIC uint64_t gendata_h48short(gendata_h48short_arg_t [static 1]); -STATIC int64_t gendata_h48(gendata_h48_arg_t [static 1]); -STATIC void gendata_h48_maintable(gendata_h48_arg_t [static 1]); +STATIC uint64_t gendata_h48short(gendata_h48short_arg_t [NON_NULL]); +STATIC int64_t gendata_h48(gendata_h48_arg_t [NON_NULL]); +STATIC void gendata_h48_maintable(gendata_h48_arg_t [NON_NULL]); STATIC wrapthread_return_t gendata_h48_runthread(void *); -STATIC_INLINE void gendata_h48_mark(gendata_h48_mark_t [static 1]); +STATIC_INLINE void gendata_h48_mark(gendata_h48_mark_t [NON_NULL]); STATIC_INLINE bool gendata_h48_dfs_stop( - cube_t, int8_t, h48_dfs_arg_t [static 1]); -STATIC void gendata_h48_dfs(h48_dfs_arg_t [static 1]); -STATIC tableinfo_t makeinfo_h48(gendata_h48_arg_t [static 1]); + cube_t, int8_t, h48_dfs_arg_t [NON_NULL]); +STATIC void gendata_h48_dfs(h48_dfs_arg_t [NON_NULL]); +STATIC tableinfo_t makeinfo_h48(gendata_h48_arg_t [NON_NULL]); STATIC const uint32_t *get_cocsepdata_constptr(const unsigned char *); STATIC const unsigned char *get_h48data_constptr(const unsigned char *); @@ -19,7 +19,7 @@ STATIC_INLINE void set_h48_pval(unsigned char *, uint64_t, uint8_t); STATIC_INLINE uint8_t get_h48_pvalmin(const unsigned char *, uint64_t); STATIC_INLINE void set_h48_pvalmin(unsigned char *, uint64_t, uint8_t); STATIC_INLINE uint8_t get_h48_pval_and_min( - const unsigned char *, uint64_t, uint8_t [static 1]); + const unsigned char *, uint64_t, uint8_t [NON_NULL]); STATIC long long gendata_h48_dispatch( @@ -43,7 +43,7 @@ gendata_h48_dispatch( } STATIC uint64_t -gendata_h48short(gendata_h48short_arg_t arg[static 1]) +gendata_h48short(gendata_h48short_arg_t arg[NON_NULL]) { uint8_t i, m; uint64_t coord; @@ -77,7 +77,7 @@ gendata_h48short(gendata_h48short_arg_t arg[static 1]) } STATIC int64_t -gendata_h48(gendata_h48_arg_t arg[static 1]) +gendata_h48(gendata_h48_arg_t arg[NON_NULL]) { uint64_t size, cocsepsize, h48size, eoesepsize; long long r; @@ -149,7 +149,7 @@ gendata_h48(gendata_h48_arg_t arg[static 1]) } STATIC void -gendata_h48_maintable(gendata_h48_arg_t arg[static 1]) +gendata_h48_maintable(gendata_h48_arg_t arg[NON_NULL]) { /* * A good base value for the h48 tables have few positions with value @@ -264,7 +264,7 @@ gendata_h48_maintable(gendata_h48_arg_t arg[static 1]) velocity = count; /* We plan to log 10 times */ - sleeptime = (100*(nshort-velocity)) / velocity; + sleeptime = (int)((100*(nshort-velocity)) / velocity); done = count; while (nshort - done > (velocity * sleeptime) / 1000) { @@ -320,7 +320,7 @@ gendata_h48_runthread(void *arg) mutex = H48_LINE(coord) % CHUNKS; wrapthread_mutex_lock(dfsarg->table_mutex[mutex]); set_h48_pval(dfsarg->table, coordext, 0); - set_h48_pvalmin(dfsarg->table, coordmin, kv.val); + set_h48_pvalmin(dfsarg->table, coordmin, (uint8_t)kv.val); wrapthread_mutex_unlock(dfsarg->table_mutex[mutex]); } else { dfsarg->cube = invcoord_h48(kv.key, dfsarg->crep, 11); @@ -332,7 +332,7 @@ gendata_h48_runthread(void *arg) } STATIC void -gendata_h48_dfs(h48_dfs_arg_t arg[static 1]) +gendata_h48_dfs(h48_dfs_arg_t arg[NON_NULL]) { int8_t d; uint8_t m[4]; @@ -411,7 +411,7 @@ gendata_h48_dfs(h48_dfs_arg_t arg[static 1]) } STATIC_INLINE void -gendata_h48_mark(gendata_h48_mark_t arg[static 1]) +gendata_h48_mark(gendata_h48_mark_t arg[NON_NULL]) { uint8_t oldval, newval, v; uint64_t coord, coordext, coordmin; @@ -435,7 +435,7 @@ gendata_h48_mark(gendata_h48_mark_t arg[static 1]) } STATIC_INLINE bool -gendata_h48_dfs_stop(cube_t cube, int8_t d, h48_dfs_arg_t arg[static 1]) +gendata_h48_dfs_stop(cube_t cube, int8_t d, h48_dfs_arg_t arg[NON_NULL]) { uint64_t val; uint64_t coord, coordext; @@ -463,7 +463,7 @@ gendata_h48_dfs_stop(cube_t cube, int8_t d, h48_dfs_arg_t arg[static 1]) } STATIC tableinfo_t -makeinfo_h48(gendata_h48_arg_t arg[static 1]) +makeinfo_h48(gendata_h48_arg_t arg[NON_NULL]) { tableinfo_t info; @@ -533,7 +533,7 @@ STATIC_INLINE uint8_t get_h48_pval_and_min( const unsigned char *table, uint64_t coord_noext, - uint8_t pval_min[static 1] + uint8_t pval_min[NON_NULL] ) { uint64_t iext, imin; diff --git a/src/solvers/h48/map.h b/src/solvers/h48/map.h @@ -1,13 +1,13 @@ -STATIC void h48map_create(h48map_t [static 1], uint64_t, uint64_t); -STATIC void h48map_clear(h48map_t [static 1]); -STATIC void h48map_destroy(h48map_t [static 1]); -STATIC uint64_t h48map_lookup(h48map_t [static 1], uint64_t); -STATIC void h48map_insertmin(h48map_t [static 1], uint64_t, uint64_t); -STATIC uint64_t h48map_value(h48map_t [static 1], uint64_t); -STATIC kvpair_t h48map_nextkvpair(h48map_t [static 1], uint64_t [static 1]); +STATIC void h48map_create(h48map_t [NON_NULL], uint64_t, uint64_t); +STATIC void h48map_clear(h48map_t [NON_NULL]); +STATIC void h48map_destroy(h48map_t [NON_NULL]); +STATIC uint64_t h48map_lookup(h48map_t [NON_NULL], uint64_t); +STATIC void h48map_insertmin(h48map_t [NON_NULL], uint64_t, uint64_t); +STATIC uint64_t h48map_value(h48map_t [NON_NULL], uint64_t); +STATIC kvpair_t h48map_nextkvpair(h48map_t [NON_NULL], uint64_t [NON_NULL]); STATIC void -h48map_create(h48map_t map[static 1], uint64_t capacity, uint64_t randomizer) +h48map_create(h48map_t map[NON_NULL], uint64_t capacity, uint64_t randomizer) { map->capacity = capacity; map->randomizer = randomizer; @@ -17,20 +17,20 @@ h48map_create(h48map_t map[static 1], uint64_t capacity, uint64_t randomizer) } STATIC void -h48map_clear(h48map_t map[static 1]) +h48map_clear(h48map_t map[NON_NULL]) { memset(map->table, 0xFF, map->capacity * sizeof(uint64_t)); map->n = 0; } STATIC void -h48map_destroy(h48map_t map[static 1]) +h48map_destroy(h48map_t map[NON_NULL]) { free(map->table); } STATIC_INLINE uint64_t -h48map_lookup(h48map_t map[static 1], uint64_t x) +h48map_lookup(h48map_t map[NON_NULL], uint64_t x) { uint64_t hash, i; @@ -44,7 +44,7 @@ h48map_lookup(h48map_t map[static 1], uint64_t x) } STATIC_INLINE void -h48map_insertmin(h48map_t map[static 1], uint64_t key, uint64_t val) +h48map_insertmin(h48map_t map[NON_NULL], uint64_t key, uint64_t val) { uint64_t i, oldval, min; @@ -57,13 +57,13 @@ h48map_insertmin(h48map_t map[static 1], uint64_t key, uint64_t val) } STATIC_INLINE uint64_t -h48map_value(h48map_t map[static 1], uint64_t key) +h48map_value(h48map_t map[NON_NULL], uint64_t key) { return map->table[h48map_lookup(map, key)] >> MAP_KEYSHIFT; } STATIC kvpair_t -h48map_nextkvpair(h48map_t map[static 1], uint64_t p[static 1]) +h48map_nextkvpair(h48map_t map[NON_NULL], uint64_t p[NON_NULL]) { kvpair_t kv; uint64_t pair; diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h @@ -64,27 +64,27 @@ typedef struct { STATIC long long solve_h48_dispatch(oriented_cube_t, const char *, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned long long, const unsigned char *, unsigned, char *, - long long [static NISSY_SIZE_SOLVE_STATS], int (*)(void *), void *); -STATIC_INLINE void h48_prune_pipeline(dfsarg_solve_h48_t [static 1], - h48_prune_t [static NMOVES], uint8_t, bool); + long long [SIZE(NISSY_SIZE_SOLVE_STATS)], int (*)(void *), void *); +STATIC_INLINE void h48_prune_pipeline(dfsarg_solve_h48_t [NON_NULL], + h48_prune_t [SIZE(NMOVES)], uint8_t, bool); STATIC_INLINE uint8_t h48_prune_lookup( - uint64_t, cube_t, dfsarg_solve_h48_t [static 1]); + uint64_t, cube_t, dfsarg_solve_h48_t [NON_NULL]); STATIC_INLINE uint8_t h48_prune_lookup_nocoord( - cube_t, dfsarg_solve_h48_t [static 1]); -STATIC_INLINE void h48_prune_restore_normal(const h48_prune_t [static 1], - dfsarg_solve_h48_t [static 1], uint8_t); -STATIC_INLINE void h48_prune_restore_inverse(const h48_prune_t [static 1], - dfsarg_solve_h48_t [static 1], uint8_t); + cube_t, dfsarg_solve_h48_t [NON_NULL]); +STATIC_INLINE void h48_prune_restore_normal(const h48_prune_t [NON_NULL], + dfsarg_solve_h48_t [NON_NULL], uint8_t); +STATIC_INLINE void h48_prune_restore_inverse(const h48_prune_t [NON_NULL], + dfsarg_solve_h48_t [NON_NULL], uint8_t); STATIC int64_t solve_h48_maketasks( - dfsarg_solve_h48_t [static 1], dfsarg_solve_h48_maketasks_t [static 1], - solve_h48_task_t [static H48_STARTING_CUBES], int [static 1]); + dfsarg_solve_h48_t [NON_NULL], dfsarg_solve_h48_maketasks_t [NON_NULL], + solve_h48_task_t [SIZE(H48_STARTING_CUBES)], int [NON_NULL]); STATIC wrapthread_return_t solve_h48_runthread(void *); -STATIC int64_t solve_h48_dfs(dfsarg_solve_h48_t [static 1]); -STATIC void solve_h48_log_solutions(solution_list_t [static 1], size_t); +STATIC int64_t solve_h48_dfs(dfsarg_solve_h48_t [NON_NULL]); +STATIC void solve_h48_log_solutions(solution_list_t [NON_NULL], size_t); STATIC int solve_h48_compare_tasks(const void *, const void *); STATIC int64_t solve_h48(oriented_cube_t, uint8_t, uint8_t, uint64_t, uint8_t, uint8_t, uint64_t, const unsigned char *, size_t, char *, - long long [static NISSY_SIZE_SOLVE_STATS], int (*)(void *), void *); + long long [SIZE(NISSY_SIZE_SOLVE_STATS)], int (*)(void *), void *); STATIC long long solve_h48_dispatch( oriented_cube_t oc, @@ -99,7 +99,7 @@ STATIC long long solve_h48_dispatch( const unsigned char *data, unsigned sols_size, char *sols, - long long stats[static NISSY_SIZE_SOLVE_STATS], + long long stats[SIZE(NISSY_SIZE_SOLVE_STATS)], int (*poll_status)(void *), void *poll_status_data ) @@ -111,7 +111,8 @@ STATIC long long solve_h48_dispatch( if (err != NISSY_OK) return err; - return solve_h48(oc, minmoves, maxmoves, maxsols, optimal, threads, + return solve_h48(oc, (uint8_t)minmoves, (uint8_t)maxmoves, + (uint8_t)maxsols, (uint8_t)optimal, (uint8_t)threads, data_size, data, sols_size, sols, stats, poll_status, poll_status_data); } @@ -120,7 +121,7 @@ STATIC_INLINE uint8_t h48_prune_lookup( uint64_t coord, cube_t cube, - dfsarg_solve_h48_t arg[static 1] + dfsarg_solve_h48_t arg[NON_NULL] ) { uint8_t p, pmin, pe; @@ -139,7 +140,7 @@ h48_prune_lookup( STATIC_INLINE uint8_t h48_prune_lookup_nocoord( cube_t cube, - dfsarg_solve_h48_t arg[static 1] + dfsarg_solve_h48_t arg[NON_NULL] ) { uint32_t cdata; @@ -152,8 +153,8 @@ h48_prune_lookup_nocoord( STATIC_INLINE void h48_prune_pipeline( - dfsarg_solve_h48_t arg[static 1], - h48_prune_t prune[static NMOVES], + dfsarg_solve_h48_t arg[NON_NULL], + h48_prune_t prune[SIZE(NMOVES)], uint8_t target, bool normal ) @@ -252,8 +253,8 @@ h48_prune_pipeline( STATIC_INLINE void h48_prune_restore_normal( - const h48_prune_t prune[static 1], - dfsarg_solve_h48_t arg[static 1], + const h48_prune_t prune[NON_NULL], + dfsarg_solve_h48_t arg[NON_NULL], uint8_t target ) { @@ -276,8 +277,8 @@ h48_prune_restore_normal( STATIC_INLINE void h48_prune_restore_inverse( - const h48_prune_t prune[static 1], - dfsarg_solve_h48_t arg[static 1], + const h48_prune_t prune[NON_NULL], + dfsarg_solve_h48_t arg[NON_NULL], uint8_t target ) { @@ -299,7 +300,7 @@ h48_prune_restore_inverse( } STATIC int64_t -solve_h48_dfs(dfsarg_solve_h48_t arg[static 1]) +solve_h48_dfs(dfsarg_solve_h48_t arg[NON_NULL]) { int64_t ret, n; uint8_t m, nm, nn, ni, target; @@ -343,7 +344,7 @@ solve_h48_dfs(dfsarg_solve_h48_t arg[static 1]) backup_inverse = arg->inverse; ret = 0; - if (popcount_u32(mm_normal) <= popcount_u32(mm_inverse)) { + if (popcount_u64(mm_normal) <= popcount_u64(mm_inverse)) { h48_prune_pipeline(arg, prune, target, true); arg->solution_moves->nmoves++; for (m = 0; m < NMOVES; m++) { @@ -450,14 +451,13 @@ solve_h48_runthread_end: STATIC int64_t solve_h48_maketasks( - dfsarg_solve_h48_t solve_arg[static 1], - dfsarg_solve_h48_maketasks_t mtarg[static 1], - solve_h48_task_t tasks[static H48_STARTING_CUBES], - int ntasks[static 1] + dfsarg_solve_h48_t solve_arg[NON_NULL], + dfsarg_solve_h48_maketasks_t mtarg[NON_NULL], + solve_h48_task_t tasks[SIZE(H48_STARTING_CUBES)], + int ntasks[NON_NULL] ) { - int r; - int64_t appret; + int64_t r, appret; uint8_t m, t; uint64_t mm; cube_t backup_cube; @@ -524,7 +524,7 @@ solve_h48_maketasks( } STATIC void -solve_h48_log_solutions(solution_list_t s[static 1], size_t e) +solve_h48_log_solutions(solution_list_t s[NON_NULL], size_t e) { size_t i; char b; @@ -561,7 +561,7 @@ solve_h48( const unsigned char *data, size_t solutions_size, char *solutions, - long long stats[static NISSY_SIZE_SOLVE_STATS], + long long stats[SIZE(NISSY_SIZE_SOLVE_STATS)], int (*poll_status)(void *), void *poll_status_data ) diff --git a/src/solvers/h48/utils.h b/src/solvers/h48/utils.h @@ -4,11 +4,11 @@ #define H48_HMAX UINT8_C(7) #endif -long long parse_h48h(const char *, uint8_t [static 1]); -STATIC long long dataid_h48(const char *, char [static NISSY_SIZE_DATAID]); +long long parse_h48h(const char *, uint8_t [NON_NULL]); +STATIC long long dataid_h48(const char *, char [SIZE(NISSY_SIZE_DATAID)]); long long -parse_h48h(const char *buf, uint8_t h[static 1]) +parse_h48h(const char *buf, uint8_t h[NON_NULL]) { char format_error_msg[100]; sprintf(format_error_msg, "[H48] Error parsing H48 solver: must be in " @@ -29,7 +29,7 @@ parse_h48h(const char *buf, uint8_t h[static 1]) goto parse_h48h_error; } - *h = atoi(buf); + *h = (uint8_t)atoi(buf); if (*h > H48_HMAX) { LOG("[H48] Invalid value %" PRIu8 " for parameter h (must be " "at most %" PRIu8 ")\n", *h, H48_HMAX); @@ -51,7 +51,7 @@ parse_h48h_error: } STATIC long long -dataid_h48(const char *str, char buf[static NISSY_SIZE_DATAID]) +dataid_h48(const char *str, char buf[SIZE(NISSY_SIZE_DATAID)]) { uint8_t h; long long err; diff --git a/src/solvers/solutions.h b/src/solvers/solutions.h @@ -1,39 +1,39 @@ -STATIC void solution_moves_reset(solution_moves_t [static 1]); -STATIC void solution_moves_transform(solution_moves_t [static 1], size_t, +STATIC void solution_moves_reset(solution_moves_t [NON_NULL]); +STATIC void solution_moves_transform(solution_moves_t [NON_NULL], size_t, uint8_t); -STATIC void solution_moves_reorient(solution_moves_t [static 1], uint8_t); -STATIC bool solution_list_init(solution_list_t [static 1], size_t, char *); +STATIC void solution_moves_reorient(solution_moves_t [NON_NULL], uint8_t); +STATIC bool solution_list_init(solution_list_t [NON_NULL], size_t, char *); STATIC bool solution_moves_equal( - const solution_moves_t [static 1], const solution_moves_t [static 1]); -STATIC bool last_solution_is_duplicate(const solution_list_t [static 1]); -STATIC bool appendchar(solution_list_t [static 1], char); + const solution_moves_t [NON_NULL], const solution_moves_t [NON_NULL]); +STATIC bool last_solution_is_duplicate(const solution_list_t [NON_NULL]); +STATIC bool appendchar(solution_list_t [NON_NULL], char); STATIC bool appendnormal( - const solution_moves_t [static 1], solution_list_t [static 1]); + const solution_moves_t [NON_NULL], solution_list_t [NON_NULL]); STATIC bool appendinverse( - const solution_moves_t [static 1], solution_list_t [static 1]); -STATIC void appendsolution_dfs(const solution_moves_t [static 1], size_t, - const uint64_t *, size_t, uint8_t *, const solution_settings_t [static 1], - solution_list_t [static 1], - solution_moves_t [static NTRANS * SOLUTION_MAXLEN], int64_t [static 1]); -STATIC int64_t appendsolution(const solution_moves_t [static 1], - size_t, const uint64_t *, const solution_settings_t [static 1], - solution_list_t [static 1]); -STATIC bool solutions_done(const solution_list_t [static 1], - const solution_settings_t [static 1], int8_t depth); + const solution_moves_t [NON_NULL], solution_list_t [NON_NULL]); +STATIC void appendsolution_dfs(const solution_moves_t [NON_NULL], size_t, + const uint64_t *, size_t, uint8_t *, const solution_settings_t [NON_NULL], + solution_list_t [NON_NULL], + solution_moves_t [SIZE(NTRANS * SOLUTION_MAXLEN)], int64_t [NON_NULL]); +STATIC int64_t appendsolution(const solution_moves_t [NON_NULL], + size_t, const uint64_t *, const solution_settings_t [NON_NULL], + solution_list_t [NON_NULL]); +STATIC bool solutions_done(const solution_list_t [NON_NULL], + const solution_settings_t [NON_NULL], int8_t depth); STATIC void -solution_moves_reset(solution_moves_t sol[static 1]) +solution_moves_reset(solution_moves_t sol[NON_NULL]) { sol->nmoves = 0; sol->npremoves = 0; } STATIC void -solution_moves_transform(solution_moves_t moves[static 1], size_t z, uint8_t t) +solution_moves_transform(solution_moves_t moves[NON_NULL], size_t z, uint8_t t) { uint8_t i; - for (i = z; i < moves->nmoves; i++) + for (i = (uint8_t)z; i < moves->nmoves; i++) moves->moves[i] = transform_move(moves->moves[i], t); for (i = 0; i < moves->npremoves; i++) @@ -41,7 +41,7 @@ solution_moves_transform(solution_moves_t moves[static 1], size_t z, uint8_t t) } STATIC void -solution_moves_reorient(solution_moves_t moves[static 1], uint8_t or) +solution_moves_reorient(solution_moves_t moves[NON_NULL], uint8_t or) { uint8_t i; @@ -55,7 +55,7 @@ solution_moves_reorient(solution_moves_t moves[static 1], uint8_t or) } STATIC bool -solution_list_init(solution_list_t sols[static 1], size_t n, char *buf) +solution_list_init(solution_list_t sols[NON_NULL], size_t n, char *buf) { if (n == 0) return false; @@ -72,8 +72,8 @@ solution_list_init(solution_list_t sols[static 1], size_t n, char *buf) STATIC bool solution_moves_equal( - const solution_moves_t a[static 1], - const solution_moves_t b[static 1] + const solution_moves_t a[NON_NULL], + const solution_moves_t b[NON_NULL] ) { uint8_t i; @@ -93,7 +93,7 @@ solution_moves_equal( } STATIC bool -last_solution_is_duplicate(const solution_list_t l[static 1]) +last_solution_is_duplicate(const solution_list_t l[NON_NULL]) { size_t i, j; @@ -119,7 +119,7 @@ last_solution_is_duplicate(const solution_list_t l[static 1]) } STATIC bool -appendchar(solution_list_t solutions[static 1], char c) +appendchar(solution_list_t solutions[NON_NULL], char c) { if (solutions->size <= solutions->used) return false; @@ -131,8 +131,8 @@ appendchar(solution_list_t solutions[static 1], char c) STATIC bool appendnormal( - const solution_moves_t moves[static 1], - solution_list_t list[static 1] + const solution_moves_t moves[NON_NULL], + solution_list_t list[NON_NULL] ) { int64_t strl; @@ -150,8 +150,8 @@ appendnormal( STATIC bool appendinverse( - const solution_moves_t moves[static 1], - solution_list_t list[static 1] + const solution_moves_t moves[NON_NULL], + solution_list_t list[NON_NULL] ) { int64_t strl; @@ -172,15 +172,15 @@ appendinverse( STATIC void appendsolution_dfs( - const solution_moves_t moves[static 1], + const solution_moves_t moves[NON_NULL], size_t ntmask, const uint64_t *tmask, size_t itm, uint8_t *tt, - const solution_settings_t settings[static 1], - solution_list_t list[static 1], - solution_moves_t tsol[static NTRANS * SOLUTION_MAXLEN], - int64_t r[static 1] + const solution_settings_t settings[NON_NULL], + solution_list_t list[NON_NULL], + solution_moves_t tsol[SIZE(NTRANS * SOLUTION_MAXLEN)], + int64_t r[NON_NULL] ) { /* @@ -276,11 +276,11 @@ appendsolution_dfs_error_buffer: STATIC int64_t appendsolution( - const solution_moves_t moves[static 1], + const solution_moves_t moves[NON_NULL], size_t ntmask, const uint64_t *tmask, - const solution_settings_t settings[static 1], - solution_list_t list[static 1] + const solution_settings_t settings[NON_NULL], + solution_list_t list[NON_NULL] ) { int64_t r; @@ -329,8 +329,8 @@ appendsolution_error_solution_length: STATIC bool solutions_done( - const solution_list_t list[static 1], - const solution_settings_t settings[static 1], + const solution_list_t list[NON_NULL], + const solution_settings_t settings[NON_NULL], int8_t depth ) { diff --git a/src/solvers/tables.h b/src/solvers/tables.h @@ -1,17 +1,17 @@ STATIC uint64_t read_unaligned_u64( - const unsigned char [static sizeof(uint64_t)]); + const unsigned char [SIZE(sizeof(uint64_t))]); STATIC void write_unaligned_u64( - unsigned char [static sizeof(uint64_t)], uint64_t); + unsigned char [SIZE(sizeof(uint64_t))], uint64_t); STATIC int64_t readtableinfo( - size_t, const unsigned char *, tableinfo_t [static 1]); + size_t, const unsigned char *, tableinfo_t [NON_NULL]); STATIC int64_t readtableinfo_n( - size_t, const unsigned char *, uint8_t, tableinfo_t [static 1]); + size_t, const unsigned char *, uint8_t, tableinfo_t [NON_NULL]); STATIC int64_t writetableinfo( - const tableinfo_t [static 1], size_t, unsigned char *); -STATIC void append_name(tableinfo_t [static 1], const char *); + const tableinfo_t [NON_NULL], size_t, unsigned char *); +STATIC void append_name(tableinfo_t [NON_NULL], const char *); STATIC uint64_t -read_unaligned_u64(const unsigned char buf[static sizeof(uint64_t)]) +read_unaligned_u64(const unsigned char buf[SIZE(sizeof(uint64_t))]) { uint64_t ret; @@ -21,7 +21,7 @@ read_unaligned_u64(const unsigned char buf[static sizeof(uint64_t)]) } STATIC void -write_unaligned_u64(unsigned char buf[static sizeof(uint64_t)], uint64_t x) +write_unaligned_u64(unsigned char buf[SIZE(sizeof(uint64_t))], uint64_t x) { memcpy(buf, &x, sizeof(uint64_t)); } @@ -30,7 +30,7 @@ STATIC int64_t readtableinfo( size_t buf_size, const unsigned char *buf, - tableinfo_t info[static 1] + tableinfo_t info[NON_NULL] ) { size_t i; @@ -75,7 +75,7 @@ readtableinfo_n( size_t buf_size, const unsigned char *buf, uint8_t n, - tableinfo_t info[static 1] + tableinfo_t info[NON_NULL] ) { int64_t ret; @@ -89,7 +89,7 @@ readtableinfo_n( STATIC int64_t writetableinfo( - const tableinfo_t info[static 1], + const tableinfo_t info[NON_NULL], size_t data_size, unsigned char *buf ) @@ -138,9 +138,9 @@ writetableinfo( } STATIC void -append_name(tableinfo_t info[static 1], const char *str) +append_name(tableinfo_t info[NON_NULL], const char *str) { - int i, j; + size_t i, j; for (i = 0, j = strlen(info->solver); str[i] != '\0'; i++, j++) info->solver[j] = str[i]; diff --git a/src/utils/compilers.h b/src/utils/compilers.h @@ -1,13 +1,24 @@ #if defined(__GNUC__) -#define unused __attribute__((unused)) +#define UNUSED __attribute__((unused)) +#define SIZE(x) static (x) +#define NON_NULL SIZE(1) #elif defined(__clang__) -#define unused __attribute__((unused)) +#define UNUSED __attribute__((unused)) +#define SIZE(x) static (x) +#define NON_NULL SIZE(1) #else -#define unused +/* +For example MSVC, which is not fully C11 compliant (e.g. it does not support +a[static N] notation for array parameters). +*/ + +#define UNUSED +#define SIZE(x) +#define NON_NULL #endif diff --git a/src/utils/dbg_log.h b/src/utils/dbg_log.h @@ -7,8 +7,7 @@ void write_wrapper(void (*)(const char *, void *), const char *, ...); void write_wrapper(void (*write)(const char *, void *), const char *str, ...) { - static const size_t len = 1000; - char message[len]; + char message[1000]; va_list args; va_start(args, str); diff --git a/src/utils/math.h b/src/utils/math.h @@ -73,10 +73,10 @@ indextoperm(uint64_t p, size_t n, uint8_t *r) /* Find k-th unused number */ for (j = 0, c = 0; c <= k; j++) - c += 1 - ((used & (1<<j)) >> j); + c += UINT64_C(1) - ((used & (UINT64_C(1)<<j)) >> j); - r[i] = j-1; - used |= 1 << (j-1); + r[i] = (uint8_t)(j-1); + used |= UINT64_C(1) << (j-1); p %= factorial[n-i-1]; } diff --git a/src/utils/wrapthread.h b/src/utils/wrapthread.h @@ -61,8 +61,8 @@ #define wrapthread_return_t int #define wrapthread_return_val 0 - #define wrapthread_define_var_thread_t(x) unused char x - #define wrapthread_define_var_mutex_t(x) unused char x + #define wrapthread_define_var_thread_t(x) UNUSED char x + #define wrapthread_define_var_mutex_t(x) UNUSED char x #define wrapthread_define_struct_thread_t(x) char x #define wrapthread_define_struct_mutex_t(x) char x diff --git a/test/001_pieces/pieces_tests.c b/test/001_pieces/pieces_tests.c @@ -1,6 +1,6 @@ #include "../test.h" -void pieces(cube_t *, uint8_t [static 8], uint8_t [static 12]); +void pieces(cube_t *, uint8_t [SIZE(8)], uint8_t [SIZE(12)]); void run(void) { int i; diff --git a/test/010_math_permtoindex/permtoindex_tests.c b/test/010_math_permtoindex/permtoindex_tests.c @@ -1,6 +1,6 @@ #include "../test.h" -uint64_t permtoindex(size_t n, const uint8_t [n]); +uint64_t permtoindex(size_t n, const uint8_t *); void run(void) { char str[STRLENMAX]; @@ -11,7 +11,7 @@ void run(void) { n = atoll(str); for (i = 0; i < n; i++) { fgets(str, STRLENMAX, stdin); - a[i] = atoi(str); + a[i] = (uint8_t)atoi(str); } p = permtoindex(n, a); diff --git a/test/011_math_indextoperm/indextoperm_tests.c b/test/011_math_indextoperm/indextoperm_tests.c @@ -1,6 +1,6 @@ #include "../test.h" -void indextoperm(uint64_t, size_t n, uint8_t [n]); +void indextoperm(uint64_t, size_t n, uint8_t *); void run(void) { char str[STRLENMAX]; diff --git a/test/012_math_permsign/permsign_tests.c b/test/012_math_permsign/permsign_tests.c @@ -1,6 +1,6 @@ #include "../test.h" -int permsign(size_t n, const uint8_t [n]); +int permsign(size_t n, const uint8_t *); void run(void) { char str[STRLENMAX]; @@ -13,7 +13,7 @@ void run(void) { for (i = 0; i < n; i++) { fgets(str, STRLENMAX, stdin); - a[i] = atoi(str); + a[i] = (uint8_t)atoi(str); } p = permsign(n, a); diff --git a/test/013_math_digitstosumzero/digitstosumzero_tests.c b/test/013_math_digitstosumzero/digitstosumzero_tests.c @@ -1,6 +1,6 @@ #include "../test.h" -uint64_t digitstosumzero(size_t n, uint8_t [n], uint8_t); +uint64_t digitstosumzero(size_t n, uint8_t *, uint8_t); void run(void) { char str[STRLENMAX]; @@ -11,10 +11,10 @@ void run(void) { fgets(str, STRLENMAX, stdin); n = atoi(str); fgets(str, STRLENMAX, stdin); - b = atoi(str); + b = (uint8_t)atoi(str); for (i = 0; i < n; i++) { fgets(str, STRLENMAX, stdin); - a[i] = atoi(str); + a[i] = (uint8_t)atoi(str); } p = digitstosumzero(n, a, b); diff --git a/test/014_math_sumzerotodigits/sumzerotodigits.c b/test/014_math_sumzerotodigits/sumzerotodigits.c @@ -1,6 +1,6 @@ #include "../test.h" -void sumzerotodigits(uint64_t, size_t n, uint8_t, uint8_t [n]); +void sumzerotodigits(uint64_t, size_t n, uint8_t, uint8_t *); void run(void) { char str[STRLENMAX]; @@ -8,9 +8,9 @@ void run(void) { uint64_t d; fgets(str, STRLENMAX, stdin); - n = atoi(str); + n = (uint8_t)atoi(str); fgets(str, STRLENMAX, stdin); - b = atoi(str); + b = (uint8_t)atoi(str); fgets(str, STRLENMAX, stdin); d = atoll(str); diff --git a/test/033_inverse_move/inverse_move_tests.c b/test/033_inverse_move/inverse_move_tests.c @@ -3,7 +3,7 @@ extern char *movestr[]; int64_t readmoves(const char *, size_t n, size_t m, - size_t *, size_t *, uint8_t [n], uint8_t [m]); + size_t *, size_t *, uint8_t *, uint8_t *); uint8_t inverse_move(uint8_t); void run(void) { diff --git a/test/061_inverse_trans/inverse_trans_tests.c b/test/061_inverse_trans/inverse_trans_tests.c @@ -1,6 +1,6 @@ #include "../test.h" -uint8_t readtrans(char [static NISSY_SIZE_TRANSFORMATION]); +uint8_t readtrans(char [SIZE(NISSY_SIZE_TRANSFORMATION)]); uint8_t inverse_trans(uint8_t); oriented_cube_t applymoves(oriented_cube_t, char *); oriented_cube_t applytrans(oriented_cube_t, char *); diff --git a/test/062_transform_move/transform_move_tests.c b/test/062_transform_move/transform_move_tests.c @@ -5,10 +5,10 @@ cube_t applytrans(cube_t, const char *); uint8_t transform_move(uint8_t, uint8_t); int64_t readmoves(const char *, size_t n, size_t m, - size_t *, size_t *, uint8_t [n], uint8_t [m]); + size_t *, size_t *, uint8_t *, uint8_t *); oriented_cube_t move_extended(oriented_cube_t, uint8_t); oriented_cube_t applymoves(oriented_cube_t, const char *); -uint8_t readtrans(const char[static NISSY_SIZE_TRANSFORMATION]); +uint8_t readtrans(const char[SIZE(NISSY_SIZE_TRANSFORMATION)]); void run(void) { char movestr[STRLENMAX], transtr[STRLENMAX], cubestr[STRLENMAX]; diff --git a/test/075_set_eo/set_eo_tests.c b/test/075_set_eo/set_eo_tests.c @@ -2,7 +2,7 @@ uint64_t coord_eo(cube_t); void set_eo(cube_t *, uint64_t); -void pieces(cube_t *, uint8_t [static 8], uint8_t [static 12]); +void pieces(cube_t *, uint8_t [SIZE(8)], uint8_t [SIZE(12)]); void run(void) { char str[STRLENMAX]; diff --git a/test/076_copy_co/copy_co_tests.c b/test/076_copy_co/copy_co_tests.c @@ -1,7 +1,7 @@ #include "../test.h" void copy_co(cube_t *, cube_t); -void pieces(cube_t *, uint8_t [static 8], uint8_t [static 12]); +void pieces(cube_t *, uint8_t [SIZE(8)], uint8_t [SIZE(12)]); void run(void) { char str[STRLENMAX]; diff --git a/test/090_allowedmoves/allowedmoves_tests.c b/test/090_allowedmoves/allowedmoves_tests.c @@ -1,6 +1,6 @@ #include "../test.h" -bool allowedmoves(size_t n, const uint8_t [n]); +bool allowedmoves(size_t n, const uint8_t *); static char *moves[] = { "U", "U2", "U'", @@ -13,8 +13,8 @@ static char *moves[] = { void run(void) { char movestr[STRLENMAX]; - uint8_t m[100]; - int n, i, j; + uint8_t j, m[100]; + int n, i; fgets(movestr, STRLENMAX, stdin); n = atoi(movestr); diff --git a/test/114_cocsep_ttrep/cocsep_ttrep_tests.c b/test/114_cocsep_ttrep/cocsep_ttrep_tests.c @@ -6,9 +6,9 @@ uint64_t coord_cocsep(cube_t); size_t gendata_cocsep(unsigned char *, uint64_t *, cube_t *); void run(void) { - uint8_t t; + uint8_t t, tt; unsigned char buf[2000000]; - uint32_t *cocsepdata, tt; + uint32_t *cocsepdata; uint64_t i, selfsim[COCSEP_CLASSES]; uint64_t j, k, l; cube_t rep[COCSEP_CLASSES], c, d; diff --git a/test/115_gendata_eoesep/gendata_eoesep_tests.c b/test/115_gendata_eoesep/gendata_eoesep_tests.c @@ -25,7 +25,7 @@ The test does not generate the full table. For reference, these are the values: unsigned char buf[FULLSIZE]; -size_t gendata_eoesep(unsigned char [static FULLSIZE], uint8_t); +size_t gendata_eoesep(unsigned char [SIZE(FULLSIZE)], uint8_t); int64_t readtableinfo(size_t, const unsigned char *, tableinfo_t *); void run(void) { diff --git a/test/121_h48map/h48map_tests.c b/test/121_h48map/h48map_tests.c @@ -2,11 +2,11 @@ #define MAXPOS 1000 -void h48map_create(h48map_t [static 1], uint64_t, uint64_t); -void h48map_destroy(h48map_t [static 1]); -void h48map_insertmin(h48map_t [static 1], uint64_t, uint64_t); -uint64_t h48map_value(h48map_t [static 1], uint64_t); -kvpair_t h48map_nextkvpair(h48map_t [static 1], uint64_t [static 1]); +void h48map_create(h48map_t [NON_NULL], uint64_t, uint64_t); +void h48map_destroy(h48map_t [NON_NULL]); +void h48map_insertmin(h48map_t [NON_NULL], uint64_t, uint64_t); +uint64_t h48map_value(h48map_t [NON_NULL], uint64_t); +kvpair_t h48map_nextkvpair(h48map_t [NON_NULL], uint64_t [NON_NULL]); char str[STRLENMAX]; diff --git a/test/122_gendata_h48short/gendata_h48short_tests.c b/test/122_gendata_h48short/gendata_h48short_tests.c @@ -2,11 +2,11 @@ #define MAXPOS 200 -void h48map_create(h48map_t [static 1], uint64_t, uint64_t); -void h48map_destroy(h48map_t [static 1]); -kvpair_t h48map_nextkvpair(h48map_t [static 1], uint64_t [static 1]); +void h48map_create(h48map_t [NON_NULL], uint64_t, uint64_t); +void h48map_destroy(h48map_t [NON_NULL]); +kvpair_t h48map_nextkvpair(h48map_t [NON_NULL], uint64_t [NON_NULL]); size_t gendata_cocsep(unsigned char *, uint64_t *, cube_t *); -uint64_t gendata_h48short(gendata_h48short_arg_t [static 1]); +uint64_t gendata_h48short(gendata_h48short_arg_t [NON_NULL]); char str[STRLENMAX]; @@ -34,7 +34,7 @@ void run(void) { capacity = readl(); randomizer = readl(); - arg.maxdepth = readl(); + arg.maxdepth = (uint8_t)readl(); arg.crep = crep; arg.selfsim = selfsim; arg.map = &map; diff --git a/test/131_coorddata_dr/coorddata_dr.c b/test/131_coorddata_dr/coorddata_dr.c @@ -11,7 +11,7 @@ size_t coordinate_dr_gendata(unsigned char *); void run(void) { bool found; - uint64_t t; + uint8_t t; char str[STRLENMAX]; unsigned char *data; size_t size; @@ -33,8 +33,8 @@ void run(void) { goto cleanup; } - for (t = 0, found = false; t < 48; t++) { - if (!((UINT64_C(1) << t) & TGROUP)) + for (t = 0, found = false, coord2 = UINT64_MAX; t < 48; t++) { + if (!((UINT64_C(1) << (uint8_t)t) & TGROUP)) continue; coord2 = coordinate_dr_coord(transform(cube, t), data); diff --git a/test/132_coorddata_dreo/coorddata_dreo.c b/test/132_coorddata_dreo/coorddata_dreo.c @@ -11,7 +11,7 @@ size_t coordinate_dreo_gendata(unsigned char *); void run(void) { bool found; - uint64_t t; + uint8_t t; char str[STRLENMAX]; unsigned char *data; size_t size; @@ -33,8 +33,8 @@ void run(void) { goto cleanup; } - for (t = 0, found = false; t < 48; t++) { - if (!((UINT64_C(1) << t) & TGROUP)) + for (t = 0, found = false, coord2 = UINT64_MAX; t < 48; t++) { + if (!((UINT64_C(1) << (uint64_t)t) & TGROUP)) continue; coord2 = coordinate_dreo_coord(transform(cube, t), data); diff --git a/test/133_coordata_drfinnoe/coorddata_drfinnoe.c b/test/133_coordata_drfinnoe/coorddata_drfinnoe.c @@ -10,7 +10,7 @@ size_t coordinate_drfinnoe_gendata(unsigned char *); void run(void) { bool found; - uint64_t t; + uint8_t t; char str[STRLENMAX]; unsigned char *data; size_t size; @@ -32,8 +32,8 @@ void run(void) { goto cleanup; } - for (t = 0, found = false; t < 48; t++) { - if (!((UINT64_C(1) << t) & TGROUP)) + for (t = 0, found = false, coord2 = UINT64_MAX; t < 48; t++) { + if (!((UINT64_C(1) << (uint64_t)t) & TGROUP)) continue; coord2 = coordinate_drfinnoe_coord(transform(cube, t), data); diff --git a/test/140_appendsolution/appendsolution_tests.c b/test/140_appendsolution/appendsolution_tests.c @@ -16,12 +16,12 @@ See below for the output format. uint8_t readtrans(const char [NISSY_SIZE_TRANSFORMATION]); int64_t readmoves(const char *, size_t n, size_t m, - size_t *, size_t *, uint8_t [n], uint8_t [m]); -void solution_moves_reset(solution_moves_t [static 1]); -bool solution_list_init(solution_list_t [static 1], size_t n, char [n]); -int64_t appendsolution(const solution_moves_t [static 1], - size_t, const uint64_t *, const solution_settings_t [static 1], - solution_list_t [static 1]); + size_t *, size_t *, uint8_t *, uint8_t *); +void solution_moves_reset(solution_moves_t [NON_NULL]); +bool solution_list_init(solution_list_t [NON_NULL], size_t n, char *); +int64_t appendsolution(const solution_moves_t [NON_NULL], + size_t, const uint64_t *, const solution_settings_t [NON_NULL], + solution_list_t [NON_NULL]); void run(void) { int i, j, nnt, ntrans; @@ -39,7 +39,7 @@ void run(void) { .unniss = false, .maxmoves = 20, .maxsolutions = 100, - .optimal = -1, + .optimal = 0, }; fgets(str, STRLENMAX, stdin); @@ -48,8 +48,8 @@ void run(void) { printf("Test error reading moves\n"); return; } - moves.nmoves = nm; - moves.npremoves = np; + moves.nmoves = (uint8_t)nm; + moves.npremoves = (uint8_t)np; fgets(str, STRLENMAX, stdin); settings.unniss = (bool)atoi(str); @@ -64,7 +64,7 @@ void run(void) { } } fgets(str, STRLENMAX, stdin); - settings.orientation = atoi(str); + settings.orientation = (uint8_t)atoi(str); appendsolution(&moves, nnt, tmask, &settings, &list); diff --git a/test/test.h b/test/test.h @@ -7,6 +7,7 @@ #include <stdlib.h> #include <string.h> +#include "../src/utils/compilers.h" #include "../src/utils/wrapthread.h" #include "../src/nissy.h" #include "../src/arch/arch.h" @@ -27,7 +28,7 @@ bool isconsistent(oriented_cube_t); bool issolvable(oriented_cube_t); bool issolved(oriented_cube_t); oriented_cube_t readcube(char *); -int64_t writecube(oriented_cube_t, size_t n, char [n]); +int64_t writecube(oriented_cube_t, size_t n, char *); /* Test function to be implemented by all tests */ void run(void); diff --git a/tools/420_solvetest_h48_symmetric/solvetest.c b/tools/420_solvetest_h48_symmetric/solvetest.c @@ -1,4 +1,4 @@ -#define SOLVER "h48h3k2" +#define SOLVER "h48h3" #define NISSFLAG NISSY_NISSFLAG_NORMAL #define MINMOVES 0 #define MAXMOVES 20 diff --git a/tools/solvetest.h b/tools/solvetest.h @@ -13,7 +13,7 @@ bool check_one( const char *aname, const char *bstr, const char *bname, - bool exp[static MAXSOLUTIONS] + bool *exp ) { size_t i, j, nn, lb; char b[MAX_SOLUTION_LEN]; @@ -130,7 +130,7 @@ int main(int argc, char **argv) { printf("Using user-specified solver %s\n", solver); } - srand(time(NULL)); + srand((unsigned)time(NULL)); nissy_setlogger(log_stderr, NULL); size = nissy_solverinfo(solver, dataid); diff --git a/tools/tool.h b/tools/tool.h @@ -18,10 +18,9 @@ static void log_stderr(const char *, void *); static double timerun(void (*)(void)); static void writetable(const unsigned char *, int64_t, const char *); -static long long int generatetable(const char *, unsigned char **, - char [static NISSY_SIZE_DATAID]); +static long long int generatetable(const char *, unsigned char **, char *); static int getdata(const char *, unsigned char **, const char *); -static void gendata_run(const char *, uint64_t[static 21]); +static void gendata_run(const char *, uint64_t *); static void log_stderr(const char *str, void *unused) @@ -113,7 +112,7 @@ static long long int generatetable( const char *solver, unsigned char **buf, - char dataid[static NISSY_SIZE_DATAID] + char *dataid ) { long long int size, gensize; @@ -183,7 +182,7 @@ getdata_error_nofree: static void gendata_run( const char *solver, - uint64_t expected[static 21] + uint64_t *expected ) { long long int size; char filename[1024], dataid[NISSY_SIZE_DATAID];