1/*
2 * Copyright 2016-present Facebook, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <folly/Portability.h>
20
21#include <cstdint>
22
23#ifdef _MSC_VER
24#include <intrin.h>
25#endif
26
27namespace folly {
28inline void asm_volatile_memory() {
29#if defined(__clang__) || defined(__GNUC__)
30 asm volatile("" : : : "memory");
31#elif defined(_MSC_VER)
32 ::_ReadWriteBarrier();
33#endif
34}
35
36inline void asm_volatile_pause() {
37#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
38 ::_mm_pause();
39#elif defined(__i386__) || FOLLY_X64
40 asm volatile("pause");
41#elif FOLLY_AARCH64 || defined(__arm__)
42 asm volatile("yield");
43#elif FOLLY_PPC64
44 asm volatile("or 27,27,27");
45#endif
46}
47} // namespace folly
48