From fc41f7917531693680b5baf71ffe38c47333fe84 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 6 Apr 2026 15:55:33 +0200 Subject: 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. --- src/arch/avx2.h | 12 ++++++------ src/arch/common.h | 14 +++++++------- src/arch/neon.h | 10 +++++----- src/arch/portable.h | 10 +++++----- 4 files changed, 23 insertions(+), 23 deletions(-) (limited to 'src/arch') diff --git a/src/arch/avx2.h b/src/arch/avx2.h index 15ce02a..801419e 100644 --- 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 index 2b95fe3..a7c4a3b 100644 --- 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 index 725e589..501b722 100644 --- 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 index 162ed1a..f1491f0 100644 --- 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; -- cgit v1.3