Skip to content

Commit ec062b2

Browse files
committed
Moved some constants and macros to private.h
1 parent ce78b14 commit ec062b2

File tree

3 files changed

+63
-60
lines changed

3 files changed

+63
-60
lines changed

ext/bcmath/libbcmath/src/bcmath.h

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -78,66 +78,6 @@ typedef struct bc_struct {
7878
#define LONG_MAX 0x7ffffff
7979
#endif
8080

81-
/* This will be 0x01010101 for 32-bit and 0x0101010101010101 for 64-bit */
82-
#define SWAR_ONES (~((size_t) 0) / 0xFF)
83-
/* This repeats a byte `x` into an entire 32/64-bit word.
84-
* Example: SWAR_REPEAT(0xAB) will be 0xABABABAB for 32-bit and 0xABABABABABABABAB for 64-bit. */
85-
#define SWAR_REPEAT(x) (SWAR_ONES * (x))
86-
87-
/* Bytes swap */
88-
#if defined(_MSC_VER)
89-
# include <stdlib.h>
90-
# define BSWAP32(u) _byteswap_ulong(u)
91-
# define BSWAP64(u) _byteswap_uint64(u)
92-
#else
93-
# ifdef __has_builtin
94-
# if __has_builtin(__builtin_bswap32)
95-
# define BSWAP32(u) __builtin_bswap32(u)
96-
# endif // __has_builtin(__builtin_bswap32)
97-
# if __has_builtin(__builtin_bswap64)
98-
# define BSWAP64(u) __builtin_bswap64(u)
99-
# endif // __has_builtin(__builtin_bswap64)
100-
# elif defined(__GNUC__)
101-
# define BSWAP32(u) __builtin_bswap32(u)
102-
# define BSWAP64(u) __builtin_bswap64(u)
103-
# endif // __has_builtin
104-
#endif // defined(_MSC_VER)
105-
#ifndef BSWAP32
106-
inline uint32_t BSWAP32(uint32_t u)
107-
{
108-
return (((u & 0xff000000) >> 24)
109-
| ((u & 0x00ff0000) >> 8)
110-
| ((u & 0x0000ff00) << 8)
111-
| ((u & 0x000000ff) << 24));
112-
}
113-
#endif
114-
#ifndef BSWAP64
115-
inline uint64_t BSWAP64(uint64_t u)
116-
{
117-
return (((u & 0xff00000000000000ULL) >> 56)
118-
| ((u & 0x00ff000000000000ULL) >> 40)
119-
| ((u & 0x0000ff0000000000ULL) >> 24)
120-
| ((u & 0x000000ff00000000ULL) >> 8)
121-
| ((u & 0x00000000ff000000ULL) << 8)
122-
| ((u & 0x0000000000ff0000ULL) << 24)
123-
| ((u & 0x000000000000ff00ULL) << 40)
124-
| ((u & 0x00000000000000ffULL) << 56));
125-
}
126-
#endif
127-
128-
#if SIZEOF_SIZE_T >= 8
129-
#define BC_BSWAP(u) BSWAP64(u)
130-
#define BC_UINT_T uint64_t
131-
#else
132-
#define BC_BSWAP(u) BSWAP32(u)
133-
#define BC_UINT_T uint32_t
134-
#endif
135-
136-
#ifdef WORDS_BIGENDIAN
137-
#define BC_LITTLE_ENDIAN 0
138-
#else
139-
#define BC_LITTLE_ENDIAN 1
140-
#endif
14181

14282
/* Function Prototypes */
14383

ext/bcmath/libbcmath/src/private.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,68 @@
3434
#include <stdbool.h>
3535
#include <stddef.h>
3636

37+
/* This will be 0x01010101 for 32-bit and 0x0101010101010101 for 64-bit */
38+
#define SWAR_ONES (~((size_t) 0) / 0xFF)
39+
/* This repeats a byte `x` into an entire 32/64-bit word.
40+
* Example: SWAR_REPEAT(0xAB) will be 0xABABABAB for 32-bit and 0xABABABABABABABAB for 64-bit. */
41+
#define SWAR_REPEAT(x) (SWAR_ONES * (x))
42+
43+
/* Bytes swap */
44+
#if defined(_MSC_VER)
45+
# include <stdlib.h>
46+
# define BSWAP32(u) _byteswap_ulong(u)
47+
# define BSWAP64(u) _byteswap_uint64(u)
48+
#else
49+
# ifdef __has_builtin
50+
# if __has_builtin(__builtin_bswap32)
51+
# define BSWAP32(u) __builtin_bswap32(u)
52+
# endif // __has_builtin(__builtin_bswap32)
53+
# if __has_builtin(__builtin_bswap64)
54+
# define BSWAP64(u) __builtin_bswap64(u)
55+
# endif // __has_builtin(__builtin_bswap64)
56+
# elif defined(__GNUC__)
57+
# define BSWAP32(u) __builtin_bswap32(u)
58+
# define BSWAP64(u) __builtin_bswap64(u)
59+
# endif // __has_builtin
60+
#endif // defined(_MSC_VER)
61+
#ifndef BSWAP32
62+
inline uint32_t BSWAP32(uint32_t u)
63+
{
64+
return (((u & 0xff000000) >> 24)
65+
| ((u & 0x00ff0000) >> 8)
66+
| ((u & 0x0000ff00) << 8)
67+
| ((u & 0x000000ff) << 24));
68+
}
69+
#endif
70+
#ifndef BSWAP64
71+
inline uint64_t BSWAP64(uint64_t u)
72+
{
73+
return (((u & 0xff00000000000000ULL) >> 56)
74+
| ((u & 0x00ff000000000000ULL) >> 40)
75+
| ((u & 0x0000ff0000000000ULL) >> 24)
76+
| ((u & 0x000000ff00000000ULL) >> 8)
77+
| ((u & 0x00000000ff000000ULL) << 8)
78+
| ((u & 0x0000000000ff0000ULL) << 24)
79+
| ((u & 0x000000000000ff00ULL) << 40)
80+
| ((u & 0x00000000000000ffULL) << 56));
81+
}
82+
#endif
83+
84+
#if SIZEOF_SIZE_T >= 8
85+
#define BC_BSWAP(u) BSWAP64(u)
86+
#define BC_UINT_T uint64_t
87+
#else
88+
#define BC_BSWAP(u) BSWAP32(u)
89+
#define BC_UINT_T uint32_t
90+
#endif
91+
92+
#ifdef WORDS_BIGENDIAN
93+
#define BC_LITTLE_ENDIAN 0
94+
#else
95+
#define BC_LITTLE_ENDIAN 1
96+
#endif
97+
98+
3799
/* routines */
38100
int _bc_do_compare (bc_num n1, bc_num n2, bool use_sign);
39101
bc_num _bc_do_add (bc_num n1, bc_num n2, size_t scale_min);

ext/bcmath/libbcmath/src/str2num.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "bcmath.h"
3333
#include "convert.h"
34+
#include "private.h"
3435
#include <stdbool.h>
3536
#include <stddef.h>
3637
#ifdef __SSE2__

0 commit comments

Comments
 (0)