16 bit jump tables for -Oss - code

Frank Klemm pfk@fuchs.offl.uni-jena.de
Wed Sep 5 14:54:00 GMT 2001


code is taken from strftime() as an example
This is the current GNU-C code:
------------------------------------------------------------------------
	movzbl	(%edx), %eax			switch (*charptr)
	subb	$65, %al			first label is 'A'  (is it not better to use subl $65, %eax ???)
	cmpb	$56, %al			last  label is 'z'  (is it not better to use cmpl $56, %eax ???)
	ja	.L4				default:
	movzbl	%al, %eax			masking is unnecessary, especially when using subl/cmpl
	jmp	*.L58(,%eax,4)			jumping to destination
	.p2align 4,,7
	
	.section	.rodata
	.align 16				do make this alignment makes sense? The data is not handled as a string, only some data is picked out
	.align 4
.L58:
	.long	.L23
	.long	.L26
	.long	.L32
	.long	.L4
	.long	.L4
	.long	.L4
	.long	.L4
	.long	.L37
	.long	.L38
	.long	.L4
	.long	.L4
	.long	.L4
	.long	.L43
	.long	.L4
	.long	.L4
	.long	.L30
	.long	.L4
	.long	.L16
	.long	.L44
	.long	.L19
	.long	.L4
	.long	.L4
	.long	.L4
	.long	.L18
	.long	.L50
	.long	.L49
	.long	.L4
	.long	.L4
	.long	.L4
	.long	.L4
	.long	.L4
	.long	.L4
	.long	.L21
	.long	.L25
	.long	.L13
	.long	.L34
	.long	.L35
	.long	.L4
	.long	.L4
	.long	.L25
	.long	.L4
	.long	.L39
	.long	.L40
	.long	.L41
	.long	.L42
	.long	.L11
	.long	.L4
	.long	.L27
	.long	.L4
	.long	.L15
	.long	.L4
	.long	.L12
	.long	.L45
	.long	.L4
	.long	.L48
	.long	.L17
	.long	.L51

	.text
	.p2align 4,,7

----------------------------------------------------------------------------------
optimized version
----------------------------------------------------------------------------------
	movzbl	(%edx), %eax			switch (*charptr)
	subl	$'A', %eax			first label is 'A'
	cmpl	$'z'-'A'+1, %eax		last  label is 'z'
	jnc	.L4				default:
	jmp	*.L58(,%eax,4)			jumping to destination
	.p2align 4,,7
	
	.section	.rodata
	.align 4
.L58:
	.short	.L23
	.short	.L26
	.short	.L32
	.short	.L4
	.short	.L4
	.short	.L4
	.short	.L4
	.short	.L37
	.short	.L38
	.short	.L4
	.short	.L4
	.short	.L4
	.short	.L43
	.short	.L4
	.short	.L4
	.short	.L30
	.short	.L4
	.short	.L16
	.short	.L44
	.short	.L19
	.short	.L4
	.short	.L4
	.short	.L4
	.short	.L18
	.short	.L50
	.short	.L49
	.short	.L4
	.short	.L4
	.short	.L4
	.short	.L4
	.short	.L4
	.short	.L4
	.short	.L21
	.short	.L25
	.short	.L13
	.short	.L34
	.short	.L35
	.short	.L4
	.short	.L4
	.short	.L25
	.short	.L4
	.short	.L39
	.short	.L40
	.short	.L41
	.short	.L42
	.short	.L11
	.short	.L4
	.short	.L27
	.short	.L4
	.short	.L15
	.short	.L4
	.short	.L12
	.short	.L45
	.short	.L4
	.short	.L48
	.short	.L17
	.short	.L51

	.text
	.p2align 4,,7


----------------------------------------------------------------------------------
Version for '-Oss' (aggressive size optimization) and larger tables (threshold must be defined)
----------------------------------------------------------------------------------
	movzbl	(%edx), %eax			switch (*charptr)
	subl	$'A', %eax			first label is 'A'
	cmpl	$'z'-'A'+1, %eax		last  label is 'z'
	jnc	.L4				default:
	movzwl	*.L58(,%eax,2),%eax		offset from first jump label (max. 64 Kbyte)
	addl	$.L58end, %eax			address of first label
	jmp	*%eax				jumping to destination
	.p2align 4,,7
	
	.section	.rodata
	.align 2
.L58:
	.short	.L23 - .L58end
	.short	.L26 - .L58end
	.short	.L32 - .L58end
	.short	.L4  - .L58end
	.short	.L4  - .L58end
	.short	.L4  - .L58end
	.short	.L4  - .L58end
	.short	.L37 - .L58end
	.short	.L38 - .L58end
	.short	.L4  - .L58end
	.short	.L4  - .L58end
	.short	.L4  - .L58end
	.short	.L43 - .L58end
	.short	.L4  - .L58end
	.short	.L4  - .L58end
	.short	.L30 - .L58end
	.short	.L4  - .L58end
	.short	.L16 - .L58end
	.short	.L44 - .L58end
	.short	.L19 - .L58end
	.short	.L4  - .L58end
	.short	.L4  - .L58end
	.short	.L4  - .L58end
	.short	.L18 - .L58end
	.short	.L50 - .L58end
	.short	.L49 - .L58end
	.short	.L4  - .L58end
	.short	.L4  - .L58end
	.short	.L4  - .L58end
	.short	.L4  - .L58end
	.short	.L4  - .L58end
	.short	.L4  - .L58end
	.short	.L21 - .L58end
	.short	.L25 - .L58end
	.short	.L13 - .L58end
	.short	.L34 - .L58end
	.short	.L35 - .L58end
	.short	.L4  - .L58end
	.short	.L4  - .L58end
	.short	.L25 - .L58end
	.short	.L4  - .L58end
	.short	.L39 - .L58end
	.short	.L40 - .L58end
	.short	.L41 - .L58end
	.short	.L42 - .L58end
	.short	.L11 - .L58end
	.short	.L4  - .L58end
	.short	.L27 - .L58end
	.short	.L4  - .L58end
	.short	.L15 - .L58end
	.short	.L4  - .L58end
	.short	.L12 - .L58end
	.short	.L45 - .L58end
	.short	.L4  - .L58end
	.short	.L48 - .L58end
	.short	.L17 - .L58end
	.short	.L51 - .L58end
                   
	.text       
	.p2align 4,,7
.L58end:


-----------------------------------------------------------
The 64 Kbyte limit is a problem. If the jump labels too spreaded
it can be possible to use the normal 32 bit version.

Also it may be possible that 8 bit are enough.

-- 
Frank Klemm



More information about the Gcc mailing list