1 // Copyright 2021 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_EXECUTION_ENCODED_C_SIGNATURE_H_ 6 #define V8_EXECUTION_ENCODED_C_SIGNATURE_H_ 7 8 #include <stdint.h> 9 10 namespace v8 { 11 class CFunctionInfo; 12 13 namespace internal { 14 15 namespace compiler { 16 class CallDescriptor; 17 } // namespace compiler 18 19 // This structure represents whether the parameters for a given function 20 // should be read from general purpose or FP registers. parameter_count = 21 // kInvalidParamCount represents "invalid" signature, a placeholder for 22 // non-existing elements in the mapping. 23 struct EncodedCSignature { 24 public: 25 EncodedCSignature() = default; EncodedCSignatureEncodedCSignature26 EncodedCSignature(uint32_t bitfield, int parameter_count) 27 : bitfield_(bitfield), parameter_count_(parameter_count) {} EncodedCSignatureEncodedCSignature28 explicit EncodedCSignature(int parameter_count) 29 : parameter_count_(parameter_count) {} 30 explicit EncodedCSignature(const CFunctionInfo* signature); 31 IsFloatEncodedCSignature32 bool IsFloat(int index) const { 33 return (bitfield_ & (static_cast<uint32_t>(1) << index)) != 0; 34 } IsReturnFloatEncodedCSignature35 bool IsReturnFloat() const { return IsFloat(kReturnIndex); } SetFloatEncodedCSignature36 void SetFloat(int index) { bitfield_ |= (static_cast<uint32_t>(1) << index); } 37 IsValidEncodedCSignature38 bool IsValid() const { return parameter_count_ < kInvalidParamCount; } 39 ParameterCountEncodedCSignature40 int ParameterCount() const { return parameter_count_; } 41 int FPParameterCount() const; 42 InvalidEncodedCSignature43 static const EncodedCSignature& Invalid() { 44 static EncodedCSignature kInvalid = {0, kInvalidParamCount}; 45 return kInvalid; 46 } 47 48 static const int kReturnIndex = 31; 49 static const int kInvalidParamCount = kReturnIndex + 1; 50 51 private: 52 uint32_t bitfield_ = 0; // Bit i is set if floating point, unset if not. 53 54 int parameter_count_ = kInvalidParamCount; 55 }; 56 57 } // namespace internal 58 } // namespace v8 59 60 #endif // V8_EXECUTION_ENCODED_C_SIGNATURE_H_ 61