more fixes for 32 bits architecture
This commit is contained in:
12
c/debug.c
12
c/debug.c
@@ -19,12 +19,13 @@
|
|||||||
#define DEBUG_DEBUG
|
#define DEBUG_DEBUG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "bits.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#define NANOSEC 1000000000 /* nano sec in sec */
|
#define NANOSEC 1000000000 /* nano sec in sec */
|
||||||
#define MILLISEC 1000000 /* milli sec in sec */
|
#define MILLISEC 1000000 /* milli sec in sec */
|
||||||
|
|
||||||
static s64 timer_start; /* in nanosecond */
|
static long long timer_start; /* in nanosecond */
|
||||||
static u32 debug_level=0;
|
static u32 debug_level=0;
|
||||||
|
|
||||||
void debug_level_set(u32 level)
|
void debug_level_set(u32 level)
|
||||||
@@ -48,7 +49,7 @@ void debug_init(u32 level)
|
|||||||
log(0, "timer started.\n");
|
log(0, "timer started.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static s64 timer_elapsed()
|
inline static long long timer_elapsed()
|
||||||
{
|
{
|
||||||
struct timespec timer;
|
struct timespec timer;
|
||||||
|
|
||||||
@@ -56,7 +57,6 @@ inline static s64 timer_elapsed()
|
|||||||
return (timer.tv_sec * NANOSEC + timer.tv_nsec) - timer_start;
|
return (timer.tv_sec * NANOSEC + timer.tv_nsec) - timer_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* void debug - log function
|
/* void debug - log function
|
||||||
* @timestamp : boolean
|
* @timestamp : boolean
|
||||||
* @indent : indent level (2 spaces each)
|
* @indent : indent level (2 spaces each)
|
||||||
@@ -75,9 +75,9 @@ void debug(u32 level, bool timestamp, u32 indent, const char *src,
|
|||||||
printf("%*s", 2*(indent-1), "");
|
printf("%*s", 2*(indent-1), "");
|
||||||
|
|
||||||
if (timestamp) {
|
if (timestamp) {
|
||||||
s64 diff = timer_elapsed();
|
long long diff = timer_elapsed();
|
||||||
printf("%ld.%03ld ", diff/NANOSEC, (diff/1000000)%1000);
|
printf("%lld.%03lld ", diff/NANOSEC, (diff/1000000)%1000);
|
||||||
printf("%010ld ", diff);
|
printf("%010lld ", diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (src) {
|
if (src) {
|
||||||
|
@@ -25,10 +25,10 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* no plan to support 32bits for now...
|
/* no plan to support 32bits for now...
|
||||||
|
* #if __WORDSIZE != 64
|
||||||
|
* #error "Only 64 bits word size supported."
|
||||||
|
* #endif
|
||||||
*/
|
*/
|
||||||
#if __WORDSIZE != 64
|
|
||||||
#error "Only 64 bits word size supported."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* fixed-size types
|
/* fixed-size types
|
||||||
*/
|
*/
|
||||||
@@ -73,6 +73,27 @@ static __always_inline int popcount64(u64 n)
|
|||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static __always_inline int popcount32(u32 n)
|
||||||
|
{
|
||||||
|
# if __has_builtin(__builtin_popcount)
|
||||||
|
# ifdef DEBUG_BITS
|
||||||
|
log_f(1, "builtin.\n");
|
||||||
|
# endif
|
||||||
|
return __builtin_popcount(n);
|
||||||
|
|
||||||
|
# else
|
||||||
|
# ifdef DEBUG_BITS
|
||||||
|
log_f(1, "emulated.\n");
|
||||||
|
# endif
|
||||||
|
int count = 0;
|
||||||
|
while (n) {
|
||||||
|
count++;
|
||||||
|
n &= (n - 1);
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
/* char is a special case, as it can be signed or unsigned
|
/* char is a special case, as it can be signed or unsigned
|
||||||
*/
|
*/
|
||||||
typedef signed char schar;
|
typedef signed char schar;
|
||||||
@@ -242,27 +263,6 @@ static __always_inline uint ffs32(u32 n)
|
|||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static __always_inline int popcount32(u32 n)
|
|
||||||
{
|
|
||||||
# if __has_builtin(__builtin_popcount)
|
|
||||||
# ifdef DEBUG_BITS
|
|
||||||
log_f(1, "builtin.\n");
|
|
||||||
# endif
|
|
||||||
return __builtin_popcount(n);
|
|
||||||
|
|
||||||
# else
|
|
||||||
# ifdef DEBUG_BITS
|
|
||||||
log_f(1, "emulated.\n");
|
|
||||||
# endif
|
|
||||||
int count = 0;
|
|
||||||
while (n) {
|
|
||||||
count++;
|
|
||||||
n &= (n - 1);
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
# endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/* rolXX are taken from kernel's <linux/bitops.h> are are:
|
/* rolXX are taken from kernel's <linux/bitops.h> are are:
|
||||||
* SPDX-License-Identifier: GPL-2.0
|
* SPDX-License-Identifier: GPL-2.0
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user