1 //===-- runtime/buffer.cpp ------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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.
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"
28 RT_OFFLOAD_API_GROUP_END
29 } // namespace Fortran::runtime::io