Skip to content

Use the custom implementation of multipliedFullWidth on arm64_32 #37905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions stdlib/public/core/IntegerTypes.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -1514,15 +1514,23 @@ ${assignmentOperatorComment(x.operator, True)}
% end

% dbits = bits*2
% if bits <= word_bits:
% if bits == 64:
#if !(arch(arm) || arch(i386) || arch(wasm32))
// On 32b architectures we fall back on the generic implementation,
// because LLVM doesn't know how to codegen the 128b multiply we use.
//
// Note that arm64_32 is a 64b architecture for the purposes of this
// check, because we have a 64x64 -> 128 multiply there (the actual
// ISA is AArch64).
% end
/// Returns a tuple containing the high and low parts of the result of
/// multiplying this value by the given value.
///
/// Use this method to calculate the full result of a product that would
/// otherwise overflow. Unlike traditional truncating multiplication, the
/// `multipliedFullWidth(by:)` method returns a tuple
/// containing both the `high` and `low` parts of the product of this value and
/// `other`. The following example uses this method to multiply two `UInt8`
/// `multipliedFullWidth(by:)` method returns a tuple containing both the
/// `high` and `low` parts of the product of this value and `other`.
/// The following example uses this method to multiply two `UInt8`
/// values that normally overflow when multiplied:
///
/// let x: UInt8 = 100
Expand Down Expand Up @@ -1557,6 +1565,8 @@ ${assignmentOperatorComment(x.operator, True)}
let high = ${Self}(Builtin.truncOrBitCast_Int${dbits}_Int${bits}(shifted))
return (high: high, low: low)
}
% if bits == 64:
#endif
% end

/// Returns a tuple containing the quotient and remainder of dividing the
Expand Down