1*a508df5bSriastradh /* $NetBSD: compiler.h,v 1.6 2021/12/19 11:26:57 riastradh Exp $ */ 2704dac09Sriastradh 3704dac09Sriastradh /*- 4704dac09Sriastradh * Copyright (c) 2018 The NetBSD Foundation, Inc. 5704dac09Sriastradh * All rights reserved. 6704dac09Sriastradh * 7704dac09Sriastradh * This code is derived from software contributed to The NetBSD Foundation 8704dac09Sriastradh * by Taylor R. Campbell. 9704dac09Sriastradh * 10704dac09Sriastradh * Redistribution and use in source and binary forms, with or without 11704dac09Sriastradh * modification, are permitted provided that the following conditions 12704dac09Sriastradh * are met: 13704dac09Sriastradh * 1. Redistributions of source code must retain the above copyright 14704dac09Sriastradh * notice, this list of conditions and the following disclaimer. 15704dac09Sriastradh * 2. Redistributions in binary form must reproduce the above copyright 16704dac09Sriastradh * notice, this list of conditions and the following disclaimer in the 17704dac09Sriastradh * documentation and/or other materials provided with the distribution. 18704dac09Sriastradh * 19704dac09Sriastradh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20704dac09Sriastradh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21704dac09Sriastradh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22704dac09Sriastradh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23704dac09Sriastradh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24704dac09Sriastradh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25704dac09Sriastradh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26704dac09Sriastradh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27704dac09Sriastradh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28704dac09Sriastradh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29704dac09Sriastradh * POSSIBILITY OF SUCH DAMAGE. 30704dac09Sriastradh */ 31704dac09Sriastradh 32704dac09Sriastradh #ifndef _LINUX_COMPILER_H_ 33704dac09Sriastradh #define _LINUX_COMPILER_H_ 34704dac09Sriastradh 3571ee315fSriastradh #include <sys/atomic.h> 364301684eSriastradh #include <sys/cdefs.h> 3771ee315fSriastradh 389cda6864Sriastradh #include <linux/stddef.h> 399cda6864Sriastradh 40b641547dSriastradh #include <asm/barrier.h> 41b641547dSriastradh 424301684eSriastradh #define __printf __printflike 434301684eSriastradh #define __user 444301684eSriastradh #if __GNUC_PREREQ__(4,0) /* not sure when but this will work */ 454301684eSriastradh #define __must_check __attribute__((warn_unused_result)) 464301684eSriastradh #else 474301684eSriastradh #define __must_check /* nothing */ 484301684eSriastradh #endif 494301684eSriastradh #define __always_unused __unused 504301684eSriastradh #define __maybe_unused __unused 514301684eSriastradh #define noinline __noinline 524301684eSriastradh #define __deprecated /* nothing */ 534301684eSriastradh 544301684eSriastradh #define barrier() __insn_barrier() 554301684eSriastradh #define likely(X) __predict_true(X) 564301684eSriastradh #define unlikely(X) __predict_false(X) 57*a508df5bSriastradh #define __same_type(X,Y) \ 58*a508df5bSriastradh __builtin_types_compatible_p(__typeof__(X), __typeof__(Y)) 59*a508df5bSriastradh #define __must_be_array(X) \ 60*a508df5bSriastradh BUILD_BUG_ON_ZERO(__same_type((X), &(X)[0])) 614301684eSriastradh 6271ee315fSriastradh #define READ_ONCE(X) ({ \ 6371ee315fSriastradh typeof(X) __read_once_tmp = (X); \ 6471ee315fSriastradh membar_datadep_consumer(); \ 6571ee315fSriastradh __read_once_tmp; \ 6671ee315fSriastradh }) 6771ee315fSriastradh 6871ee315fSriastradh #define WRITE_ONCE(X, V) ({ \ 6971ee315fSriastradh typeof(X) __write_once_tmp = (V); \ 7071ee315fSriastradh (X) = __write_once_tmp; \ 7171ee315fSriastradh __write_once_tmp; \ 7271ee315fSriastradh }) 7371ee315fSriastradh 74b641547dSriastradh #define smp_store_mb(X, V) do { \ 75b641547dSriastradh WRITE_ONCE(X, V); \ 76b641547dSriastradh smp_mb(); \ 77b641547dSriastradh } while (0) 78b641547dSriastradh 79b641547dSriastradh #define smp_store_release(X, V) do { \ 80b641547dSriastradh typeof(X) __smp_store_release_tmp = (V); \ 81b641547dSriastradh membar_exit(); \ 82b641547dSriastradh (X) = __write_once_tmp; \ 83b641547dSriastradh } while (0) 84b641547dSriastradh 85704dac09Sriastradh #endif /* _LINUX_COMPILER_H_ */ 86