Skip to content

Commit 442f091

Browse files
author
Vysheng
committed
Support for compilers without __builtin_bswap32
1 parent d25f28d commit 442f091

File tree

6 files changed

+333
-0
lines changed

6 files changed

+333
-0
lines changed

‎config.h.in

+3
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@
125125
/* Define to 1 if you have the <unistd.h> header file. */
126126
#undef HAVE_UNISTD_H
127127

128+
/* Define to 1 if the system has the `__builtin_bswap32' built-in function */
129+
#undef HAVE___BUILTIN_BSWAP32
130+
128131
/* Define to the address where bug reports for this package should be sent. */
129132
#undef PACKAGE_BUGREPORT
130133

‎configure

+141
Original file line numberDiff line numberDiff line change
@@ -2533,6 +2533,102 @@ ac_config_headers="$ac_config_headers config.h"
25332533

25342534

25352535

2536+
# ===========================================================================
2537+
# http://www.gnu.org/software/autoconf-archive/ax_gcc_builtin.html
2538+
# ===========================================================================
2539+
#
2540+
# SYNOPSIS
2541+
#
2542+
# AX_GCC_BUILTIN(BUILTIN)
2543+
#
2544+
# DESCRIPTION
2545+
#
2546+
# This macro checks if the compiler supports one of GCC's built-in
2547+
# functions; many other compilers also provide those same built-ins.
2548+
#
2549+
# The BUILTIN parameter is the name of the built-in function.
2550+
#
2551+
# If BUILTIN is supported define HAVE_<BUILTIN>. Keep in mind that since
2552+
# builtins usually start with two underscores they will be copied over
2553+
# into the HAVE_<BUILTIN> definition (e.g. HAVE___BUILTIN_EXPECT for
2554+
# __builtin_expect()).
2555+
#
2556+
# The macro caches its result in the ax_cv_have_<BUILTIN> variable (e.g.
2557+
# ax_cv_have___builtin_expect).
2558+
#
2559+
# The macro currently supports the following built-in functions:
2560+
#
2561+
# __builtin_assume_aligned
2562+
# __builtin_bswap32
2563+
# __builtin_bswap64
2564+
# __builtin_choose_expr
2565+
# __builtin___clear_cache
2566+
# __builtin_clrsb
2567+
# __builtin_clrsbl
2568+
# __builtin_clrsbll
2569+
# __builtin_clz
2570+
# __builtin_clzl
2571+
# __builtin_clzll
2572+
# __builtin_complex
2573+
# __builtin_constant_p
2574+
# __builtin_ctz
2575+
# __builtin_ctzl
2576+
# __builtin_ctzll
2577+
# __builtin_expect
2578+
# __builtin_ffs
2579+
# __builtin_ffsl
2580+
# __builtin_ffsll
2581+
# __builtin_fpclassify
2582+
# __builtin_huge_val
2583+
# __builtin_huge_valf
2584+
# __builtin_huge_vall
2585+
# __builtin_inf
2586+
# __builtin_infd128
2587+
# __builtin_infd32
2588+
# __builtin_infd64
2589+
# __builtin_inff
2590+
# __builtin_infl
2591+
# __builtin_isinf_sign
2592+
# __builtin_nan
2593+
# __builtin_nand128
2594+
# __builtin_nand32
2595+
# __builtin_nand64
2596+
# __builtin_nanf
2597+
# __builtin_nanl
2598+
# __builtin_nans
2599+
# __builtin_nansf
2600+
# __builtin_nansl
2601+
# __builtin_object_size
2602+
# __builtin_parity
2603+
# __builtin_parityl
2604+
# __builtin_parityll
2605+
# __builtin_popcount
2606+
# __builtin_popcountl
2607+
# __builtin_popcountll
2608+
# __builtin_powi
2609+
# __builtin_powif
2610+
# __builtin_powil
2611+
# __builtin_prefetch
2612+
# __builtin_trap
2613+
# __builtin_types_compatible_p
2614+
# __builtin_unreachable
2615+
#
2616+
# Unsuppored built-ins will be tested with an empty parameter set and the
2617+
# result of the check might be wrong or meaningless so use with care.
2618+
#
2619+
# LICENSE
2620+
#
2621+
# Copyright (c) 2013 Gabriele Svelto <gabriele.svelto@gmail.com>
2622+
#
2623+
# Copying and distribution of this file, with or without modification, are
2624+
# permitted in any medium without royalty provided the copyright notice
2625+
# and this notice are preserved. This file is offered as-is, without any
2626+
# warranty.
2627+
2628+
#serial 2
2629+
2630+
2631+
25362632

