mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-18 10:32:48 +02:00
[Matrix] Add support for matrix-by-scalar division.
This patch extends the matrix spec to allow matrix-by-scalar division. Originally support for `/` was left out to avoid ambiguity for the matrix-matrix version of `/`, which could either be elementwise or specified as matrix multiplication M1 * (1/M2). For the matrix-scalar version, no ambiguity exists; `*` is also an elementwise operation in that case. Matrix-by-scalar division is commonly supported by systems including Matlab, Mathematica or NumPy. Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D97857
This commit is contained in:
parent
68c47b952f
commit
648fd413ce
@ -215,6 +215,22 @@ public:
|
||||
return B.CreateMul(LHS, RHS);
|
||||
}
|
||||
|
||||
/// Divide matrix \p LHS by scalar \p RHS. If the operands are integers, \p
|
||||
/// IsUnsigned indicates whether UDiv or SDiv should be used.
|
||||
Value *CreateScalarDiv(Value *LHS, Value *RHS, bool IsUnsigned) {
|
||||
assert(LHS->getType()->isVectorTy() && !RHS->getType()->isVectorTy());
|
||||
assert(!isa<ScalableVectorType>(LHS->getType()) &&
|
||||
"LHS Assumed to be fixed width");
|
||||
RHS =
|
||||
B.CreateVectorSplat(cast<VectorType>(LHS->getType())->getElementCount(),
|
||||
RHS, "scalar.splat");
|
||||
return cast<VectorType>(LHS->getType())
|
||||
->getElementType()
|
||||
->isFloatingPointTy()
|
||||
? B.CreateFDiv(LHS, RHS)
|
||||
: (IsUnsigned ? B.CreateUDiv(LHS, RHS) : B.CreateSDiv(LHS, RHS));
|
||||
}
|
||||
|
||||
/// Extracts the element at (\p RowIdx, \p ColumnIdx) from \p Matrix.
|
||||
Value *CreateExtractElement(Value *Matrix, Value *RowIdx, Value *ColumnIdx,
|
||||
unsigned NumRows, Twine const &Name = "") {
|
||||
|
Loading…
Reference in New Issue
Block a user