Skip to content

Add f64 <-> i64/u64 conversions - #310

Open
Shnatsel wants to merge 8 commits into
linebender:mainfrom
Shnatsel:64-bit-conversions
Open

Add f64 <-> i64/u64 conversions#310
Shnatsel wants to merge 8 commits into
linebender:mainfrom
Shnatsel:64-bit-conversions

Conversation

@Shnatsel

@Shnatsel Shnatsel commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Part of #297

The combined diff is large but it's not as scary as it looks. This is what this PR does:

  • Add 64-bit type conversions, with lowering to hardware instructions where available, and scalar fallback otherwise (482faea)
    • Faster AVX2 formulations are possible but that's for a follow-up PR to keep the size of this one manageable
  • Optimize AVX-512 Float->Unsigned conversion for both 32 and 64 bits (39adc0e)
  • The rest is generator refactoring for readability with no impact on the generated code, confined to its own separate commits

@danderson danderson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed commit by commit, which makes the refactors easy to reason about because they don't alter codegen output or tests.

Avx512,
}

#[derive(Clone, Copy, PartialEq, Eq)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe Debug too? Only matters for println debugging though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an internal generator struct, we'll add it when it comes up

Comment thread fearless_simd_gen/src/mk_x86.rs Outdated
intrinsic_ident("setzero", coarse_type(&target_ty), target_ty.n_bits());
let upper_bound = match scalar_bits {
32 => quote! { 2147483648.0 },
64 => quote! { 9223372036854775808.0 },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this literal survive compilation unchanged? In rust playground, loading it into an f64 rounds it up to 9223372036854776000.0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a formatting artifact, the bitpattern is the same. Try this:

let x = 9223372036854775808.0_f64;

assert_eq!(x.to_bits(), 0x43e0_0000_0000_0000);
assert_eq!(x, 2.0_f64.powi(63));

I've added a comment on that, and then looked at it and added comments on the rest of the code as well because if you didn't write it it's probably completely inscrutable

# Conflicts:
#	fearless_simd_gen/src/mk_simd_types.rs
@Shnatsel Shnatsel mentioned this pull request Aug 6, 2026
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