Skip to content

Commit

Permalink
fix after merge and remove function overload
Browse files Browse the repository at this point in the history
Signed-off-by: martinvuyk <martin.vuyklop@gmail.com>
  • Loading branch information
martinvuyk committed Feb 27, 2025
1 parent eca0ffc commit ec4968a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 42 deletions.
4 changes: 3 additions & 1 deletion stdlib/src/collections/string/string_slice.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -2197,6 +2197,8 @@ fn _memmem[


@always_inline
# FIXME(#2535): remove capturing once function effects can be parametrized
@parameter
fn _is_utf8_continuation_byte[
w: Int
](vec: SIMD[DType.uint8, w]) -> SIMD[DType.bool, w]:
Expand All @@ -2205,7 +2207,7 @@ fn _is_utf8_continuation_byte[

@always_inline
fn _count_utf8_continuation_bytes(span: Span[Byte]) -> Int:
return span.count[func=_is_continuation_byte]()
return span.count[func=_is_utf8_continuation_byte]()


@always_inline
Expand Down
42 changes: 1 addition & 41 deletions stdlib/src/memory/span.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -510,47 +510,7 @@ struct Span[
)
)

fn count[
D: DType, //, func: fn[w: Int] (SIMD[D, w]) -> SIMD[DType.bool, w]
](self: Span[Scalar[D]]) -> UInt:
"""Count the amount of times the function returns `True`.
Parameters:
D: The DType.
func: The function to evaluate.
Returns:
The amount of times the function returns `True`.
"""

alias widths = (256, 128, 64, 32, 16, 8)
var ptr = self.unsafe_ptr()
var length = len(self)
var amnt = UInt(0)
var processed = 0

@parameter
for i in range(len(widths)):
alias w = widths[i]

@parameter
if simdwidthof[D]() >= w:
for _ in range((length - processed) // w):
var vec = (ptr + processed).load[width=w]()

@parameter
if w >= 256:
amnt += Int(func(vec).cast[DType.uint16]().reduce_add())
else:
amnt += Int(func(vec).cast[DType.uint8]().reduce_add())
processed += w

for i in range(length - processed):
amnt += Int(func(ptr[processed + i]))

return amnt

# FIXME(#2535): delete once function effects can be parametrized
# FIXME(#2535): parametrize capturing once function effects can be parametrized
fn count[
D: DType, //,
func: fn[w: Int] (SIMD[D, w]) capturing -> SIMD[DType.bool, w],
Expand Down

0 comments on commit ec4968a

Please sign in to comment.