github.com/moontrade/nogc@v0.1.7/sync/Asm.h (about)

     1  /*
     2   * Copyright (c) Facebook, Inc. and its affiliates.
     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 "Portability.h"
    20  
    21  #include <cstdint>
    22  
    23  #ifdef _MSC_VER
    24  #include <intrin.h>
    25  #endif
    26  
    27  inline void asm_volatile_memory() {
    28  #if defined(__GNUC__) || defined(__clang__)
    29      asm volatile("" : : : "memory");
    30  #elif defined(_MSC_VER)
    31      ::_ReadWriteBarrier();
    32  #endif
    33  }
    34  
    35  inline void asm_volatile_pause() {
    36  #if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
    37      ::_mm_pause();
    38  #elif defined(__i386__) || FOLLY_X64 || (__mips_isa_rev > 1)
    39      asm volatile("pause");
    40  #elif FOLLY_AARCH64 || (defined(__arm__) && !(__ARM_ARCH < 7))
    41      asm volatile("yield");
    42  #elif FOLLY_PPC64
    43      asm volatile("or 27,27,27");
    44  #endif
    45  }