Skip to content

Commit

Permalink
Apply qbs changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ABBAPOH committed May 21, 2024
1 parent d378a9f commit 18b844f
Show file tree
Hide file tree
Showing 8 changed files with 594 additions and 286 deletions.
3 changes: 1 addition & 2 deletions cutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ int dbuf_putstr(DynBuf *s, const char *str)
return dbuf_put(s, (const uint8_t *)str, strlen(str));
}

int __attribute__((format(printf, 2, 3))) dbuf_printf(DynBuf *s,
const char *fmt, ...)
int FORMAT_ATTR(2, 3) dbuf_printf(DynBuf *s, const char *fmt, ...)
{
va_list ap;
char buf[128];
Expand Down
56 changes: 49 additions & 7 deletions cutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,30 @@
#include <string.h>
#include <inttypes.h>

#if defined(_MSC_VER)
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#else
#include <sys/types.h>
#endif

#ifdef __GNUC__
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define force_inline inline __attribute__((always_inline))
#define no_inline __attribute__((noinline))
#define __maybe_unused __attribute__((unused))
#else
#define likely(x) (x)
#define unlikely(x) (x)
#define force_inline
#define no_inline
#define __maybe_unused
#endif

#ifdef _MSC_VER
#define alloca _alloca
#endif

#define xglue(x, y) x ## y
#define glue(x, y) xglue(x, y)
Expand Down Expand Up @@ -128,38 +147,54 @@ static inline int64_t min_int64(int64_t a, int64_t b)
/* WARNING: undefined if a = 0 */
static inline int clz32(unsigned int a)
{
#ifdef _MSC_VER
return (int) __lzcnt(a);
#else
return __builtin_clz(a);
#endif
}

/* WARNING: undefined if a = 0 */
static inline int clz64(uint64_t a)
{
#ifdef _MSC_VER
return (int) __lzcnt64(a);
#else
return __builtin_clzll(a);
#endif
}

/* WARNING: undefined if a = 0 */
static inline int ctz32(unsigned int a)
{
#ifdef _MSC_VER
return (int) _tzcnt_u32(a);
#else
return __builtin_ctz(a);
#endif
}

/* WARNING: undefined if a = 0 */
static inline int ctz64(uint64_t a)
{
#ifdef _MSC_VER
return (int) _tzcnt_u64(a);
#else
return __builtin_ctzll(a);
#endif
}

struct __attribute__((packed)) packed_u64 {
#pragma pack(push, 1)
struct packed_u64 {
uint64_t v;
};

struct __attribute__((packed)) packed_u32 {
struct packed_u32 {
uint32_t v;
};

struct __attribute__((packed)) packed_u16 {
struct packed_u16 {
uint16_t v;
};
#pragma pack(pop)

static inline uint64_t get_u64(const uint8_t *tab)
{
Expand Down Expand Up @@ -282,8 +317,15 @@ static inline int dbuf_put_u64(DynBuf *s, uint64_t val)
{
return dbuf_put(s, (uint8_t *)&val, 8);
}
int __attribute__((format(printf, 2, 3))) dbuf_printf(DynBuf *s,
const char *fmt, ...);

#ifdef __GNUC__
#define FORMAT_ATTR(x, y) __attribute__((format(printf, x, y)))
#else
#define FORMAT_ATTR(x, y)
#endif

int FORMAT_ATTR(2, 3) dbuf_printf(DynBuf *s, const char *fmt, ...);

void dbuf_free(DynBuf *s);
static inline BOOL dbuf_error(DynBuf *s) {
return s->error;
Expand Down
4 changes: 2 additions & 2 deletions libbf.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@

/* enable it to check the multiplication result */
//#define USE_MUL_CHECK
#ifdef CONFIG_BIGNUM
/* enable it to use FFT/NTT multiplication */
#define USE_FFT_MUL
/* enable decimal floating point support */
#define USE_BF_DEC
#endif

//#define inline __attribute__((always_inline))

Expand Down Expand Up @@ -5499,6 +5497,7 @@ static inline limb_t fast_udiv(limb_t a, const FastDivData *s)
return (t1 + t0) >> s->shift2;
}

#endif // USE_BF_DEC
/* contains 10^i */
const limb_t mp_pow_dec[LIMB_DIGITS + 1] = {
1U,
Expand All @@ -5524,6 +5523,7 @@ const limb_t mp_pow_dec[LIMB_DIGITS + 1] = {
10000000000000000000U,
#endif
};
#ifdef USE_BF_DEC

/* precomputed from fast_udiv_init(10^i) */
static const FastDivData mp_pow_div[LIMB_DIGITS + 1] = {
Expand Down
28 changes: 18 additions & 10 deletions libbf.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Tiny arbitrary precision floating point library
*
*
* Copyright (c) 2017-2021 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -27,6 +27,10 @@
#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#if defined(__SIZEOF_INT128__) && (INTPTR_MAX >= INT64_MAX)
#define LIMB_LOG2_BITS 6
#else
Expand Down Expand Up @@ -171,7 +175,7 @@ static inline bf_flags_t bf_set_exp_bits(int n)
#define BF_ST_UNDERFLOW (1 << 3)
#define BF_ST_INEXACT (1 << 4)
/* indicate that a memory allocation error occured. NaN is returned */
#define BF_ST_MEM_ERROR (1 << 5)
#define BF_ST_MEM_ERROR (1 << 5)

#define BF_RADIX_MAX 36 /* maximum radix for bf_atof() and bf_ftoa() */

Expand Down Expand Up @@ -284,7 +288,7 @@ int bf_sub(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, bf_flags_t flags)
int bf_add_si(bf_t *r, const bf_t *a, int64_t b1, limb_t prec, bf_flags_t flags);
int bf_mul(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, bf_flags_t flags);
int bf_mul_ui(bf_t *r, const bf_t *a, uint64_t b1, limb_t prec, bf_flags_t flags);
int bf_mul_si(bf_t *r, const bf_t *a, int64_t b1, limb_t prec,
int bf_mul_si(bf_t *r, const bf_t *a, int64_t b1, limb_t prec,
bf_flags_t flags);
int bf_mul_2exp(bf_t *r, slimb_t e, limb_t prec, bf_flags_t flags);
int bf_div(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, bf_flags_t flags);
Expand Down Expand Up @@ -341,12 +345,12 @@ int bf_mul_pow_radix(bf_t *r, const bf_t *T, limb_t radix,
/* fractional format: prec digits after the decimal point rounded with
(flags & BF_RND_MASK) */
#define BF_FTOA_FORMAT_FRAC (1 << 16)
/* free format:
/* free format:
For binary radices with bf_ftoa() and for bfdec_ftoa(): use the minimum
number of digits to represent 'a'. The precision and the rounding
mode are ignored.
For the non binary radices with bf_ftoa(): use as many digits as
necessary so that bf_atof() return the same number when using
precision 'prec', rounding to nearest and the subnormal
Expand All @@ -373,7 +377,7 @@ char *bf_ftoa(size_t *plen, const bf_t *a, int radix, limb_t prec,
bf_flags_t flags);

/* modulo 2^n instead of saturation. NaN and infinity return 0 */
#define BF_GET_INT_MOD (1 << 0)
#define BF_GET_INT_MOD (1 << 0)
int bf_get_int32(int *pres, const bf_t *a, int flags);
int bf_get_int64(int64_t *pres, const bf_t *a, int flags);
int bf_get_uint64(uint64_t *pres, const bf_t *a);
Expand All @@ -387,10 +391,10 @@ int bf_normalize_and_round(bf_t *r, limb_t prec1, bf_flags_t flags);
int bf_can_round(const bf_t *a, slimb_t prec, bf_rnd_t rnd_mode, slimb_t k);
slimb_t bf_mul_log2_radix(slimb_t a1, unsigned int radix, int is_inv,
int is_ceil1);
int mp_mul(bf_context_t *s, limb_t *result,
const limb_t *op1, limb_t op1_size,
int mp_mul(bf_context_t *s, limb_t *result,
const limb_t *op1, limb_t op1_size,
const limb_t *op2, limb_t op2_size);
limb_t mp_add(limb_t *res, const limb_t *op1, const limb_t *op2,
limb_t mp_add(limb_t *res, const limb_t *op1, const limb_t *op2,
limb_t n, limb_t carry);
limb_t mp_add_ui(limb_t *tab, limb_t b, size_t n);
int mp_sqrtrem(bf_context_t *s, limb_t *tabs, limb_t *taba, limb_t n);
Expand Down Expand Up @@ -532,4 +536,8 @@ static inline int bfdec_resize(bfdec_t *r, limb_t len)
}
int bfdec_normalize_and_round(bfdec_t *r, limb_t prec1, bf_flags_t flags);

#ifdef __cplusplus
} /* extern "C" { */
#endif

#endif /* LIBBF_H */
2 changes: 1 addition & 1 deletion libregexp.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ static void re_emit_op_u16(REParseState *s, int op, uint32_t val)
dbuf_put_u16(&s->byte_code, val);
}

static int __attribute__((format(printf, 2, 3))) re_parse_error(REParseState *s, const char *fmt, ...)
static int FORMAT_ATTR(2, 3) re_parse_error(REParseState *s, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
Expand Down
2 changes: 2 additions & 0 deletions libunicode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1575,11 +1575,13 @@ static int unicode_prop_ops(CharRange *cr, ...)
}
}
done:
va_end(ap);
assert(stack_len == 1);
ret = cr_copy(cr, &stack[0]);
cr_free(&stack[0]);
return ret;
fail:
va_end(ap);
for(i = 0; i < stack_len; i++)
cr_free(&stack[i]);
return -1;
Expand Down
Loading

0 comments on commit 18b844f

Please sign in to comment.