Skip to content

Commit

Permalink
Fix unnecessary code repetition in SSE2 patch.
Browse files Browse the repository at this point in the history
Signed-off-by: Tuomas Tonteri <[email protected]>
  • Loading branch information
johnfea committed Aug 17, 2024
1 parent 9e5c674 commit 8ed8976
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions src/liboslexec/llvm_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4027,37 +4027,29 @@ LLVM_Util::op_1st_active_lane_of(llvm::Value* mask)
// Assumes mask is not empty

llvm::Type* intMaskType = nullptr;
llvm::Value* int_mask;
switch (m_vector_width) {
case 16:
// We can just reinterpret cast a 16 bit mask to a 16 bit integer
// and all types are happy
intMaskType = type_int16();
int_mask = builder().CreateBitCast(mask, intMaskType);
break;
case 8:
// We can just reinterpret cast a 8 bit mask to a 8 bit integer
// and all types are happy
intMaskType = type_int8();
int_mask = builder().CreateBitCast(mask, intMaskType);
break;
case 4: {
intMaskType = type_int8();

llvm::Value* mask_as_int = mask4_as_int8(mask);

// Count trailing zeros, least significant
llvm::Type* types[] = { intMaskType };
llvm::Function* func_cttz
= llvm::Intrinsic::getDeclaration(module(), llvm::Intrinsic::cttz,
toArrayRef(types));

llvm::Value* args[2] = { mask_as_int, constant_bool(true) };

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

int_mask = mask4_as_int8(mask);
break;
}
default: OSL_ASSERT(0 && "unsupported native bit mask width");
default: {
OSL_ASSERT(0 && "unsupported native bit mask width");
int_mask = 0;
}
};

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

llvm::Value* int_mask = builder().CreateBitCast(mask, intMaskType);
llvm::Value* args[2] = { int_mask, constant_bool(true) };
llvm::Value* args[2] = { int_mask, constant_bool(true) };

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

0 comments on commit 8ed8976

Please sign in to comment.