1//===-- runtime/buffer.cpp ------------------------------------------------===//
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-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "buffer.h"
10#include <algorithm>
11
12namespace Fortran::runtime::io {
13RT_OFFLOAD_API_GROUP_BEGIN
14
15// Here's a very old trick for shifting circular buffer data cheaply
16// 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_PUSH
21 RT_DIAG_DISABLE_CALL_HOST_FROM_DEVICE_WARN
22 std::reverse(buffer, buffer + shift); // "gfeabcd"
23 std::reverse(first: buffer, last: buffer + bytes); // "dcbaefg"
24 std::reverse(first: buffer, last: buffer + bytes - shift); // "abcdefg"
25 RT_DIAG_POP
26}
27
28RT_OFFLOAD_API_GROUP_END
29} // namespace Fortran::runtime::io
30

source code of flang/runtime/buffer.cpp