Skip to content

Add mul_q15 and mul_q15_precise for 16-bit signed integer vectors - #444

Closed
LaurenzV wants to merge 1 commit into
linebender:mainfrom
LaurenzV:mul-q15
Closed

LaurenzV wants to merge 1 commit into
linebender:mainfrom
LaurenzV:mul-q15

Conversation

@LaurenzV

@LaurenzV LaurenzV commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Need this for my SVG filters crate I'm working on, for Gaussian blur. While a bit niche, it has dedicated instructions on all architectures, so worth having I think? Otherwise, I need to emulate it with feature gates on my side, and it's still worse.

Unfortunately, there is one edge case that is handled differently on x86... Hence why we need a fast variant and a _precise one. 🙃

@LaurenzV
LaurenzV requested a review from Shnatsel November 17, 2026 19:46
@Shnatsel

Copy link
Copy Markdown
Contributor

If the difference in overflow handling, then we should have mul_q15 and saturating_mul_q15 following the existing saturating_add convention in both fearless_simd and std

@LaurenzV

Copy link
Copy Markdown
Collaborator Author

The problem is that, from what I've seen, NEON only has saturating, while x86 _only has wrapping. This means if we only have one method for saturating and one for wrapping, it's going to be slower on one of the two platforms. So I would like to have a method where the -32768 × -32768 case is unspecified, to get the best performance on all platforms.

Maybe mul_q15 for saturating and relaxed_mul_q15 for unspecified?

@Shnatsel

Copy link
Copy Markdown
Contributor

Sounds like we can't really provide consistent semantics here then. We can only implement the _relaxed variant that would be fast, so we're not really gaining portability here.

The operation seems rather niche and difficult to explain. The way q15 types are exposed is also an API decision; should we expose a q15 vector type, with conversions to/from i32 vectors, bitcasting into u16/i16 vectors, and other basic ops like addition?

I'm leaning against merging this in the current form. You can add these ops to your crate via an extension trait, which Vello already does; I think that's the better path forward if all you need is multiplication.

@LaurenzV

Copy link
Copy Markdown
Collaborator Author

😕 I personally don't see it as being very problematic, as long as we maybe improve the documentation a bit, to clarify that the i16 is interpreted as a fixed-point number. But I'll trust your judgement here, I'll work around it from my side!

@LaurenzV LaurenzV closed this Nov 20, 2026
@Shnatsel

Copy link
Copy Markdown
Contributor

Maybe I'm over-reacting after #433

Feel free to ask other maintainers/contributors for a second opinion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants