Skip to content
Alessandro Autiero
Go back

On JDK-8377386: dot product instructions for the Vector API

Context: this was my comment on openjdk/jdk#32359 (JDK-8377386), which adds vectorized dot product support on aarch64 (sdot/udot) through the Vector API.

Hi, I’d like to add a +1 for this with a concrete use case. I also think having x86 support would be really cool.

I have been building for some time a pure Java media library that uses the Vector API for its codecs: AV1, HEVC, H.264, VP9 and VP8 decoding and encoding, WebP, AAC and so on. I’ve been benchmarking every codec throughout development against FFmpeg and dav1d. I have plans to release this work soon, but I was trying to reach performance parity in as many workloads as possible against these implementations before doing so. Most of the remaining gap comes from one thing: the Vector API has no integer multiply-add for narrow types. Right now every byte-times-coefficient kernel widens the bytes, multiplies in wider lanes and adds, which costs 2 to 4 times the instructions of the native code. What I think I would need is dot products over 8-bit pixels or 16-bit coefficients, so this PR is exactly the primitive I’m missing.

On the points raised above:

  • I don’t think dot product is a snowflake op, at least not in media code. Basically every motion compensation filter, transform and SATD/RD cost kernel in FFmpeg, dav1d and libvpx is built on pmaddubsw/pmaddwd on x86 or sdot/udot/usdot on Arm. x86 has had the 16-bit pair version (pmaddwd) since SSE2, so it’s about as portable as integer SIMD gets.
  • The scalar-returning int dot(Vector<Byte>) wouldn’t work for my use case. A filter needs one group sum per output sample: each output pixel is the sum of 4 or 8 taps times 4 or 8 pixels. So the current shape, with a group-wise IntVector result and an accumulator, is exactly what I need. Reducing to a scalar on every call would make it unusable for filters and transforms.
  • I’d also be careful with recognizing the pattern in C2 instead. I already spend a lot of time writing kernels in the specific shapes C2 handles well; for example, range checks only get hoisted when the index has a constant scale, so I keep one kernel per block size. If the dot product only kicks in when I hit a matched IR shape, that’s the same brittleness as auto-vectorization, which is the reason I’m using the Vector API in the first place. An explicit op with an exact fallback (widen, mul, add) is predictable.

A few things:

  1. I think x86 support could be added. With AVX-VNNI / AVX512-VNNI this maps to vpdpbusd (and vpdpbssd / vpdpbuud on newer cores). On plain AVX2 a fallback through zero-extend + vpmaddwd would still beat what we can write today. It has to keep exact semantics, so not pmaddubsw, since that saturates.
  2. I’m not sure whether this is covered, but mixed signedness (unsigned x signed) would be very important for some use cases, like video. Pixels are unsigned bytes and filter taps are signed, which is exactly what vpdpbusd, pmaddubsw and aarch64’s usdot do. With only signed x signed and unsigned x unsigned we’d still have to widen or bias the pixels first.
  3. I think a 16-bit variant (e.g. ShortVector.dot into IntVector, pairs of shorts per int lane) would also be very useful: this is pmaddwd on x86 (vpdpwssd with VNNI), and it’s what transforms and the second filter pass of motion compensation need.

Maybe framing these as one family, a widening dot over groups of 4 bytes or 2 shorts into int lanes, would also make it feel less like a one-off operation.

I’m happy to test any of this on my codecs (x86 AVX2 and AVX-512 machines) and share before/after numbers if that helps the review.


Originally posted on the OpenJDK core-libs-dev mailing list on October 13, 2026.



Previous Post
Warm up Vector API