← Back to Pull requests

intrinsics: Support SIMD vectors in elementwise intrinsics #63347

Open
oscardssmith opened this pull request with 816 lines diff across 10 files
View on GitHub
oscardssmith oscardssmith commented on Sep 25, 2026 00:01 UTC
Author

successor to https://github.com/JuliaLang/julia/pull/55118 (now with claude)

Many intrinsics (arithmetic, bitwise, shifts, comparisons, conversions and bitcast) now accept SIMD vectors, i.e. NTuple{N,VecElement{T}} for primitive T that LLVM can do as <N x T>. They act lane-wise and compile to LLVM vector instructions, so SIMD code no longer needs llvmcall for these operations. Comparisons return a NTuple{N,VecElement{Bool}}, and bitcast only requires the total bit size to match. Checked intrinsics aren't supported.

Codegen lowers these directly to LLVM. Runtime applies the scalar implementation to each lane, and inference models the new result types and nothrow conditions so vector operations can be folded and removed when unused.

Random's XoshiroSimd now uses these intrinsics instead of llvmcall; the generated random stream is unchanged.

Assisted-by: Claude Code (Opus 5.5)

Diff: 816 lines (+680 / -136) across 10 files Reviewer: matthias314 Review duration: 76482m
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.68) × (1 − Review Confidence (0.74)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.68 · 816 lines diff across 10 files
0.68
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.66 · 1 substantive comment(s)
0.66
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
74%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.400
Ai Authored ai_authored
0.050
Real PR Conversation Timeline
2 items
matthias314 matthias314 commented on code on Sep 25, 2026 23:55 UTC
Code Review
stdlib/Random/src/XoshiroSimd.jl:1
@@ -61,92 +55,35 @@ end
     return (UInt64(reinterpret(UInt16, f1)) << 48) | (UInt64(reinterpret(UInt16, f2)) << 32) | (UInt64(reinterpret(UInt16, f3)) << 16) | UInt64(reinterpret(UInt16, f4))
 end
 
-# required operations. These could be written more concisely with `ntuple`, but the compiler
-# sometimes refuses to properly vectorize.
-for N in [4,8,16]
-    let code, s, fshl = "llvm.fshl.v$(N)i64",
-        VT = :(NTuple{$N, VecElement{UInt64}})
-
-        s = ntuple(_->VecElement(UInt64(45)), N)
-        @eval @inline _rotl45(x::$VT) = ccall($fshl, llvmcall, $VT, ($VT, $VT, $VT), x, x, $s)
-
-        s = ntuple(_->VecElement(UInt64(23)), N)
-        @eval @inline _rotl23(x::$VT) = ccall($fshl, llvmcall, $VT, ($VT, $VT, $VT), x, x, $s)
-
-        code = """
-        %lshiftOp = shufflevector <1 x i64> <i64 17>, <1 x i64> undef, <$N x i32> zeroinitializer
-        %res = shl <$N x i64> %0, %lshiftOp
-        ret <$N x i64> %res
-        """
-        @eval @inline _shl17(x::$VT) = llvmcall($code, $VT, Tuple{$VT}, x)
-
-        code = """
-        %res = add <$N x i64> %1, %0
-        ret <$N x i64> %res
-        """
-        @eval @inline _plus(x::$VT, y::$VT) = llvmcall($code, $VT, Tuple{$VT, $VT}, x, y)
-
-        code = """
-        %res = xor <$N x i64> %1, %0
-        ret <$N x i64> %res
-        """
-        @eval @inline _xor(x::$VT, y::$VT) = llvmcall($code, $VT, Tuple{$VT, $VT}, x, y)
-
-        code = """
-        %res = and <$N x i64> %1, %0
-        ret <$N x i64> %res
-        """
-        @eval @inline _and(x::$VT, y::$VT) = llvmcall($code, $VT, Tuple{$VT, $VT}, x, y)
-
-        code = """
-        %res = or <$N x i64> %1, %0
-        ret <$N x i64> %res
-        """
-        @eval @inline _or(x::$VT, y::$VT) = llvmcall($code, $VT, Tuple{$VT, $VT}, x, y)
-
-        code = """
-        %tmp = insertelement <1 x i64> undef, i64 %1, i32 0
-        %shift = shufflevector <1 x i64> %tmp, <1 x i64> %tmp, <$N x i32> zeroinitializer
-        %res = lshr <$N x i64> %0, %shift
-        ret <$N x i64> %res
-        """
-        @eval @inline _lshr(x::$VT, y::Int64) = llvmcall($code, $VT, Tuple{$VT, Int64}, x, y)
-
-        code = """
-        %shiftamt = shufflevector <1 x i64> <i64 11>, <1 x i64> undef, <$N x i32> zeroinitializer
-        %sh = lshr <$N x i64> %0, %shiftamt
-        %f = uitofp <$N x i64> %sh to <$N x double>
-        %scale = shufflevector <1 x double> <double 0x3ca0000000000000>, <1 x double> undef, <$N x i32> zeroinitializer
-        %m = fmul <$N x double> %f, %scale
-        %i = bitcast <$N x double> %m to <$N x i64>
-        ret <$N x i64> %i
-        """
-        @eval @inline _bits2float(x::$VT, ::Type{Float64}) = llvmcall($code, $VT, Tuple{$VT}, x)
-
-        code = """
-        %as32 = bitcast <$N x i64> %0 to <$(2N) x i32>
-        %shiftamt = shufflevector <1 x i32> <i32 8>, <1 x i32> undef, <$(2N) x i32> zeroinitializer
-        %sh = lshr <$(2N) x i32> %as32, %shiftamt
-        %f = uitofp <$(2N) x i32> %sh to <$(2N) x float>
-        %scale = shufflevector <1 x float> <float 0x3e70000000000000>, <1 x float> undef, <$(2N) x i32> zeroinitializer
-        %m = fmul <$(2N) x float> %f, %scale
-        %i = bitcast <$(2N) x float> %m to <$N x i64>
-        ret <$N x i64> %i
-        """
-        @eval @inline _bits2float(x::$VT, ::Type{Float32}) = llvmcall($code, $VT, Tuple{$VT}, x)
-
-        code = """
-        %as16 = bitcast <$N x i64> %0 to <$(4N) x i16>
-        %shiftamt = shufflevector <1 x i16> <i16 5>, <1 x i16> undef, <$(4N) x i32> zeroinitializer
-        %sh = lshr <$(4N) x i16> %as16, %shiftamt
-        %f = uitofp <$(4N) x i16> %sh to <$(4N) x half>
-        %scale = shufflevector <1 x half> <half 0x3f40000000000000>, <1 x half> undef, <$(4N) x i32> zeroinitializer
-        %m = fmul <$(4N) x half> %f, %scale
-        %i = bitcast <$(4N) x half> %m to <$N x i64>
-        ret <$N x i64> %i
-        """
-        @eval @inline _bits2float(x::$VT, ::Type{Float16}) = llvmcall($code, $VT, Tuple{$VT}, x)
-    end
+# required operations on SIMD vectors. These could be written more concisely with `ntuple`, but
+# the compiler sometimes refuses to properly vectorize, so they use the intrinsics directly.

Out of curiosity: Do you have an example where vectorization fails?

Reviewers
Assignees
oscardssmith oscardssmith
Labels
risk: low confidence: 74.2% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 68.2% (HIGH) · Higher = larger blast radius
68.2%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 74.2% · Lower = rushed or shallow review
74.2%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 17.6% · Safe to merge
17.6%