Skip to content

Integer multiply high (mulh) equivalent in SimdInt and SimdUint #440

Open
@ds84182

Description

@ds84182

LLVM already has a fairly shaky optimization that doesn't make it through isel when followed by a left or right shift. https://rust.godbolt.org/z/a6eexcE6z

#![no_std]
#![feature(portable_simd)]

use core::simd::prelude::*;

// Generates vpmulhw
pub fn mulhw(a: i16x16, b: i16x16) -> i16x16 {
    (((a.cast::<i32>()) * (b.cast::<i32>())) >> 16).cast::<i16>()
}

// Generates a mess
pub fn mulhw_and_shift(a: i16x16, b: i16x16) -> i16x16 {
    mulhw(a, b) >> 1
}

A dedicated function that can multiply two integers and take the high parts would be very beneficial when handling fixed-point integers. And hopefully it'll have a better chance of surviving optimization passes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: a feature request, i.e. not implemented / a PR

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions