From d776a13026dc58919c5df0c9981452bea0ef3877 Mon Sep 17 00:00:00 2001 From: Nikos Nikoleris Date: Sun, 26 May 2019 23:51:28 +0100 Subject: [PATCH] python: Add binding for the new AddrRange c++ constructor Change-Id: I5b3fb59a11d8587a753759310dd3b2748ac13a0b Signed-off-by: Nikos Nikoleris Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/19132 Reviewed-by: Daniel Carvalho Maintainer: Jason Lowe-Power Tested-by: kokoro --- src/python/m5/params.py | 67 ++++++++++++++++++++++++------------- src/python/pybind11/core.cc | 4 ++- 2 files changed, 46 insertions(+), 25 deletions(-) diff --git a/src/python/m5/params.py b/src/python/m5/params.py index 02f5e51b5..c1c6ca947 100644 --- a/src/python/m5/params.py +++ b/src/python/m5/params.py @@ -1,4 +1,4 @@ -# Copyright (c) 2012-2014, 2017, 2018 ARM Limited +# Copyright (c) 2012-2014, 2017-2019 ARM Limited # All rights reserved. # # The license below extends only to copyright in the software and shall @@ -761,6 +761,7 @@ class AddrRange(ParamValue): self.xorHighBit = 0 self.intlvBits = 0 self.intlvMatch = 0 + self.masks = [] def handle_kwargs(self, kwargs): # An address range needs to have an upper limit, specified @@ -774,15 +775,28 @@ class AddrRange(ParamValue): raise TypeError("Either end or size must be specified") # Now on to the optional bit - if 'intlvHighBit' in kwargs: - self.intlvHighBit = int(kwargs.pop('intlvHighBit')) - if 'xorHighBit' in kwargs: - self.xorHighBit = int(kwargs.pop('xorHighBit')) - if 'intlvBits' in kwargs: - self.intlvBits = int(kwargs.pop('intlvBits')) if 'intlvMatch' in kwargs: self.intlvMatch = int(kwargs.pop('intlvMatch')) + if 'masks' in kwargs: + self.masks = [ long(x) for x in list(kwargs.pop('masks')) ] + self.intlvBits = len(self.masks) + else: + if 'intlvHighBit' in kwargs: + intlv_high_bit = int(kwargs.pop('intlvHighBit')) + if 'xorHighBit' in kwargs: + xor_high_bit = int(kwargs.pop('xorHighBit')) + if 'intlvBits' in kwargs: + self.intlvBits = int(kwargs.pop('intlvBits')) + self.masks = [0] * self.intlvBits + for i in range(0, self.intlvBits): + bit1 = intlv_high_bit - i + mask = 1 << bit1 + if xor_high_bit != 0: + bit2 = xor_high_bit - i + mask |= 1 << bit2 + self.masks[self.intlvBits - i - 1] = mask + if len(args) == 0: self.start = Addr(kwargs.pop('start')) handle_kwargs(self, kwargs) @@ -808,9 +822,11 @@ class AddrRange(ParamValue): raise TypeError("Too many keywords: %s" % list(kwargs.keys())) def __str__(self): - return '%s:%s:%s:%s:%s:%s' \ - % (self.start, self.end, self.intlvHighBit, self.xorHighBit,\ - self.intlvBits, self.intlvMatch) + if len(self.masks) == 0: + return '%s:%s' % (self.start, self.end) + else: + return '%s:%s:%s:%s' % (self.start, self.end, self.intlvMatch, + ':'.join(str(m) for m in self.masks)) def size(self): # Divide the size by the size of the interleaving slice @@ -829,31 +845,35 @@ class AddrRange(ParamValue): @classmethod def cxx_ini_predecls(cls, code): code('#include ') + code('#include ') + code('#include "base/types.hh"') @classmethod def cxx_ini_parse(cls, code, src, dest, ret): - code('uint64_t _start, _end, _intlvHighBit = 0, _xorHighBit = 0;') - code('uint64_t _intlvBits = 0, _intlvMatch = 0;') + code('bool _ret = true;') + code('uint64_t _start, _end, _intlvMatch = 0;') + code('std::vector _masks;') code('char _sep;') code('std::istringstream _stream(${src});') code('_stream >> _start;') code('_stream.get(_sep);') + code('_ret = _sep == \':\';') code('_stream >> _end;') code('if (!_stream.fail() && !_stream.eof()) {') code(' _stream.get(_sep);') - code(' _stream >> _intlvHighBit;') - code(' _stream.get(_sep);') - code(' _stream >> _xorHighBit;') - code(' _stream.get(_sep);') - code(' _stream >> _intlvBits;') - code(' _stream.get(_sep);') + code(' _ret = ret && _sep == \':\';') code(' _stream >> _intlvMatch;') + code(' while (!_stream.fail() && !_stream.eof()) {') + code(' _stream.get(_sep);') + code(' _ret = ret && _sep == \':\';') + code(' Addr mask;') + code(' _stream >> mask;') + code(' _masks.push_back(mask);') + code(' }') code('}') - code('bool _ret = !_stream.fail() &&' - '_stream.eof() && _sep == \':\';') + code('_ret = _ret && !_stream.fail() && _stream.eof();') code('if (_ret)') - code(' ${dest} = AddrRange(_start, _end, _intlvHighBit, \ - _xorHighBit, _intlvBits, _intlvMatch);') + code(' ${dest} = AddrRange(_start, _end, _masks, _intlvMatch);') code('${ret} _ret;') def getValue(self): @@ -861,8 +881,7 @@ class AddrRange(ParamValue): from _m5.range import AddrRange return AddrRange(long(self.start), long(self.end), - int(self.intlvHighBit), int(self.xorHighBit), - int(self.intlvBits), int(self.intlvMatch)) + self.masks, int(self.intlvMatch)) # Boolean parameter type. Python doesn't let you subclass bool, since # it doesn't want to let you create multiple instances of True and diff --git a/src/python/pybind11/core.cc b/src/python/pybind11/core.cc index fad7a7daa..3523c0639 100644 --- a/src/python/pybind11/core.cc +++ b/src/python/pybind11/core.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited + * Copyright (c) 2017, 2019 ARM Limited * All rights reserved * * The license below extends only to copyright in the software and shall @@ -45,6 +45,7 @@ */ #include "pybind11/pybind11.h" +#include "pybind11/stl.h" #include "python/pybind11/core.hh" @@ -148,6 +149,7 @@ init_range(py::module &m_native) py::class_(m, "AddrRange") .def(py::init<>()) .def(py::init()) + .def(py::init &, uint8_t>()) .def(py::init &>()) .def(py::init()) -- 2.30.2