Skip to content

Commit 21beebb

Browse files
arhikmaleadt
authored andcommitted
Refactor encode_reduce_body to use if/else instead of dispatch
Single-use functionality doesn't benefit from dispatch-based selection.
1 parent a7ebd17 commit 21beebb

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

src/bytecode/writer.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ function encode_tagged_int!(cb::CodeBuilder, identity::IntegerIdentityOp)
291291
encode_typeid!(cb.buf, identity.type_id)
292292
# Mask value to correct bit width and apply zigzag encoding for signed types
293293
masked_value = mask_to_width(identity.value, identity.dtype)
294-
encode_varint!(cb.buf, masked_value)
294+
encode_varint!(cb.buf, masked_value) # masked_value are already zigzag encoded
295295
end
296296

297297
"""

src/compiler/intrinsics/core.jl

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -618,17 +618,25 @@ operation_identity(::Val{:max}, dtype, ::Type{T}) where T <: Integer =
618618
IntegerIdentityOp(to_uint128(typemin(T)), dtype, T)
619619

620620
#=============================================================================#
621-
# Reduce Body Operations - dispatch on Val{fn} and elem_type
621+
# Reduce Body Operations
622622
#=============================================================================#
623623

624-
encode_reduce_body(cb, type, acc, elem, ::Val{:add}, ::Type{T}) where T <: AbstractFloat =
625-
encode_AddFOp!(cb, type, acc, elem)
626-
encode_reduce_body(cb, type, acc, elem, ::Val{:max}, ::Type{T}) where T <: AbstractFloat =
627-
encode_MaxFOp!(cb, type, acc, elem)
628-
encode_reduce_body(cb, type, acc, elem, ::Val{:add}, ::Type{T}) where T <: Integer =
629-
encode_AddIOp!(cb, type, acc, elem)
630-
encode_reduce_body(cb, type, acc, elem, ::Val{:max}, ::Type{T}) where T <: Integer =
631-
encode_MaxIOp!(cb, type, acc, elem; signedness=T <: Signed ? SignednessSigned : SignednessUnsigned)
624+
function encode_reduce_body(cb, type, acc, elem, op::Val, ::Type{T}) where T
625+
if T <: AbstractFloat
626+
if op == Val{:add}
627+
encode_AddFOp!(cb, type, acc, elem)
628+
else # Val{:max}
629+
encode_MaxFOp!(cb, type, acc, elem)
630+
end
631+
else # Integer
632+
signedness = T <: Signed ? SignednessSigned : SignednessUnsigned
633+
if op == Val{:add}
634+
encode_AddIOp!(cb, type, acc, elem)
635+
else # Val{:max}
636+
encode_MaxIOp!(cb, type, acc, elem; signedness)
637+
end
638+
end
639+
end
632640

633641

634642
# cuda_tile.reshape

0 commit comments

Comments
 (0)