@@ -174,10 +174,10 @@ struct AddWrapFunctions : public AST::NonParameterisedObjectVisitor
174
174
if (auto constIndex = createConstantWrappedIndex (index, isClamp, size))
175
175
return *constIndex;
176
176
177
- if (! isClamp && choc::math::isPowerOf2 (size))
178
- return AST::createBinaryOp (index.context , AST::BinaryOpTypeEnum::Enum::bitwiseAnd,
179
- AST::createCastIfNeeded (index.context .allocator .int32Type , AST::castToRef<AST::ValueBase> (index)),
180
- index.context .allocator .createConstantInt32 (static_cast <int32_t > (size - 1 )));
177
+ // if (! isClamp && choc::math::isPowerOf2 (size))
178
+ // return AST::createBinaryOp (index.context, AST::BinaryOpTypeEnum::Enum::bitwiseAnd,
179
+ // AST::createCastIfNeeded (index.context.allocator.int32Type, AST::castToRef<AST::ValueBase> (index)),
180
+ // index.context.allocator.createConstantInt32 (static_cast<int32_t> (size - 1)));
181
181
182
182
auto & function = getOrCreateWrapOrClampFunction (isClamp, size);
183
183
return AST::createFunctionCall (index.context , function, index);
@@ -218,6 +218,17 @@ struct AddWrapFunctions : public AST::NonParameterisedObjectVisitor
218
218
void createWrapFunction (AST::ScopeBlock& block, AST::VariableReference& param, AST::ConstantValueBase& size)
219
219
{
220
220
auto & context = block.context ;
221
+
222
+ if (choc::math::isPowerOf2 (*size.getAsInt32 ()))
223
+ {
224
+ auto & value = AST::createBinaryOp (context, AST::BinaryOpTypeEnum::Enum::bitwiseAnd,
225
+ param,
226
+ allocator.createConstantInt32 (*size.getAsInt32 () - 1 ));
227
+
228
+ AST::addReturnStatement (block, value);
229
+ return ;
230
+ }
231
+
221
232
auto & nModSize = AST::createBinaryOp (context, AST::BinaryOpTypeEnum::Enum::modulo, param, size);
222
233
auto & x = AST::createLocalVariableRef (block, " x" , nModSize);
223
234
0 commit comments