Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
Go
Haskell
HLSL
Hook
Hylo
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Nim
Objective-C
Objective-C++
OCaml
OpenCL C
Pascal
Pony
Python
Racket
Ruby
Rust
Snowball
Scala
Solidity
Spice
Swift
LLVM TableGen
Toit
TypeScript Native
V
Vala
Visual Basic
Zig
Javascript
GIMPLE
ispc source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
ispc (templates_new)
ispc (trunk)
ispc 1.10.0
ispc 1.11.0
ispc 1.12.0
ispc 1.13.0
ispc 1.14.0
ispc 1.14.1
ispc 1.15.0
ispc 1.16.0
ispc 1.16.1
ispc 1.17.0
ispc 1.18.0
ispc 1.19.0
ispc 1.20.0
ispc 1.21.0
ispc 1.22.0
ispc 1.23.0
ispc 1.9.1
ispc 1.9.2
Options
Source code
struct FVector4 { float<4> V; }; struct FMatrix { float<4> X; float<4> Y; float<4> Z; float<4> W; }; inline void MulVec4FloatMat(uniform FVector4& V, const uniform float F, const uniform float<4> M) { V.V = F * M; } inline void Vec4Add(uniform FVector4& V1, const uniform FVector4 V2) { V1.V += V2.V; } inline void VecReplicate(uniform FVector4& Target, const uniform FVector4 Source) { Target.V = Source.V; } struct WideFVector4 { float V[programCount]; }; unmasked inline uniform WideFVector4 operator+(const uniform WideFVector4 &A, const uniform WideFVector4 &B) { uniform WideFVector4 Result; Result.V[programIndex] = A.V[programIndex] + B.V[programIndex]; return Result; } unmasked inline uniform WideFVector4 operator*(const uniform WideFVector4 &A, const uniform WideFVector4 &B) { uniform WideFVector4 Result; Result.V[programIndex] = A.V[programIndex] * B.V[programIndex]; return Result; } unmasked inline uniform WideFVector4 VectorReplicateFloat4(const uniform float<4> Vec, const uniform int X, const uniform int Y, const uniform int Z, const uniform int W) { #if TARGET_WIDTH == 4 const varying int vPerm = { X, Y, Z, W}; #elif TARGET_WIDTH == 8 const varying int vPerm = { X, Y, Z, W, X, Y, Z, W }; #elif TARGET_WIDTH == 16 const varying int vPerm = { X, Y, Z, W, X, Y, Z, W, X, Y, Z, W, X, Y, Z, W }; #endif float V; *((uniform float<4> * uniform)&V) = *((uniform float<4> * uniform)&Vec); const float R = shuffle(V, vPerm); uniform WideFVector4 Result; Result.V[programIndex] = R; return Result; } unmasked inline uniform WideFVector4 VectorReplicate(const uniform WideFVector4 &Vec, const uniform int R) { #if TARGET_WIDTH == 4 const varying int vPerm = { R, R, R, R }; #elif TARGET_WIDTH == 8 const varying int vPerm = { R, R, R, R, R+4, R+4, R+4, R+4 }; #elif TARGET_WIDTH == 16 const varying int vPerm = { R, R, R, R, R+4, R+4, R+4, R+4, R+8, R+8, R+8, R+8, R+12, R+12, R+12, R+12 }; #endif const float V = Vec.V[programIndex]; const float S = shuffle(V, vPerm); uniform WideFVector4 Result; Result.V[programIndex] = S; return Result; } unmasked void MatrixTransformVector( const uniform FVector4 V[], const uniform FMatrix& M, uniform FVector4 out[], const uniform int count) { const uniform int CountBase = count & ~(programCount-1); const uniform int CountOffset = programCount / 4; const uniform WideFVector4 MX = VectorReplicateFloat4(M.X, 0, 1, 2, 3); const uniform WideFVector4 MY = VectorReplicateFloat4(M.Y, 0, 1, 2, 3); const uniform WideFVector4 MZ = VectorReplicateFloat4(M.Z, 0, 1, 2, 3); const uniform WideFVector4 MW = VectorReplicateFloat4(M.W, 0, 1, 2, 3); for(uniform int CountIdx = 0; CountIdx < CountBase; CountIdx+=CountOffset) { uniform float *uniform SrcPtr = (uniform float * uniform)&V[CountIdx]; uniform float *uniform DstPtr = (uniform float * uniform)&out[CountIdx]; uniform WideFVector4 v; v.V[programIndex] = SrcPtr[programIndex]; const uniform WideFVector4 tempX = VectorReplicate(v, 0) * MX; const uniform WideFVector4 tempY = VectorReplicate(v, 1) * MY; const uniform WideFVector4 tempZ = VectorReplicate(v, 2) * MZ; const uniform WideFVector4 tempW = VectorReplicate(v, 3) * MW; const uniform WideFVector4 Result = tempX + tempY + tempZ + tempW; streaming_store(&DstPtr[0], Result.V[programIndex]); } for (uniform int CountIdx = CountBase; CountIdx < count; CountIdx++) { const uniform FVector4 v = V[CountIdx]; uniform FVector4 tempX; MulVec4FloatMat(tempX, v.V[0], M.X); uniform FVector4 tempY; MulVec4FloatMat(tempY, v.V[1], M.Y); uniform FVector4 tempZ; MulVec4FloatMat(tempZ, v.V[2], M.Z); uniform FVector4 tempW; MulVec4FloatMat(tempW, v.V[3], M.W); Vec4Add(tempX, tempY); Vec4Add(tempZ, tempW); Vec4Add(tempX, tempZ); VecReplicate(out[CountIdx], tempX); } }
Become a Patron
Sponsor on GitHub
Donate via PayPal
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
About the author
Statistics
Changelog
Version tree