Skip to content

Commit

Permalink
Fix arm32 compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ankith26 committed Mar 28, 2024
1 parent 18b8927 commit 638d580
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 48 deletions.
82 changes: 37 additions & 45 deletions src_c/bitmask.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,56 +39,48 @@
static INLINE unsigned int
bitcount(BITMASK_W n)
{
const int bitmask_len = BITMASK_W_LEN;
if (bitmask_len == 32) {
#if BITMASK_W_LEN == 32
#ifdef GILLIES
/* (C) Donald W. Gillies, 1992. All rights reserved. You may reuse
this bitcount() function anywhere you please as long as you retain
this Copyright Notice. */
register unsigned long tmp;
return (tmp = (n) - (((n) >> 1) & 033333333333) -
(((n) >> 2) & 011111111111),
tmp = ((tmp + (tmp >> 3)) & 030707070707),
tmp = (tmp + (tmp >> 6)),
tmp = (tmp + (tmp >> 12) + (tmp >> 24)) & 077);
/* (C) Donald W. Gillies, 1992. All rights reserved. You may reuse
this bitcount() function anywhere you please as long as you retain
this Copyright Notice. */
register unsigned long tmp;
return (
tmp = (n) - (((n) >> 1) & 033333333333) - (((n) >> 2) & 011111111111),
tmp = ((tmp + (tmp >> 3)) & 030707070707), tmp = (tmp + (tmp >> 6)),
tmp = (tmp + (tmp >> 12) + (tmp >> 24)) & 077);
/* End of Donald W. Gillies bitcount code */
#else
/* This piece taken from Jorg Arndt's "Algorithms for Programmers" */
n = ((n >> 1) & 0x55555555) + (n & 0x55555555); // 0-2 in 2 bits
n = ((n >> 2) & 0x33333333) + (n & 0x33333333); // 0-4 in 4 bits
n = ((n >> 4) + n) & 0x0f0f0f0f; // 0-8 in 4 bits
n += n >> 8; // 0-16 in 8 bits
n += n >> 16; // 0-32 in 8 bits
return n & 0xff;
#endif
}
else if (bitmask_len == 64) {
n = ((n >> 1) & 0x5555555555555555) + (n & 0x5555555555555555);
n = ((n >> 2) & 0x3333333333333333) + (n & 0x3333333333333333);
n = ((n >> 4) + n) & 0x0f0f0f0f0f0f0f0f;
n += n >> 8;
n += n >> 16;
#ifdef _WIN32
/* Use explicit typecast to silence MSVC warning about large bitshift,
* even though this part code does not run on windows */
n += (long long)n >> 32;
#else
n += n >> 32;
#endif
return n & 0xff;
}
else {
/* Handle non-32 or 64 bit case the slow way */
unsigned int nbits = 0;
while (n) {
if (n & 1)
nbits++;
n = n >> 1;
}
return nbits;
#else /* ~GILLIES */
/* This piece taken from Jorg Arndt's "Algorithms for Programmers" */
n = ((n >> 1) & 0x55555555) + (n & 0x55555555); // 0-2 in 2 bits
n = ((n >> 2) & 0x33333333) + (n & 0x33333333); // 0-4 in 4 bits
n = ((n >> 4) + n) & 0x0f0f0f0f; // 0-8 in 4 bits
n += n >> 8; // 0-16 in 8 bits
n += n >> 16; // 0-32 in 8 bits
return n & 0xff;
#endif /* ~GILLIES */
#elif BITMASK_W_LEN == 64
n = ((n >> 1) & 0x5555555555555555) + (n & 0x5555555555555555);
n = ((n >> 2) & 0x3333333333333333) + (n & 0x3333333333333333);
n = ((n >> 4) + n) & 0x0f0f0f0f0f0f0f0f;
n += n >> 8;
n += n >> 16;
n += n >> 32;
return n & 0xff;
#else /* BITMASK_W_LEN */
/* Handle non-32 or 64 bit case the slow way */
unsigned int nbits = 0;
while (n) {
if (n & 1)
nbits++;
n = n >> 1;
}
return nbits;
#endif /* BITMASK_W_LEN */
}

__builtin__popcount

/* Positive modulo of the given dividend and divisor (dividend % divisor).
*
* Params:
Expand Down
7 changes: 6 additions & 1 deletion src_c/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -2356,9 +2356,14 @@ _pg_pylong_to_uint32(PyObject *val, Uint32 *color, int handle_negative)
* with most significant bit set could be incorrectly exposed as
* negative
*/
if (longval > 0xFFFFFFFF || (longval < 0 && !handle_negative)) {
if (longval < 0 && !handle_negative) {
goto error;
}
#if LONG_BIT > 32
if (longval > 0xFFFFFFFF) {
goto error;
}
#endif

*color = (Uint32)longval;
return 1;
Expand Down
4 changes: 3 additions & 1 deletion src_c/include/bitmask.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ extern "C" {
#endif

#include <limits.h>
#include <Python.h>

/* Define INLINE for different compilers. If your compiler does not
support inlining then there might be a performance hit in
bitmask_overlap_area().
Expand All @@ -43,7 +45,7 @@ extern "C" {
#endif

#define BITMASK_W unsigned long int
#define BITMASK_W_LEN (sizeof(BITMASK_W) * CHAR_BIT)
#define BITMASK_W_LEN LONG_BIT
#define BITMASK_W_MASK (BITMASK_W_LEN - 1)
#define BITMASK_N(n) ((BITMASK_W)1 << (n))

Expand Down
3 changes: 2 additions & 1 deletion src_c/mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ _format_view_to_audio(Py_buffer *view)
view->format);
return 0;
}
if (view->itemsize && PG_SAMPLE_SIZE(format) != view->itemsize) {
if (view->itemsize &&
PG_SAMPLE_SIZE(format) != (unsigned int)view->itemsize) {
PyErr_Format(PyExc_ValueError,
"Array item size %d does not match format '%s'",
(int)view->itemsize, view->format);
Expand Down

0 comments on commit 638d580

Please sign in to comment.