SIMD 编程语言 [英] SIMD programming languages

查看:78
本文介绍了SIMD 编程语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的几年里,我一直在做大量的 SIMD 编程,而且大部分时间我一直依赖编译器的内在函数(例如用于 SSE 编程的那些)或编程汇编来获得真正漂亮的东西.然而,到目前为止,我几乎找不到任何内置支持 SIMD 的编程语言.

In the last couple of years, I've been doing a lot of SIMD programming and most of the time I've been relying on compiler intrinsic functions (such as the ones for SSE programming) or on programming assembly to get to the really nifty stuff. However, up until now I've hardly been able to find any programming language with built-in support for SIMD.

现在显然有一些着色器语言,例如 HLSL、Cg 和 GLSL,它们对这类东西有本机支持,但是,我正在寻找至少能够在没有自动向量化的情况下编译为 SSE 但具有内置支持的东西用于向量运算.有这样的语言吗?

Now obviously there are the shader languages such as HLSL, Cg and GLSL that have native support for this kind of stuff however, I'm looking for something that's able to at least compile to SSE without autovectorization but with built-in support for vector operations. Does such a language exist?

这是一个(部分)Cg 着色器的例子,它做一个聚光灯,就语法而言,这可能是我正在寻找的最接近的.

This is an example of (part of) a Cg shader that does a spotlight and in terms of syntax this is probably the closest to what I'm looking for.

float4 pixelfunction(
    output_vs IN, 
    uniform sampler2D texture : TEX0, 
    uniform sampler2D normals : TEX1, 
    uniform float3 light, 
    uniform float3 eye ) : COLOR
{
    float4 color    = tex2D( texture, IN.uv );
    float4 normal   = tex2D( normals, IN.uv ) * 2 - 1;

    float3 T = normalize(IN.T);
    float3 B = normalize(IN.B);

    float3 N = 
        normal.b * normalize(IN.normal) +
        normal.r * T +
        normal.g * B;

    float3 V = normalize(eye - IN.pos.xyz);
    float3 L = normalize(light - IN.pos);
    float3 H = normalize(L + V);

    float4 diffuse  = color * saturate( dot(N, L) );
    float4 specular = color * pow(saturate(dot(N, H)), 15);
    float falloff   = dot(L, normalize(light));

    return pow(falloff, 5) * (diffuse + specular);
}

在这种语言中真正必须的东西是:

Stuff that would be a real must in this language is:

  • 内置 swizzle 运算符
  • 矢量操作(点、交叉、归一化、饱和、反射等)
  • 支持自定义数据类型(结构)
  • 动态分支会很好(for 循环、if 语句)

推荐答案

所以最近 Intel 发布了 ISPC正是我在问这个问题时正在寻找的.它是一种可以与普通 C 代码链接的语言,具有隐式执行模型,并支持开始文章中提到的所有功能(混合运算符、分支、数据结构、向量操作、着色器等)并为 SSE2、SSE4 编译,AVX、AVX2 和 Xeon Phi 矢量指令.

So recently Intel released ISPC which is exactly what I was looking for when asking this question. It's a language that can link with normal C code, has and implicit execution model, and support for all the features mentioned in the start post (swizzle operators, branching, data structs, vector ops, shader like) and compiles for SSE2, SSE4, AVX, AVX2, and Xeon Phi vector instructions.

这篇关于SIMD 编程语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