Skip to content

Commit 04be378

Browse files
committed
Unified maccess.h
1 parent 97b7844 commit 04be378

File tree

5 files changed

+309
-50
lines changed

5 files changed

+309
-50
lines changed

configure.ac

+11-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ AC_CONFIG_HEADERS([config.h])
1212
# AC_CONFIG_MACRO_DIRS requires newer autoconf/automake than is found in
1313
# Debian 7.0
1414
# AC_CONFIG_MACRO_DIRS([m4])
15-
m4_include([m4/ax_c___builtin_expect.m4])
1615
m4_include([m4/ax_check_compile_flag.m4])
1716
m4_include([m4/ax_check_link_flag.m4])
18-
m4_include([m4/ax_gcc_var_attribute.m4])
17+
m4_include([m4/ax_gcc_builtin.m4])
1918
m4_include([m4/ax_gcc_func_attribute.m4])
19+
m4_include([m4/ax_gcc_var_attribute.m4])
2020

2121
AM_INIT_AUTOMAKE([tar-ustar subdir-objects])
2222

@@ -162,7 +162,6 @@ AM_CONDITIONAL([NO_PIE],
162162
# AM_CONDITIONAL([WL_TDATA],
163163
# [test x$wl_tdata = xyes])
164164

165-
AX_C___BUILTIN_EXPECT
166165

167166
# Checks for libraries.
168167

@@ -426,6 +425,15 @@ AC_DEFINE_UNQUOTED([OS_NAME_2], ["$OS_NAME_2"],
426425
AC_DEFINE_UNQUOTED([OS_NAME_3], ["$OS_NAME_3"],
427426
[New name identifier for the operating system, "Linux".])
428427

428+
429+
# Checks for builtins
430+
431+
AX_GCC_BUILTIN(__builtin_bswap16)
432+
AX_GCC_BUILTIN(__builtin_bswap32)
433+
AX_GCC_BUILTIN(__builtin_bswap64)
434+
AX_GCC_BUILTIN(__builtin_expect)
435+
436+
429437
# Checks for header files.
430438

431439
AC_CHECK_HEADERS([AL/al.h])

m4/ax_c___builtin_expect.m4

-47
This file was deleted.

m4/ax_gcc_builtin.m4

+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# ===========================================================================
2+
# https://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_bswap16
28+
# __builtin_bswap32
29+
# __builtin_bswap64
30+
# __builtin_choose_expr
31+
# __builtin___clear_cache
32+
# __builtin_clrsb
33+
# __builtin_clrsbl
34+
# __builtin_clrsbll
35+
# __builtin_clz
36+
# __builtin_clzl
37+
# __builtin_clzll
38+
# __builtin_complex
39+
# __builtin_constant_p
40+
# __builtin_ctz
41+
# __builtin_ctzl
42+
# __builtin_ctzll
43+
# __builtin_expect
44+
# __builtin_ffs
45+
# __builtin_ffsl
46+
# __builtin_ffsll
47+
# __builtin_fpclassify
48+
# __builtin_huge_val
49+
# __builtin_huge_valf
50+
# __builtin_huge_vall
51+
# __builtin_inf
52+
# __builtin_infd128
53+
# __builtin_infd32
54+
# __builtin_infd64
55+
# __builtin_inff
56+
# __builtin_infl
57+
# __builtin_isinf_sign
58+
# __builtin_nan
59+
# __builtin_nand128
60+
# __builtin_nand32
61+
# __builtin_nand64
62+
# __builtin_nanf
63+
# __builtin_nanl
64+
# __builtin_nans
65+
# __builtin_nansf
66+
# __builtin_nansl
67+
# __builtin_object_size
68+
# __builtin_parity
69+
# __builtin_parityl
70+
# __builtin_parityll
71+
# __builtin_popcount
72+
# __builtin_popcountl
73+
# __builtin_popcountll
74+
# __builtin_powi
75+
# __builtin_powif
76+
# __builtin_powil
77+
# __builtin_prefetch
78+
# __builtin_trap
79+
# __builtin_types_compatible_p
80+
# __builtin_unreachable
81+
#
82+
# Unsupported built-ins will be tested with an empty parameter set and the
83+
# result of the check might be wrong or meaningless so use with care.
84+
#
85+
# LICENSE
86+
#
87+
# Copyright (c) 2013 Gabriele Svelto <[email protected]>
88+
#
89+
# Copying and distribution of this file, with or without modification, are
90+
# permitted in any medium without royalty provided the copyright notice
91+
# and this notice are preserved. This file is offered as-is, without any
92+
# warranty.
93+
94+
#serial 6
95+
96+
AC_DEFUN([AX_GCC_BUILTIN], [
97+
AS_VAR_PUSHDEF([ac_var], [ax_cv_have_$1])
98+
99+
AC_CACHE_CHECK([for $1], [ac_var], [
100+
AC_LINK_IFELSE([AC_LANG_PROGRAM([], [
101+
m4_case([$1],
102+
[__builtin_assume_aligned], [$1("", 0)],
103+
[__builtin_bswap16], [$1(0)],
104+
[__builtin_bswap32], [$1(0)],
105+
[__builtin_bswap64], [$1(0)],
106+
[__builtin_choose_expr], [$1(0, 0, 0)],
107+
[__builtin___clear_cache], [$1("", "")],
108+
[__builtin_clrsb], [$1(0)],
109+
[__builtin_clrsbl], [$1(0)],
110+
[__builtin_clrsbll], [$1(0)],
111+
[__builtin_clz], [$1(0)],
112+
[__builtin_clzl], [$1(0)],
113+
[__builtin_clzll], [$1(0)],
114+
[__builtin_complex], [$1(0.0, 0.0)],
115+
[__builtin_constant_p], [$1(0)],
116+
[__builtin_ctz], [$1(0)],
117+
[__builtin_ctzl], [$1(0)],
118+
[__builtin_ctzll], [$1(0)],
119+
[__builtin_expect], [$1(0, 0)],
120+
[__builtin_ffs], [$1(0)],
121+
[__builtin_ffsl], [$1(0)],
122+
[__builtin_ffsll], [$1(0)],
123+
[__builtin_fpclassify], [$1(0, 1, 2, 3, 4, 0.0)],
124+
[__builtin_huge_val], [$1()],
125+
[__builtin_huge_valf], [$1()],
126+
[__builtin_huge_vall], [$1()],
127+
[__builtin_inf], [$1()],
128+
[__builtin_infd128], [$1()],
129+
[__builtin_infd32], [$1()],
130+
[__builtin_infd64], [$1()],
131+
[__builtin_inff], [$1()],
132+
[__builtin_infl], [$1()],
133+
[__builtin_isinf_sign], [$1(0.0)],
134+
[__builtin_nan], [$1("")],
135+
[__builtin_nand128], [$1("")],
136+
[__builtin_nand32], [$1("")],
137+
[__builtin_nand64], [$1("")],
138+
[__builtin_nanf], [$1("")],
139+
[__builtin_nanl], [$1("")],
140+
[__builtin_nans], [$1("")],
141+
[__builtin_nansf], [$1("")],
142+
[__builtin_nansl], [$1("")],
143+
[__builtin_object_size], [$1("", 0)],
144+
[__builtin_parity], [$1(0)],
145+
[__builtin_parityl], [$1(0)],
146+
[__builtin_parityll], [$1(0)],
147+
[__builtin_popcount], [$1(0)],
148+
[__builtin_popcountl], [$1(0)],
149+
[__builtin_popcountll], [$1(0)],
150+
[__builtin_powi], [$1(0, 0)],
151+
[__builtin_powif], [$1(0, 0)],
152+
[__builtin_powil], [$1(0, 0)],
153+
[__builtin_prefetch], [$1("")],
154+
[__builtin_trap], [$1()],
155+
[__builtin_types_compatible_p], [$1(int, int)],
156+
[__builtin_unreachable], [$1()],
157+
[m4_warn([syntax], [Unsupported built-in $1, the test may fail])
158+
$1()]
159+
)
160+
])],
161+
[AS_VAR_SET([ac_var], [yes])],
162+
[AS_VAR_SET([ac_var], [no])])
163+
])
164+
165+
AS_IF([test yes = AS_VAR_GET([ac_var])],
166+
[AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$1), 1,
167+
[Define to 1 if the system has the `$1' built-in function])], [])
168+
169+
AS_VAR_POPDEF([ac_var])
170+
])

src/include/uae/maccess.h

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* UAE - The Un*x Amiga Emulator
3+
*
4+
* Memory access functions (for all machdeps)
5+
*
6+
* Copyright 1996 Bernd Schmidt
7+
* Copyright 2019 Frode Solheim
8+
*/
9+
10+
#ifndef UAE_MACCESS_H_
11+
#define UAE_MACCESS_H_
12+
13+
#ifdef HAVE_CONFIG_H
14+
#include "config.h"
15+
#endif
16+
17+
#ifdef FSUAE // NL
18+
#include "uae/types.h"
19+
#include "uae/inline.h"
20+
#endif
21+
22+
#ifdef _WIN32
23+
#include <stdlib.h>
24+
#define uae_bswap_16 _byteswap_uint16
25+
#define uae_bswap_32 _byteswap_uint32
26+
#define uae_bswap_64 _byteswap_uint64
27+
#elif defined(__APPLE__)
28+
#include <libkern/OSByteOrder.h>
29+
#define uae_bswap_16 OSSwapInt16
30+
#define uae_bswap_32 OSSwapInt32
31+
#define uae_bswap_64 OSSwapInt64
32+
#else
33+
#include <byteswap.h>
34+
#define uae_bswap_16 bswap_16
35+
#define uae_bswap_32 bswap_32
36+
#define uae_bswap_64 bswap_64
37+
#endif
38+
39+
// Use builtin byteswap functions where possible. In many cases, the compiler
40+
// may use optimized byteswap builtins anyway, but better to not risk using
41+
// slower function calls.
42+
43+
#ifdef HAVE___BUILTIN_BSWAP16
44+
#undef uae_bswap_16
45+
#define uae_bswap_16 __builtin_bswap16
46+
#endif
47+
#ifdef HAVE___BUILTIN_BSWAP32
48+
#undef uae_bswap_32
49+
#define uae_bswap_32 __builtin_bswap32
50+
#endif
51+
#ifdef HAVE___BUILTIN_BSWAP64
52+
#undef uae_bswap_64
53+
#define uae_bswap_64 __builtin_bswap64
54+
#endif
55+
56+
#define ALIGN_POINTER_TO32(p) ((~(uintptr_t)(p)) & 3)
57+
58+
static inline uae_u64 do_get_mem_quad(uae_u64 *a)
59+
{
60+
#ifdef WORDS_BIGENDIAN
61+
return *a;
62+
#else
63+
return uae_bswap_64(*a);
64+
#endif
65+
}
66+
67+
static inline uae_u32 do_get_mem_long(uae_u32 *a)
68+
{
69+
#ifdef WORDS_BIGENDIAN
70+
return *a;
71+
#else
72+
return uae_bswap_32(*a);
73+
#endif
74+
}
75+
76+
static inline uae_u16 do_get_mem_word(uae_u16 *a)
77+
{
78+
#ifdef WORDS_BIGENDIAN
79+
return *a;
80+
#else
81+
return uae_bswap_16(*a);
82+
#endif
83+
}
84+
85+
#define do_get_mem_byte(a) ((uae_u32)*(uae_u8 *)(a))
86+
87+
static inline void do_put_mem_quad(uae_u64 *a, uae_u64 v)
88+
{
89+
#ifdef WORDS_BIGENDIAN
90+
*a = v;
91+
#else
92+
*a = uae_bswap_64(v);
93+
#endif
94+
}
95+
96+
static inline void do_put_mem_long(uae_u32 *a, uae_u32 v)
97+
{
98+
#ifdef WORDS_BIGENDIAN
99+
*a = v;
100+
#else
101+
*a = uae_bswap_32(v);
102+
#endif
103+
}
104+
105+
static inline void do_put_mem_word(uae_u16 *a, uae_u16 v)
106+
{
107+
#ifdef WORDS_BIGENDIAN
108+
*a = v;
109+
#else
110+
*a = uae_bswap_16(v);
111+
#endif
112+
}
113+
114+
static inline void do_put_mem_byte(uae_u8 *a, uae_u8 v)
115+
{
116+
*a = v;
117+
}
118+
119+
#define call_mem_get_func(func, addr) ((*func)(addr))
120+
#define call_mem_put_func(func, addr, v) ((*func)(addr, v))
121+
122+
#endif // UAE_MACCESS_H_

src/od-fs/machdep/maccess.h

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#if 1
2+
3+
#include "uae/maccess.h"
4+
5+
#else
16
#ifdef __ARM_EABI__
27
#include "machdep/arm/maccess.h"
38
#elif __ppc__
@@ -7,3 +12,4 @@
712
#else
813
#include "machdep/generic/maccess.h"
914
#endif
15+
#endif

0 commit comments

Comments
 (0)