Dnia 2015-01-18, o godz. 21:44:05
Michał Górny <mgo...@gentoo.org> napisał(a):

> Hello,
> 
> I would like to commit the following flags as cpu_flags_x86_desc.
> The list combines global USE flags with some local USE flags I've been
> able to find.

Following your suggestions, I'm attaching three files:

1. updated cpu_flags_x86.desc, with:

 a. fma3/fma4 distinction,

 b. aes-ni renamed to aes for consistency with cpuinfo, we no longer
 have to worry about USE flag collision with other USE=aes uses,

 c. complete and machine-parseable listing of cpuinfo flags.

2. cpuinfo2cpuflags-x86.py script that parses cpu_flags_x86.desc
and /proc/cpuinfo and generates a nice CPU_FLAGS_X86 value for you. We
need to decide where to put it (scripts/?).

3. Initial text of the news item for review.

-- 
Best regards,
Michał Górny

Attachment: cpu_flags_x86.desc
Description: Binary data

#!/usr/bin/env python

import collections, errno, os, os.path, re, sys

def main(*argv):
	if 'PORTDIR' in os.environ:
		portdir = os.environ['PORTDIR']
	else:
		try:
			import portage
		except ImportError:
			return 'Unable to determine PORTDIR, please set it before calling this script'
		else:
			trees = portage.create_trees(
					config_root = os.environ.get('PORTAGE_CONFIGROOT'),
					target_root = os.environ.get('ROOT'))
			tree = trees[max(trees)]
			portdir = tree['porttree'].dbapi.repositories.get_location_for_name('gentoo')

	# dict of cpuinfo -> flag mappings
	flag_dict = collections.defaultdict(list)

	desc = os.path.join(portdir, 'profiles', 'desc', 'cpu_flags_x86.desc')
	# flag - description ; discards empty lines and comments
	l_regexp = re.compile(r'^(?P<flag>[a-z0-9_]+)\s+-\s+(?P<desc>.+)$')
	# [cpuinfo-flag] ; [] are discarded for easy use
	cpuinfo_regexp = re.compile(r'(?<=\[).+?(?=\])')
	try:
		with open(desc, 'r') as f:
			for l in f:
				m = l_regexp.match(l)
				if m:
					# grep for any [cpuinfo] or [cpuinfo2]
					flags = cpuinfo_regexp.findall(l)
					for fl in flags:
						flag_dict[fl].append(m.group('flag'))
					# fallback to exact flag match
					if not flags:
						flag_dict[m.group('flag')].append(m.group('flag'))
	except OSError as e:
		if e.errno == errno.ENOENT:
			return '%s does not exist, set PORTDIR to correct gentoo repository location' % desc

	out = set()

	flags_regexp = re.compile(r'^flags\s+:\s+(?P<flags>.*)$')
	with open('/proc/cpuinfo', 'r') as f:
		for l in f:
			m = flags_regexp.match(l)
			if m:
				for fl in m.group('flags').split():
					if fl in flag_dict:
						out.update(flag_dict[fl])
				break

	print('CPU_FLAGS_X86="%s"' % ' '.join(sorted(out)))
	return 0

if __name__ == '__main__':
	sys.exit(main(*sys.argv[1:]))
Title: CPU_FLAGS_X86 introduction
Author: Michał Górny <mgo...@gentoo.org>
Content-Type: text/plain
Posted: 2015-01-xx
Revision: 1
News-Item-Format: 1.0
Display-If-Keyword: amd64 ~amd64 x86 ~x86

The USE flags corresponding to intruction sets and other features
specific to the x86 architecture are being moved into a separate USE
flag group called CPU_FLAGS_X86.

In order not to lose CPU-specific optimizations, users will be required
to update their make.conf (and package.use) file. For example, if
the following USE flags were present:

  USE="mmx mmxext sse sse2 sse3"

Those flags need to be copied into:

  CPU_FLAGS_X86="mmx mmxext sse sse2 sse3"

When in doubt, consult profiles/desc/cpu_flags_x86.desc. Most of
the flag names match /proc/cpuinfo names, with the notable exception
of SSE3 which is called 'pni' in /proc/cpuinfo (and which isn't the same
as SSSE3).

To help you enable correct USE flags, you can use the
cpuinfo2cpuflags-x86.py script provided in scripts/ directory of the
repository. It will parse your /proc/cpuinfo and print an accurate
CPU_FLAGS_X86 value for it.

Attachment: pgpIPsI4I4KEW.pgp
Description: OpenPGP digital signature

Reply via email to