Commit 72c2e98e authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

register_pass_v and usage in Function

Summary: Whether a value is passed in registers also depends on its size, not just whether it is trivially copyable. (It also depends on its position in the arg-list but that is another step in complexity.)

Reviewed By: luciang

Differential Revision: D33079529

fbshipit-source-id: ae7383d61491001e54892cf077e45556801bdcf4
parent fe4dbb77
......@@ -229,6 +229,7 @@
#include <folly/Portability.h>
#include <folly/Traits.h>
#include <folly/functional/Invoke.h>
#include <folly/lang/Align.h>
#include <folly/lang/Exception.h>
namespace folly {
......@@ -303,7 +304,7 @@ template <typename T>
using CallArg = T&&;
#else
template <typename T>
using CallArg = conditional_t<is_trivially_copyable<T>::value, T, T&&>;
using CallArg = conditional_t<is_register_pass_v<T>, T, T&&>;
#endif
template <typename F, typename R, typename... A>
......
......@@ -20,9 +20,39 @@
#include <cstdint>
#include <folly/Portability.h>
#include <folly/Traits.h>
namespace folly {
// register_pass_max_size
//
// The platform-specific maximum size of a value which may be passed by-value
// in registers.
//
// According to each platform ABI, trivially-copyable types up to this maximum
// size may, if the stars align, be passed by-value in registers rather than
// implicitly by-reference to stack copies.
//
// Approximate. Accuracy is not promised.
constexpr std::size_t register_pass_max_size = kMscVer ? 8u : 16u;
// register_pass_v
//
// Whether a value may be passed in a register.
//
// Trivially-copyable values up to register_pass_max_size in width may be
// passed by-value in registers rather than implicitly by-reference to stack
// copies.
//
// Approximate. Accuracy is not promised.
template <typename T>
constexpr bool is_register_pass_v =
(sizeof(T) <= register_pass_max_size) && is_trivially_copyable_v<T>;
template <typename T>
constexpr bool is_register_pass_v<T&> = true;
template <typename T>
constexpr bool is_register_pass_v<T&&> = true;
// has_extended_alignment
//
// True if it may be presumed that the platform has static extended alignment;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment