• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Tint Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "src/sem/vector_type.h"
16 
17 #include "src/program_builder.h"
18 
19 TINT_INSTANTIATE_TYPEINFO(tint::sem::Vector);
20 
21 namespace tint {
22 namespace sem {
23 
Vector(Type const * subtype,uint32_t width)24 Vector::Vector(Type const* subtype, uint32_t width)
25     : subtype_(subtype), width_(width) {
26   TINT_ASSERT(Semantic, width_ > 1);
27   TINT_ASSERT(Semantic, width_ < 5);
28 }
29 
30 Vector::Vector(Vector&&) = default;
31 
32 Vector::~Vector() = default;
33 
type_name() const34 std::string Vector::type_name() const {
35   return "__vec_" + std::to_string(width_) + subtype_->type_name();
36 }
37 
FriendlyName(const SymbolTable & symbols) const38 std::string Vector::FriendlyName(const SymbolTable& symbols) const {
39   std::ostringstream out;
40   out << "vec" << width_ << "<" << subtype_->FriendlyName(symbols) << ">";
41   return out.str();
42 }
43 
IsConstructible() const44 bool Vector::IsConstructible() const {
45   return true;
46 }
47 
Size() const48 uint32_t Vector::Size() const {
49   return SizeOf(width_);
50 }
51 
Align() const52 uint32_t Vector::Align() const {
53   return AlignOf(width_);
54 }
55 
SizeOf(uint32_t width)56 uint32_t Vector::SizeOf(uint32_t width) {
57   switch (width) {
58     case 2:
59       return 8;
60     case 3:
61       return 12;
62     case 4:
63       return 16;
64   }
65   return 0;  // Unreachable
66 }
67 
AlignOf(uint32_t width)68 uint32_t Vector::AlignOf(uint32_t width) {
69   switch (width) {
70     case 2:
71       return 8;
72     case 3:
73       return 16;
74     case 4:
75       return 16;
76   }
77   return 0;  // Unreachable
78 }
79 
80 }  // namespace sem
81 }  // namespace tint
82