Skip to content

isdigit(Char(::UInt8)) performance regression? #25883

@samoconnor

Description

@samoconnor

In 0.7 it seems that isdigit(Char(x::Uint8)) produces more than 3 times as many instructions as
x::UInt8 in UInt8('0'):UInt8('9').

Is there a good reason not to define isdigit(x::UInt8) = x in UInt8('0'):UInt8('9') in Base?

julia> VERSION
v"0.6.2"

julia> code_native(x->isdigit(Char(x)), (UInt8,))
	.section	__TEXT,__text,regular,pure_instructions
	pushq	%rbp
	movq	%rsp, %rbp
	addb	$-48, %dil
	cmpb	$10, %dil
	setb	%al
	popq	%rbp
	retq
	nopw	%cs:(%rax,%rax)
julia> VERSION
v"0.7.0-DEV.3639"

# x in '0':'9' produces 5 instructions...
julia> code_native(x->x in UInt8('0'):UInt8('9'), (UInt8,))
	.section	__TEXT,__text,regular,pure_instructions
	addb	$-48, %dil
	cmpb	$10, %dil
	setb	%al
	retq
	nopl	(%rax)
;}

# ... but isdigit produces...
julia> code_native(x->isdigit(Char(x)), (UInt8,))
	.section	__TEXT,__text,regular,pure_instructions
	movzbl	%dil, %eax
	testb	%dil, %dil
	js	L22
	shll	$24, %eax
	cmpl	$805306368, %eax        ## imm = 0x30000000
	jae	L43
	xorl	%eax, %eax
	retq
L22:
	movl	%eax, %ecx
	andl	$63, %ecx
	andl	$192, %eax
	leal	(%rcx,%rax,4), %eax
	shll	$16, %eax
	orl	$3229614080, %eax       ## imm = 0xC0800000
L43:
	cmpl	$956301313, %eax        ## imm = 0x39000001
	setb	%al
	retq
	nopw	%cs:(%rax,%rax)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions