11cb0ef41Sopenharmony_ci// Copyright 2021 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_EXECUTION_ENCODED_C_SIGNATURE_H_
61cb0ef41Sopenharmony_ci#define V8_EXECUTION_ENCODED_C_SIGNATURE_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include <stdint.h>
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_cinamespace v8 {
111cb0ef41Sopenharmony_ciclass CFunctionInfo;
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_cinamespace internal {
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_cinamespace compiler {
161cb0ef41Sopenharmony_ciclass CallDescriptor;
171cb0ef41Sopenharmony_ci}  // namespace compiler
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci// This structure represents whether the parameters for a given function
201cb0ef41Sopenharmony_ci// should be read from general purpose or FP registers. parameter_count =
211cb0ef41Sopenharmony_ci// kInvalidParamCount represents "invalid" signature, a placeholder for
221cb0ef41Sopenharmony_ci// non-existing elements in the mapping.
231cb0ef41Sopenharmony_cistruct EncodedCSignature {
241cb0ef41Sopenharmony_ci public:
251cb0ef41Sopenharmony_ci  EncodedCSignature() = default;
261cb0ef41Sopenharmony_ci  EncodedCSignature(uint32_t bitfield, int parameter_count)
271cb0ef41Sopenharmony_ci      : bitfield_(bitfield), parameter_count_(parameter_count) {}
281cb0ef41Sopenharmony_ci  explicit EncodedCSignature(int parameter_count)
291cb0ef41Sopenharmony_ci      : parameter_count_(parameter_count) {}
301cb0ef41Sopenharmony_ci  explicit EncodedCSignature(const CFunctionInfo* signature);
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci  bool IsFloat(int index) const {
331cb0ef41Sopenharmony_ci    return (bitfield_ & (static_cast<uint32_t>(1) << index)) != 0;
341cb0ef41Sopenharmony_ci  }
351cb0ef41Sopenharmony_ci  bool IsReturnFloat() const { return IsFloat(kReturnIndex); }
361cb0ef41Sopenharmony_ci  void SetFloat(int index) { bitfield_ |= (static_cast<uint32_t>(1) << index); }
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci  bool IsValid() const { return parameter_count_ < kInvalidParamCount; }
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci  int ParameterCount() const { return parameter_count_; }
411cb0ef41Sopenharmony_ci  int FPParameterCount() const;
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci  static const EncodedCSignature& Invalid() {
441cb0ef41Sopenharmony_ci    static EncodedCSignature kInvalid = {0, kInvalidParamCount};
451cb0ef41Sopenharmony_ci    return kInvalid;
461cb0ef41Sopenharmony_ci  }
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ci  static const int kReturnIndex = 31;
491cb0ef41Sopenharmony_ci  static const int kInvalidParamCount = kReturnIndex + 1;
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci private:
521cb0ef41Sopenharmony_ci  uint32_t bitfield_ = 0;  // Bit i is set if floating point, unset if not.
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ci  int parameter_count_ = kInvalidParamCount;
551cb0ef41Sopenharmony_ci};
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ci}  // namespace internal
581cb0ef41Sopenharmony_ci}  // namespace v8
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ci#endif  // V8_EXECUTION_ENCODED_C_SIGNATURE_H_
61