Skip to content

Commit 8ed8976

Browse files
committed
Fix unnecessary code repetition in SSE2 patch.
Signed-off-by: Tuomas Tonteri <[email protected]>
1 parent 9e5c674 commit 8ed8976

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

src/liboslexec/llvm_util.cpp

+9-18
Original file line numberDiff line numberDiff line change
@@ -4027,37 +4027,29 @@ LLVM_Util::op_1st_active_lane_of(llvm::Value* mask)
40274027
// Assumes mask is not empty
40284028

40294029
llvm::Type* intMaskType = nullptr;
4030+
llvm::Value* int_mask;
40304031
switch (m_vector_width) {
40314032
case 16:
40324033
// We can just reinterpret cast a 16 bit mask to a 16 bit integer
40334034
// and all types are happy
40344035
intMaskType = type_int16();
4036+
int_mask = builder().CreateBitCast(mask, intMaskType);
40354037
break;
40364038
case 8:
40374039
// We can just reinterpret cast a 8 bit mask to a 8 bit integer
40384040
// and all types are happy
40394041
intMaskType = type_int8();
4042+
int_mask = builder().CreateBitCast(mask, intMaskType);
40404043
break;
40414044
case 4: {
40424045
intMaskType = type_int8();
4043-
4044-
llvm::Value* mask_as_int = mask4_as_int8(mask);
4045-
4046-
// Count trailing zeros, least significant
4047-
llvm::Type* types[] = { intMaskType };
4048-
llvm::Function* func_cttz
4049-
= llvm::Intrinsic::getDeclaration(module(), llvm::Intrinsic::cttz,
4050-
toArrayRef(types));
4051-
4052-
llvm::Value* args[2] = { mask_as_int, constant_bool(true) };
4053-
4054-
llvm::Value* firstNonZeroIndex = builder().CreateCall(func_cttz,
4055-
toArrayRef(args));
4056-
return firstNonZeroIndex;
4057-
4046+
int_mask = mask4_as_int8(mask);
40584047
break;
40594048
}
4060-
default: OSL_ASSERT(0 && "unsupported native bit mask width");
4049+
default: {
4050+
OSL_ASSERT(0 && "unsupported native bit mask width");
4051+
int_mask = 0;
4052+
}
40614053
};
40624054

40634055
// Count trailing zeros, least significant
@@ -4066,8 +4058,7 @@ LLVM_Util::op_1st_active_lane_of(llvm::Value* mask)
40664058
= llvm::Intrinsic::getDeclaration(module(), llvm::Intrinsic::cttz,
40674059
toArrayRef(types));
40684060

4069-
llvm::Value* int_mask = builder().CreateBitCast(mask, intMaskType);
4070-
llvm::Value* args[2] = { int_mask, constant_bool(true) };
4061+
llvm::Value* args[2] = { int_mask, constant_bool(true) };
40714062

40724063
llvm::Value* firstNonZeroIndex = builder().CreateCall(func_cttz,
40734064
toArrayRef(args));

0 commit comments

Comments
 (0)