[libc++][Android] Allow testing libc++ with clang-r536225 (#116149)
[llvm-project.git] / flang / runtime / buffer.cpp
blob7b4869d69c2e5136b736e25f18339d306dd1b2ce
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 //===----------------------------------------------------------------------===//
9 #include "buffer.h"
10 #include <algorithm>
12 namespace Fortran::runtime::io {
13 RT_OFFLOAD_API_GROUP_BEGIN
15 // Here's a very old trick for shifting circular buffer data cheaply
16 // without a need for a temporary array.
17 void 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(buffer, buffer + bytes); // "dcbaefg"
24 std::reverse(buffer, buffer + bytes - shift); // "abcdefg"
25 RT_DIAG_POP
28 RT_OFFLOAD_API_GROUP_END
29 } // namespace Fortran::runtime::io