• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "src/execution/encoded-c-signature.h"
6 
7 #include "include/v8-fast-api-calls.h"
8 #include "src/base/bits.h"
9 #include "src/base/logging.h"
10 
11 namespace v8 {
12 namespace internal {
13 
FPParameterCount() const14 int EncodedCSignature::FPParameterCount() const {
15   CHECK(IsValid());
16   return base::bits::CountPopulation(bitfield_ & ~(1 << kReturnIndex));
17 }
18 
EncodedCSignature(const CFunctionInfo * signature)19 EncodedCSignature::EncodedCSignature(const CFunctionInfo* signature) {
20   parameter_count_ = static_cast<int>(signature->ArgumentCount());
21   for (int i = 0; i < parameter_count_; ++i) {
22     if (signature->ArgumentInfo(i).GetSequenceType() ==
23             CTypeInfo::SequenceType::kScalar &&
24         CTypeInfo::IsFloatingPointType(signature->ArgumentInfo(i).GetType())) {
25       SetFloat(i);
26     }
27   }
28   // The struct holding the options of the CFunction (e.g. callback) is not
29   // included in the number of regular parameters, so we add it manually here.
30   if (signature->HasOptions()) {
31     parameter_count_++;
32   }
33   if (signature->ReturnInfo().GetSequenceType() ==
34           CTypeInfo::SequenceType::kScalar &&
35       CTypeInfo::IsFloatingPointType(signature->ReturnInfo().GetType())) {
36     SetFloat(EncodedCSignature::kReturnIndex);
37   }
38 }
39 
40 }  // namespace internal
41 }  // namespace v8
42