Commit bc2b1193 authored by Guillaume Chatelet's avatar Guillaume Chatelet
Browse files

[libc] add the CPP algorithm header for min/max

Reviewed By: jhuber6, sivachandra

Differential Revision: https://reviews.llvm.org/D157405
parent ff5cb1ec
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ add_header_library(
    integer_to_string.h
  DEPENDS
    libc.src.__support.common
    libc.src.__support.CPP.algorithm
    libc.src.__support.CPP.limits
    libc.src.__support.CPP.span
    libc.src.__support.CPP.string_view
+6 −0
Original line number Diff line number Diff line
add_header_library(
  algorithm
  HDRS
    algorithm.h
)

add_header_library(
  array
  HDRS
+31 −0
Original line number Diff line number Diff line
//===-- A self contained equivalent of <algorithm> --------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// This file is minimalist on purpose but can receive a few more function if
// they prove useful.
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_ALGORITHM_H
#define LLVM_LIBC_SRC_SUPPORT_CPP_ALGORITHM_H

#include "src/__support/macros/attributes.h" // LIBC_INLINE

namespace __llvm_libc {
namespace cpp {

template <class T> LIBC_INLINE constexpr const T &max(const T &a, const T &b) {
  return (a < b) ? b : a;
}

template <class T> LIBC_INLINE constexpr const T &min(const T &a, const T &b) {
  return (a < b) ? a : b;
}

} // namespace cpp
} // namespace __llvm_libc

#endif // LLVM_LIBC_SRC_SUPPORT_CPP_ALGORITHM_H
+2 −1
Original line number Diff line number Diff line
@@ -9,9 +9,10 @@ add_header_library(
    rpc_util.h
  DEPENDS
    libc.src.__support.common
    libc.src.__support.CPP.algorithm
    libc.src.__support.CPP.atomic
    libc.src.__support.CPP.optional
    libc.src.__support.CPP.functional
    libc.src.__support.CPP.optional
    libc.src.__support.GPU.utils
)

+3 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#define LLVM_LIBC_SRC_SUPPORT_RPC_RPC_H

#include "rpc_util.h"
#include "src/__support/CPP/algorithm.h" // max
#include "src/__support/CPP/atomic.h"
#include "src/__support/CPP/functional.h"
#include "src/__support/CPP/optional.h"
@@ -462,7 +463,7 @@ LIBC_INLINE void Port<T, S>::send_n(const void *const *src, uint64_t *size) {
  send([&](Buffer *buffer, uint32_t id) {
    reinterpret_cast<uint64_t *>(buffer->data)[0] = lane_value(size, id);
    num_sends = is_process_gpu() ? lane_value(size, id)
                                 : max(lane_value(size, id), num_sends);
                                 : cpp::max(lane_value(size, id), num_sends);
    uint64_t len =
        lane_value(size, id) > sizeof(Buffer::data) - sizeof(uint64_t)
            ? sizeof(Buffer::data) - sizeof(uint64_t)
@@ -495,7 +496,7 @@ LIBC_INLINE void Port<T, S>::recv_n(void **dst, uint64_t *size, A &&alloc) {
    lane_value(dst, id) =
        reinterpret_cast<uint8_t *>(alloc(lane_value(size, id)));
    num_recvs = is_process_gpu() ? lane_value(size, id)
                                 : max(lane_value(size, id), num_recvs);
                                 : cpp::max(lane_value(size, id), num_recvs);
    uint64_t len =
        lane_value(size, id) > sizeof(Buffer::data) - sizeof(uint64_t)
            ? sizeof(Buffer::data) - sizeof(uint64_t)
Loading