1 /* $NetBSD: cpp_atomic_ops_linkable.cc,v 1.4 2016/02/27 18:50:39 joerg Exp $ */
4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Martin Husemann <martin@NetBSD.org>.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * This is a simple link-time test to verify all builtin atomic sync
34 * operations for C++ <atomic> are available.
38 #include <machine/types.h> // for __HAVE_ATOMIC64_OPS
45 m_val.exchange(std::atomic<T>(8));
53 m_val.compare_exchange_weak(tval, other,
54 std::memory_order_release, std::memory_order_relaxed);
58 volatile std::atomic<T> m_val;
61 #if defined(__clang__) && defined(__sparc64__)
62 #define NO_SHORT_ATOMICS
65 int main(int argc, char **argv)
67 #ifndef NO_SHORT_ATOMICS
70 ATest<unsigned char>();
72 ATest<unsigned short>();
75 ATest<unsigned int>();
77 ATest<unsigned long>();
78 #ifdef __HAVE_ATOMIC64_OPS
80 ATest<unsigned long long>();
82 #ifndef NO_SHORT_ATOMICS
87 #ifndef NO_SHORT_ATOMICS
88 ATest<int_least8_t>();
89 ATest<uint_least8_t>();
90 ATest<int_least16_t>();
91 ATest<uint_least16_t>();
93 ATest<int_least32_t>();
94 ATest<uint_least32_t>();
95 #ifdef __HAVE_ATOMIC64_OPS
96 ATest<int_least64_t>();
97 ATest<uint_least64_t>();
99 #ifndef NO_SHORT_ATOMICS
100 ATest<int_fast8_t>();
101 ATest<uint_fast8_t>();
102 ATest<int_fast16_t>();
103 ATest<uint_fast16_t>();
105 ATest<int_fast32_t>();
106 ATest<uint_fast32_t>();
107 #ifdef __HAVE_ATOMIC64_OPS
108 ATest<int_fast64_t>();
109 ATest<uint_fast64_t>();
113 ATest<std::size_t>();
114 ATest<std::ptrdiff_t>();
115 #ifdef __HAVE_ATOMIC64_OPS
118 #endif /* NO_SHORT_ATOMICS */