intrinsics: Add new struct form of modf(), frexp()

Implement these for all the writers.
SPIR-V reader not implemented (the old overloads weren't implemented either).

Deprecate the old overloads.

Fixed: tint:54
Change-Id: If66d26dbac3389ff604734f31b426abe47868b91
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/59302
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton
2021-07-23 16:43:01 +00:00
parent 465c5aa51d
commit 053559d051
236 changed files with 5861 additions and 2658 deletions

View File

@@ -27,8 +27,9 @@ TEST_F(StructTest, Creation) {
auto* impl =
create<ast::Struct>(name, ast::StructMemberList{}, ast::DecorationList{});
auto* ptr = impl;
auto* s = create<sem::Struct>(impl, StructMemberList{}, 4 /* align */,
8 /* size */, 16 /* size_no_padding */);
auto* s =
create<sem::Struct>(impl, impl->name(), StructMemberList{}, 4 /* align */,
8 /* size */, 16 /* size_no_padding */);
EXPECT_EQ(s->Declaration(), ptr);
EXPECT_EQ(s->Align(), 4u);
EXPECT_EQ(s->Size(), 8u);
@@ -39,8 +40,9 @@ TEST_F(StructTest, TypeName) {
auto name = Sym("my_struct");
auto* impl =
create<ast::Struct>(name, ast::StructMemberList{}, ast::DecorationList{});
auto* s = create<sem::Struct>(impl, StructMemberList{}, 4 /* align */,
4 /* size */, 4 /* size_no_padding */);
auto* s =
create<sem::Struct>(impl, impl->name(), StructMemberList{}, 4 /* align */,
4 /* size */, 4 /* size_no_padding */);
EXPECT_EQ(s->type_name(), "__struct_$1");
}
@@ -48,8 +50,9 @@ TEST_F(StructTest, FriendlyName) {
auto name = Sym("my_struct");
auto* impl =
create<ast::Struct>(name, ast::StructMemberList{}, ast::DecorationList{});
auto* s = create<sem::Struct>(impl, StructMemberList{}, 4 /* align */,
4 /* size */, 4 /* size_no_padding */);
auto* s =
create<sem::Struct>(impl, impl->name(), StructMemberList{}, 4 /* align */,
4 /* size */, 4 /* size_no_padding */);
EXPECT_EQ(s->FriendlyName(Symbols()), "my_struct");
}

View File

@@ -27,11 +27,13 @@ namespace tint {
namespace sem {
Struct::Struct(const ast::Struct* declaration,
Symbol name,
StructMemberList members,
uint32_t align,
uint32_t size,
uint32_t size_no_padding)
: declaration_(declaration),
name_(name),
members_(std::move(members)),
align_(align),
size_(size),
@@ -57,7 +59,7 @@ const StructMember* Struct::FindMember(Symbol name) const {
}
std::string Struct::type_name() const {
return declaration_->type_name();
return "__struct_" + name_.to_str();
}
uint32_t Struct::Align() const {
@@ -69,7 +71,7 @@ uint32_t Struct::Size() const {
}
std::string Struct::FriendlyName(const SymbolTable& symbols) const {
return symbols.NameFor(declaration_->name());
return symbols.NameFor(name_);
}
bool Struct::IsConstructible() const {
@@ -77,12 +79,14 @@ bool Struct::IsConstructible() const {
}
StructMember::StructMember(ast::StructMember* declaration,
Symbol name,
sem::Type* type,
uint32_t index,
uint32_t offset,
uint32_t align,
uint32_t size)
: declaration_(declaration),
name_(name),
type_(type),
index_(index),
offset_(offset),

View File

@@ -58,12 +58,14 @@ class Struct : public Castable<Struct, Type> {
public:
/// Constructor
/// @param declaration the AST structure declaration
/// @param name the name of the structure
/// @param members the structure members
/// @param align the byte alignment of the structure
/// @param size the byte size of the structure
/// @param size_no_padding size of the members without the end of structure
/// alignment padding
Struct(const ast::Struct* declaration,
Symbol name,
StructMemberList members,
uint32_t align,
uint32_t size,
@@ -75,6 +77,9 @@ class Struct : public Castable<Struct, Type> {
/// @returns the struct
const ast::Struct* Declaration() const { return declaration_; }
/// @returns the name of the structure
Symbol Name() const { return name_; }
/// @returns the members of the structure
const StructMemberList& Members() const { return members_; }
@@ -156,6 +161,7 @@ class Struct : public Castable<Struct, Type> {
uint64_t LargestMemberBaseAlignment(MemoryLayout mem_layout) const;
ast::Struct const* const declaration_;
Symbol const name_;
StructMemberList const members_;
uint32_t const align_;
uint32_t const size_;
@@ -170,12 +176,14 @@ class StructMember : public Castable<StructMember, Node> {
public:
/// Constructor
/// @param declaration the AST declaration node
/// @param name the name of the structure
/// @param type the type of the member
/// @param index the index of the member in the structure
/// @param offset the byte offset from the base of the structure
/// @param align the byte alignment of the member
/// @param size the byte size of the member
StructMember(ast::StructMember* declaration,
Symbol name,
sem::Type* type,
uint32_t index,
uint32_t offset,
@@ -188,6 +196,9 @@ class StructMember : public Castable<StructMember, Node> {
/// @returns the AST declaration node
ast::StructMember* Declaration() const { return declaration_; }
/// @returns the name of the structure
Symbol Name() const { return name_; }
/// @returns the type of the member
sem::Type* Type() const { return type_; }
@@ -205,6 +216,7 @@ class StructMember : public Castable<StructMember, Node> {
private:
ast::StructMember* const declaration_;
Symbol const name_;
sem::Type* const type_;
uint32_t const index_;
uint32_t const offset_;