From 8ed89760dadf85d860973100c658fbf2e7c8c16e Mon Sep 17 00:00:00 2001 From: Tuomas Tonteri Date: Sat, 17 Aug 2024 12:14:52 +0300 Subject: [PATCH] Fix unnecessary code repetition in SSE2 patch. Signed-off-by: Tuomas Tonteri --- src/liboslexec/llvm_util.cpp | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/liboslexec/llvm_util.cpp b/src/liboslexec/llvm_util.cpp index 400cef535..482761efe 100644 --- a/src/liboslexec/llvm_util.cpp +++ b/src/liboslexec/llvm_util.cpp @@ -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 @@ -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));