brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.0 KiB · 4cf85e1 Raw
30 lines · cpp
1//===-- lib/runtime/buffer.cpp ----------------------------------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "flang-rt/runtime/buffer.h"10#include <algorithm>11 12namespace Fortran::runtime::io {13RT_OFFLOAD_API_GROUP_BEGIN14 15// Here's a very old trick for shifting circular buffer data cheaply16// without a need for a temporary array.17void LeftShiftBufferCircularly(18    char *buffer, std::size_t bytes, std::size_t shift) {19  // Assume that we start with "efgabcd" and the left shift is 3.20  RT_DIAG_PUSH21  RT_DIAG_DISABLE_CALL_HOST_FROM_DEVICE_WARN22  std::reverse(buffer, buffer + shift); // "gfeabcd"23  std::reverse(buffer, buffer + bytes); // "dcbaefg"24  std::reverse(buffer, buffer + bytes - shift); // "abcdefg"25  RT_DIAG_POP26}27 28RT_OFFLOAD_API_GROUP_END29} // namespace Fortran::runtime::io30