File: popcount.asm

package info (click to toggle)
gcl 2.6.7%2Bdfsga-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 84,796 kB
  • sloc: ansic: 452,686; lisp: 156,133; asm: 111,405; sh: 29,299; cpp: 18,599; perl: 5,602; makefile: 5,201; tcl: 3,181; sed: 469; yacc: 378; lex: 174; fortran: 48; awk: 30; csh: 23
file content (123 lines) | stat: -rw-r--r-- 2,492 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
dnl  Intel P5 mpn_popcount -- mpn bit population count.

dnl  Copyright 2001, 2002 Free Software Foundation, Inc.
dnl
dnl  This file is part of the GNU MP Library.
dnl
dnl  The GNU MP Library is free software; you can redistribute it and/or
dnl  modify it under the terms of the GNU Lesser General Public License as
dnl  published by the Free Software Foundation; either version 3 of the
dnl  License, or (at your option) any later version.
dnl
dnl  The GNU MP Library is distributed in the hope that it will be useful,
dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
dnl  Lesser General Public License for more details.
dnl
dnl  You should have received a copy of the GNU Lesser General Public License
dnl  along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.

include(`../config.m4')


C P5: 8.0 cycles/limb


C unsigned long mpn_popcount (mp_srcptr src, mp_size_t size);
C
C An arithmetic approach has been found to be slower than the table lookup,
C due to needing too many instructions.

C The slightly strange quoting here helps the renaming done by tune/many.pl.
deflit(TABLE_NAME,
m4_assert_defined(`GSYM_PREFIX')
GSYM_PREFIX`'mpn_popcount``'_table')

	RODATA
	ALIGN(8)
	GLOBL	TABLE_NAME
TABLE_NAME:
forloop(i,0,255,
`	.byte	m4_popcount(i)
')

defframe(PARAM_SIZE,8)
defframe(PARAM_SRC, 4)

	TEXT
	ALIGN(8)

PROLOGUE(mpn_popcount)
deflit(`FRAME',0)

	movl	PARAM_SIZE, %ecx
	pushl	%esi	FRAME_pushl()

ifdef(`PIC',`
	pushl	%ebx	FRAME_pushl()
	pushl	%ebp	FRAME_pushl()

	call	L(here)
L(here):
	popl	%ebp
	shll	%ecx		C size in byte pairs

	addl	$_GLOBAL_OFFSET_TABLE_+[.-L(here)], %ebp
	movl	PARAM_SRC, %esi

	xorl	%eax, %eax	C total
	xorl	%ebx, %ebx	C byte

	movl	TABLE_NAME@GOT(%ebp), %ebp
	xorl	%edx, %edx	C byte
define(TABLE,`(%ebp,$1)')
',`
dnl non-PIC
	shll	%ecx		C size in byte pairs
	movl	PARAM_SRC, %esi

	pushl	%ebx	FRAME_pushl()
	xorl	%eax, %eax	C total

	xorl	%ebx, %ebx	C byte
	xorl	%edx, %edx	C byte

define(TABLE,`TABLE_NAME`'($1)')
')


	ALIGN(8)	C necessary on P55 for claimed speed
L(top):
	C eax	total
	C ebx	byte
	C ecx	counter, 2*size to 2
	C edx	byte
	C esi	src
	C edi
	C ebp	[PIC] table

	addl	%ebx, %eax
	movb	-1(%esi,%ecx,2), %bl

	addl	%edx, %eax
	movb	-2(%esi,%ecx,2), %dl

	movb	TABLE(%ebx), %bl
	decl	%ecx

	movb	TABLE(%edx), %dl
	jnz	L(top)


ifdef(`PIC',`
	popl	%ebp
')
	addl	%ebx, %eax
	popl	%ebx

	addl	%edx, %eax
	popl	%esi

	ret

EPILOGUE()