Hello everybody. I was thinking the other day that it might be a good  
idea to templatize readMiscReg and setMiscReg. I don't have the idea  
fleshed out all the way, but I thought it would be a good idea to send  
an email to before I forgot about it.

When we access control registers, my impression is that we almost  
always know which one we want. There are some exceptions where things  
are accessed in a loop, but usually there's a specific place where we  
need a specific register for a specific purpose. What happens, though,  
is that we call a function that handles -all- registers, and it has to  
switch on a parameter to redetermine what we wanted to do. If we  
called a specific function for, say, reading CR0, we'd skip the  
overhead of the switch statement. We'd also make the functions that  
set/read those registers shorter and more managable.

In x86, I use bitunion types to split out the bitfields of a register.  
Because of that, basically each of the control registers already has a  
type that corresponds to it specifically. There are some exceptions  
where the same type is used for more than one register, but I don't  
think that's the common case. That type could be used as the template  
parameter to the read/set functions which would cause template  
instantiations all the way back into the isa object.

Once there, template specialization would let you define a function  
that reads/sets just CR0, and the type system and C++ would plop it  
into place at the right place and time while still respecting  
interfaces. It might even be inlinable. The regular version that takes  
an index would still be available. I'm not quite sure how to fold it  
into the templated version of that function since the index is  
explicit, but since it's likely going to be (and probably should  
normally be) a MiscReg, that might work out.

Gabe
_______________________________________________
m5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/m5-dev

Reply via email to