Skip to content

Commit 3ebe9bf

Browse files
committed
Changed to use ZEND_BYTES_SWAP32/ZEND_BYTES_SWAP64
1 parent 2649e1a commit 3ebe9bf

File tree

1 file changed

+3
-43
lines changed

1 file changed

+3
-43
lines changed

ext/bcmath/libbcmath/src/private.h

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -33,59 +33,19 @@
3333

3434
#include <stdbool.h>
3535
#include <stddef.h>
36+
#include "zend_portability.h"
3637

3738
/* This will be 0x01010101 for 32-bit and 0x0101010101010101 for 64-bit */
3839
#define SWAR_ONES (~((size_t) 0) / 0xFF)
3940
/* This repeats a byte `x` into an entire 32/64-bit word.
4041
* Example: SWAR_REPEAT(0xAB) will be 0xABABABAB for 32-bit and 0xABABABABABABABAB for 64-bit. */
4142
#define SWAR_REPEAT(x) (SWAR_ONES * (x))
4243

43-
/* Bytes swap */
44-
#ifdef _MSC_VER
45-
# include <stdlib.h>
46-
# define BC_BSWAP32(u) _byteswap_ulong(u)
47-
# define BC_BSWAP64(u) _byteswap_uint64(u)
48-
#else
49-
# ifdef __GNUC__
50-
# define BC_BSWAP32(u) __builtin_bswap32(u)
51-
# define BC_BSWAP64(u) __builtin_bswap64(u)
52-
# elif defined(__has_builtin)
53-
# if __has_builtin(__builtin_bswap32)
54-
# define BC_BSWAP32(u) __builtin_bswap32(u)
55-
# endif // __has_builtin(__builtin_bswap32)
56-
# if __has_builtin(__builtin_bswap64)
57-
# define BC_BSWAP64(u) __builtin_bswap64(u)
58-
# endif // __has_builtin(__builtin_bswap64)
59-
# endif // __GNUC__
60-
#endif // _MSC_VER
61-
#ifndef BC_BSWAP32
62-
static inline uint32_t BC_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 BC_BSWAP64
71-
static inline uint64_t BC_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-
8444
#if SIZEOF_SIZE_T >= 8
85-
# define BC_BSWAP(u) BC_BSWAP64(u)
45+
# define BC_BSWAP(u) ZEND_BYTES_SWAP64(u)
8646
typedef uint64_t BC_VECTOR;
8747
#else
88-
# define BC_BSWAP(u) BC_BSWAP32(u)
48+
# define BC_BSWAP(u) ZEND_BYTES_SWAP32(u)
8949
typedef uint32_t BC_VECTOR;
9050
#endif
9151

0 commit comments

Comments
 (0)