yurydelendik commented on Issue #2303:
I wonder if we can wrap SmallVec
canonicalised
initialization logic into function and do it only when needed. Also, I think it is possible to avoidcanonicalise_then_XXXX
functions.fn canonicalise<'a>( builder: &mut FunctionBuilder, values: &[ir::Value],a: &'a [u8] ) -> impl AsRef<[ir::Value]> + 'a { enum Result<'a> { Ref(&'a [ir::Value]), Vec(SmallVec<[ir::Value; 16]>), } impl<'a> AsRef<[u8]> for Result<'a> { fn as_ref(&self) -> &[u8] { match self { Result::Ref(r) => r, Result::Vec(v) => v.as_slice(), } } } // do_checks_and_stuff if ... { Result::Vec(canonicalised) } else { Result::Ref(values) } } // do e.g. builder .ins() .jump( real_dest_block, canonicalise(builder, destination_args).as_ref() );
It is nice to see fast path for canonicalise when SIMD is not in use too.
yurydelendik edited a comment on Issue #2303:
I wonder if we can wrap SmallVec
canonicalised
initialization logic into function and do it only when needed. Also, I think it is possible to avoidcanonicalise_then_XXXX
functions.fn canonicalise<'a>( builder: &mut FunctionBuilder, values: &'a [ir::Value], ) -> impl AsRef<[ir::Value]> + 'a { enum Result<'a> { Ref(&'a [ir::Value]), Vec(SmallVec<[ir::Value; 16]>), } impl<'a> AsRef<[u8]> for Result<'a> { fn as_ref(&self) -> &[u8] { match self { Result::Ref(r) => r, Result::Vec(v) => v.as_slice(), } } } // do_checks_and_stuff if ... { Result::Vec(canonicalised) } else { Result::Ref(values) } } // do e.g. builder .ins() .jump( real_dest_block, canonicalise(builder, destination_args).as_ref() );
It is nice to see fast path for canonicalise when SIMD is not in use too.
yurydelendik edited a comment on Issue #2303:
I wonder if we can wrap SmallVec
canonicalised
initialization logic into function and do it only when needed. Also, I think it is possible to avoidcanonicalise_then_XXXX
functions.fn canonicalise<'a>( builder: &mut FunctionBuilder, values: &'a [ir::Value], ) -> impl AsRef<[ir::Value]> + 'a { enum Result<'a> { Ref(&'a [ir::Value]), Vec(SmallVec<[ir::Value; 16]>), } impl<'a> AsRef<[u8]> for Result<'a> { fn as_ref(&self) -> &[u8] { match self { Result::Ref(r) => r, Result::Vec(v) => v.as_slice(), } } } // do_checks_and_stuff if ... { Result::Vec(canonicalised) } else { Result::Ref(values) } } // do e.g. let params = canonicalise(builder, destination_args); builder .ins() .jump(real_dest_block, params.as_ref());
It is nice to see fast path for canonicalise when SIMD is not in use too.
julian-seward1 commented on Issue #2303:
Thanks all for the various comments/suggestions. I pushed a revised patch that addresses all of them.
Last updated: Nov 22 2024 at 17:03 UTC