25372633
# Checks for programs.
25382634
ac_ext=c
@@ -6031,6 +6127,51 @@ done
60316127

60326128

60336129

6130+
6131+
6132+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __builtin_bswap32" >&5
6133+
$as_echo_n "checking for __builtin_bswap32... " >&6; }
6134+
if ${ax_cv_have___builtin_bswap32+:} false; then :
6135+
$as_echo_n "(cached) " >&6
6136+
else
6137+
6138+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
6139+
/* end confdefs.h. */
6140+
6141+
int
6142+
main ()
6143+
{
6144+
6145+
__builtin_bswap32(0)
6146+
6147+
;
6148+
return 0;
6149+
}
6150+
_ACEOF
6151+
if ac_fn_c_try_link "$LINENO"; then :
6152+
ax_cv_have___builtin_bswap32=yes
6153+
else
6154+
ax_cv_have___builtin_bswap32=no
6155+
fi
6156+
rm -f core conftest.err conftest.$ac_objext \
6157+
conftest$ac_exeext conftest.$ac_ext
6158+
6159+
fi
6160+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_have___builtin_bswap32" >&5
6161+
$as_echo "$ax_cv_have___builtin_bswap32" >&6; }
6162+
6163+
if test yes = $ax_cv_have___builtin_bswap32; then :
6164+
6165+
cat >>confdefs.h <<_ACEOF
6166+
#define HAVE___BUILTIN_BSWAP32 1
6167+
_ACEOF
6168+
6169+
fi
6170+
6171+
6172+
6173+
6174+
60346175
ac_config_files="$ac_config_files Makefile"
60356176

60366177
cat >confcache <<\_ACEOF

‎configure.ac

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ AC_CONFIG_HEADERS([config.h])
66
m4_include([ax_lua.m4])
77
m4_include([m4_ax_check_openssl.m4])
88
m4_include([m4_ax_check_zlib.m4])
9+
m4_include([m4-ax_gcc_builtin.m4])
910

1011
# Checks for programs.
1112
AC_PROG_CC
@@ -113,6 +114,8 @@ AC_FUNC_MALLOC
113114
AC_FUNC_REALLOC
114115
AC_CHECK_FUNCS([alarm endpwent memset memmove mkdir select socket strdup strndup uname])
115116

117+
AX_GCC_BUILTIN(__builtin_bswap32)
118+
116119
AC_SUBST(EXTRA_LIBS)
117120
AC_CONFIG_FILES([Makefile])
118121
AC_OUTPUT

‎crc32.c

+9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@
2626

2727
#include "crc32.h"
2828

