Double4 类型用于向量化的SIMD(单指令多数据)操作,这些操作在优化变换代码中常用。其源码位于\blink\render\core\ui\gfx\geometry\double4.h
Double4 类型是一个高级的数据结构,用于存储四个双精度浮点数,并允许一次性对这四个数进行并行操作。
Double4 应该仅用于局部变量,或者内联函数的参数和返回值。不应该将它用于其他情况,如类的数据成员,因为有一些约束条件(例如,内存对齐)。
当需要重新排序 Double4 变量中的数据时,建议使用类似 {v[3], v[2], v[1], v[0]} 的形式而不是使用 __builtin_shufflevector() 等其他函数。
对于逻辑操作,例如比较和逻辑与操作,注释建议使用 AllTrue 函数来检查所有分量是否满足条件,并且在做逻辑与操作时使用位与操作符 & 而不是逻辑与操作符 && 以减少分支。
最后,注释指出使用的是 GCC 扩展(也被 Clang 支持),而不是 Clang 独有的扩展,以确保代码能够在 GCC 或 Clang 编译器上编译。
Double4 类型的源码非常简单,全部如下:
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_GFX_GEOMETRY_DOUBLE4_H_
#define UI_GFX_GEOMETRY_DOUBLE4_H_
#include <type_traits>
namespace gfx {
// This header defines Double4 type for vectorized SIMD operations used in
// optimized transformation code. The type should be only used for local
// variables, or inline function parameters or return values. Don't use the
// type in other cases (e.g. for class data members) due to constraints
// (e.g. alignment).
//
// Here are some examples of usages:
//
// double matrix[4][4] = ...;
// // The scalar value will be applied to all components.
// Double4 c0 = Load(matrix[0]) + 5;
// Double4 c1 = Load(matrix[1]) * Double4{1, 2, 3, 4};
//
// Double4 v = c0 * c1;
// // s0/s1/s2/s3 are preferred to x/y/z/w for consistency.
// double a = v.s0 + Sum(c1);
// // v.s3210 is equivalent to {v.s3, v.s2, v.s1, v.s0}.
// // Should use this form instead of __builtin_shufflevector() etc.
// Double4 swapped = {v[3], v[2], v[1], v[0]};
//
// // Logical operations.
// bool b1 = AllTrue(swapped == c0);
// // & is preferred to && to reduce branches.
// bool b2 = AllTrue((c0 == c1) & (c0 == v) & (c0 >= swapped));
//
// Store(swapped, matrix_[2]);
// Store(v, matrix_[3]);
//
// We use the gcc extension (supported by clang) instead of the clang extension
// to make sure the code can compile with either gcc or clang.
//
// For more details, see
// https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html
#if !defined(__GNUC__) && !defined(__clang__)
// #error Unsupported compiler.
#endif
typedef double __attribute__((vector_size(4 * sizeof(double
Chromium中Double4类型的SIMD封装解析

最低0.47元/天 解锁文章
891

被折叠的 条评论
为什么被折叠?



