热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

c++:英特尔SIMD内部类成员的初始化。-C++:initializationofintelSIMDintrinsicsclassmembers

Idontunderstandwhythecommentedanduncommentedlinedontyieldthesameresult(LinuxGCC,wi

I don't understand why the commented and uncommented line don't yield the same result (Linux GCC, with C++11 flag enabled):

我不理解为什么注释和未注释的行不会产生相同的结果(Linux GCC,启用了c++ 11标志):

#include "immintrin.h"


typedef __m256 floatv;

struct floatv2{
public:

    //floatv2(const float f):x(_mm256_setzero_ps() + f ), y(_mm256_setzero_ps() + f ) {}; // succeeds
    floatv2(const float f):x{_mm256_setzero_ps() + f }, y{_mm256_setzero_ps() + f } {}; // fails

//private:
    floatv x, y;
};

When trying to compile the uncommented line I get the following error:

当试图编译未注释的行时,我得到以下错误:

error: cannot convert ‘__m256 {aka __vector(8) float}’ to ‘float’ in initialization

which I don't understand because x and y are floatv, not float, so no conversion should be required...

我不明白,因为x和y是floatv,而不是float,所以不需要转换。

Also, in some more complex code, the first version produces memory access violation. Is there something nasty going on behind the scene?

另外,在一些更复杂的代码中,第一个版本会产生内存访问冲突。幕后发生了什么令人不快的事情吗?

PS: above the definition of __m256, in avxintrin.h, there is the following comment:

在avxintrin中,在__m256的定义之上。h,有以下评论:

/* The Intel API is flexible enough that we must allow aliasing with other
   vector types, and their scalar components.  */

I don't understand what this means, but feel like it could be related :)

我不明白这是什么意思,但感觉可能是相关的:

Many thanks

非常感谢

2 个解决方案

#1


2  

This is related to DR 1467 which did not allow using the list-initialization syntax for copying aggregates. This was recently fixed for classes in GCC and I extended the fix to vectors in r209449. Gcc-4.10 compiles your code.

这与1467博士有关,它不允许使用list初始化语法来复制聚集。这是最近在GCC中固定的类,我将修复扩展到r209449中的向量。gcc - 4.10编译你的代码。

#2


0  

Probably _mm256_setzero_ps() + f returns a float and not a floatv, because f is a float. So you can't initialize floatv values (x and y) with a float using { }, beacuse {}-initialization doesn't allow narrowing (implicit conversion).

可能_mm256_setzero_ps() + f返回一个浮点数,而不是浮点数,因为f是一个浮点数。因此,您不能使用浮点数来初始化floatv值(x和y),因为{}-初始化不允许缩小(隐式转换)。

Maybe

也许

x{static_cast<__m256>(_mm256_setzero_ps() + f) }

will work.

将工作。


推荐阅读
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • Explore how Matterverse is redefining the metaverse experience, creating immersive and meaningful virtual environments that foster genuine connections and economic opportunities. ... [详细]
  • 题目描述:给定n个半开区间[a, b),要求使用两个互不重叠的记录器,求最多可以记录多少个区间。解决方案采用贪心算法,通过排序和遍历实现最优解。 ... [详细]
  • 前言--页数多了以后需要指定到某一页(只做了功能,样式没有细调)html ... [详细]
  • UNP 第9章:主机名与地址转换
    本章探讨了用于在主机名和数值地址之间进行转换的函数,如gethostbyname和gethostbyaddr。此外,还介绍了getservbyname和getservbyport函数,用于在服务器名和端口号之间进行转换。 ... [详细]
  • 本文探讨了 Objective-C 中的一些重要语法特性,包括 goto 语句、块(block)的使用、访问修饰符以及属性管理等。通过实例代码和详细解释,帮助开发者更好地理解和应用这些特性。 ... [详细]
  • 题目Link题目学习link1题目学习link2题目学习link3%%%受益匪浅!-----&# ... [详细]
  • golang常用库:配置文件解析库/管理工具viper使用
    golang常用库:配置文件解析库管理工具-viper使用-一、viper简介viper配置管理解析库,是由大神SteveFrancia开发,他在google领导着golang的 ... [详细]
  • 深入解析JVM垃圾收集器
    本文基于《深入理解Java虚拟机:JVM高级特性与最佳实践》第二版,详细探讨了JVM中不同类型的垃圾收集器及其工作原理。通过介绍各种垃圾收集器的特性和应用场景,帮助读者更好地理解和优化JVM内存管理。 ... [详细]
  • 本文详细介绍了Java中org.neo4j.helpers.collection.Iterators.single()方法的功能、使用场景及代码示例,帮助开发者更好地理解和应用该方法。 ... [详细]
  • 优化ListView性能
    本文深入探讨了如何通过多种技术手段优化ListView的性能,包括视图复用、ViewHolder模式、分批加载数据、图片优化及内存管理等。这些方法能够显著提升应用的响应速度和用户体验。 ... [详细]
  • 本文详细介绍了如何构建一个高效的UI管理系统,集中处理UI页面的打开、关闭、层级管理和页面跳转等问题。通过UIManager统一管理外部切换逻辑,实现功能逻辑分散化和代码复用,支持多人协作开发。 ... [详细]
  • 本文详细介绍了Java中的访问器(getter)和修改器(setter),探讨了它们在保护数据完整性、增强代码可维护性方面的重要作用。通过具体示例,展示了如何正确使用这些方法来控制类属性的访问和更新。 ... [详细]
  • 本文详细探讨了VxWorks操作系统中双向链表和环形缓冲区的实现原理及使用方法,通过具体示例代码加深理解。 ... [详细]
  • MySQL索引详解与优化
    本文深入探讨了MySQL中的索引机制,包括索引的基本概念、优势与劣势、分类及其实现原理,并详细介绍了索引的使用场景和优化技巧。通过具体示例,帮助读者更好地理解和应用索引以提升数据库性能。 ... [详细]
author-avatar
手机用户2502906377
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有