29+
#ifndef HAVE___BUILTIN_BSWAP32
30+
static inline unsigned __builtin_bswap32(unsigned x) {
31+
return ((x << 24) & 0xff000000 ) |
32+
((x << 8) & 0x00ff0000 ) |
33+
((x >> 8) & 0x0000ff00 ) |
34+
((x >> 24) & 0x000000ff );
35+
}
36+
#endif
37+
2938
unsigned int crc32_table[256] =
3039
{
3140
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,

‎m4-ax_gcc_builtin.m4

+168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# ===========================================================================
2+
# http://www.gnu.org/software/autoconf-archive/ax_gcc_builtin.html
3+
# ===========================================================================
4+
#
5+
# SYNOPSIS
6+
#
7+
# AX_GCC_BUILTIN(BUILTIN)
8+
#
9+
# DESCRIPTION
10+
#
11+
# This macro checks if the compiler supports one of GCC's built-in
12+
# functions; many other compilers also provide those same built-ins.
13+
#
14+
# The BUILTIN parameter is the name of the built-in function.
15+
#
16+
# If BUILTIN is supported define HAVE_<BUILTIN>. Keep in mind that since
17+
# builtins usually start with two underscores they will be copied over
18+
# into the HAVE_<BUILTIN> definition (e.g. HAVE___BUILTIN_EXPECT for
19+
# __builtin_expect()).
20+
#
21+
# The macro caches its result in the ax_cv_have_<BUILTIN> variable (e.g.
22+
# ax_cv_have___builtin_expect).
23+
#
24+
# The macro currently supports the following built-in functions:
25+
#
26+
# __builtin_assume_aligned
27+
# __builtin_bswap32
28+
# __builtin_bswap64
29+
# __builtin_choose_expr
30+
# __builtin___clear_cache
31+
# __builtin_clrsb
32+
# __builtin_clrsbl
33+
# __builtin_clrsbll
34+
# __builtin_clz
35+
# __builtin_clzl
36+
# __builtin_clzll
37+
# __builtin_complex
38+
# __builtin_constant_p
39+
# __builtin_ctz
40+
# __builtin_ctzl
41+
# __builtin_ctzll
42+
# __builtin_expect
43+
# __builtin_ffs
44+
# __builtin_ffsl
45+
# __builtin_ffsll
46+
# __builtin_fpclassify
47+
# __builtin_huge_val
48+
# __builtin_huge_valf
49+
# __builtin_huge_vall
50+
# __builtin_inf
51+
# __builtin_infd128
52+
# __builtin_infd32
53+
# __builtin_infd64
54+
# __builtin_inff
55+
# __builtin_infl
56+
# __builtin_isinf_sign
57+
# __builtin_nan
58+
# __builtin_nand128
59+
# __builtin_nand32
60+
# __builtin_nand64
61+
# __builtin_nanf
62+
# __builtin_nanl
63+
# __builtin_nans
64+
# __builtin_nansf
65+
# __builtin_nansl
66+
# __builtin_object_size
67+
# __builtin_parity
68+
# __builtin_parityl
69+
# __builtin_parityll
70+
# __builtin_popcount
71+
# __builtin_popcountl
72+
# __builtin_popcountll
73+
# __builtin_powi
74+
# __builtin_powif
75+
# __builtin_powil
76+
# __builtin_prefetch
77+
# __builtin_trap
78+
# __builtin_types_compatible_p
79+
# __builtin_unreachable
80+
#
81+
# Unsuppored built-ins will be tested with an empty parameter set and the
82+
# result of the check might be wrong or meaningless so use with care.
83+
#
84+
# LICENSE
85+
#
86+
# Copyright (c) 2013 Gabriele Svelto <gabriele.svelto@gmail.com>
87+
#
88+
# Copying and distribution of this file, with or without modification, are
89+
# permitted in any medium without royalty provided the copyright notice
90+
# and this notice are preserved. This file is offered as-is, without any
91+
# warranty.
92+
93+
#serial 2
94+
95+
AC_DEFUN([AX_GCC_BUILTIN], [
96+
AS_VAR_PUSHDEF([ac_var], [ax_cv_have_$1])
97+
98+
AC_CACHE_CHECK([for $1], [ac_var], [
99+
AC_LINK_IFELSE([AC_LANG_PROGRAM([], [
100+
m4_case([$1],
101+
[__builtin_assume_aligned], [$1("", 0)],
102+
[__builtin_bswap32], [$1(0)],
103+
[__builtin_bswap64], [$1(0)],
104+
[__builtin_choose_expr], [$1(0, 0, 0)],
105+
[__builtin___clear_cache], [$1("", "")],
106+
[__builtin_clrsb], [$1(0)],
107+
[__builtin_clrsbl], [$1(0)],
108+
[__builtin_clrsbll], [$1(0)],
109+
[__builtin_clz], [$1(0)],
110+
[__builtin_clzl], [$1(0)],
111+
[__builtin_clzll], [$1(0)],
112+
[__builtin_complex], [$1(0.0, 0.0)],
113+
[__builtin_constant_p], [$1(0)],
114+
[__builtin_ctz], [$1(0)],
115+
[__builtin_ctzl], [$1(0)],
116+
[__builtin_ctzll], [$1(0)],
117+
[__builtin_expect], [$1(0, 0)],
118+
[__builtin_ffs], [$1(0)],
119+
[__builtin_ffsl], [$1(0)],
120+
[__builtin_ffsll], [$1(0)],
121+
[__builtin_fpclassify], [$1(0, 1, 2, 3, 4, 0.0)],
122+
[__builtin_huge_val], [$1()],
123+
[__builtin_huge_valf], [$1()],
124+
[__builtin_huge_vall], [$1()],
125+
[__builtin_inf], [$1()],
126+
[__builtin_infd128], [$1()],
127+
[__builtin_infd32], [$1()],
128+
[__builtin_infd64], [$1()],
129+
[__builtin_inff], [$1()],
130+
[__builtin_infl], [$1()],
131+
[__builtin_isinf_sign], [$1(0.0)],
132+
[__builtin_nan], [$1("")],
133+
[__builtin_nand128], [$1("")],
134+
[__builtin_nand32], [$1("")],
135+
[__builtin_nand64], [$1("")],
136+
[__builtin_nanf], [$1("")],
137+
[__builtin_nanl], [$1("")],
138+
[__builtin_nans], [$1("")],
139+
[__builtin_nansf], [$1("")],
140+
[__builtin_nansl], [$1("")],
141+
[__builtin_object_size], [$1("", 0)],
142+
[__builtin_parity], [$1(0)],
143+
[__builtin_parityl], [$1(0)],
144+
[__builtin_parityll], [$1(0)],
145+
[__builtin_popcount], [$1(0)],
146+
[__builtin_popcountl], [$1(0)],
147+
[__builtin_popcountll], [$1(0)],
148+
[__builtin_powi], [$1(0, 0)],
149+
[__builtin_powif], [$1(0, 0)],
150+
[__builtin_powil], [$1(0, 0)],
151+
[__builtin_prefetch], [$1("")],
152+
[__builtin_trap], [$1()],
153+
[__builtin_types_compatible_p], [$1(int, int)],
154+
[__builtin_unreachable], [$1()],
155+
[m4_warn([syntax], [Unsupported built-in $1, the test may fail])
156+
$1()]
157+
)
158+
])],
159+
[AS_VAR_SET([ac_var], [yes])],
160+
[AS_VAR_SET([ac_var], [no])])
161+
])
162+
163+
AS_IF([test yes = AS_VAR_GET([ac_var])],
164+
[AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$1), 1,
165+
[Define to 1 if the system has the `$1' built-in function])], [])
166+
167+
AS_VAR_POPDEF([ac_var])
168+
])

‎mtproto-client.c

+9
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@
8080
#define MAX_NET_RES (1L << 16)
8181
//extern int log_level;
8282

83+
#ifndef HAVE___BUILTIN_BSWAP32
84+
static inline unsigned __builtin_bswap32(unsigned x) {
85+
return ((x << 24) & 0xff000000 ) |
86+
((x << 8) & 0x00ff0000 ) |
87+
((x >> 8) & 0x0000ff00 ) |
88+
((x >> 24) & 0x000000ff );
89+
}
90+
#endif
91+
8392
//int verbosity;
8493
static int auth_success;
8594
//static enum tgl_dc_state c_state;

0 commit comments

Comments
 (0)