Implement ALU as a template class
graudtv opened this issue · 6 comments
All ALU methods are parameterized with typename I. It may be better to extract it to ALU definition, so it will look like this:
template <typename I>
struct ALU
{
using Predicate = bool (*)( const I*);
// ...
static bool eq( const I* instr) { return instr->v_src[0] == instr->v_src[1]; }
// ...
};
instead of current implementation:
struct ALU
{
template<typename I> using Predicate = bool (*)( const I*);
// ...
template<typename I> static bool eq( const I* instr) { return instr->v_src[0] == instr->v_src[1]; }
template<typename I> /* ... */
// ...
};
ALU has to access I
internals, so we define it as a friend class:
mipt-mips/simulator/func_sim/operation.h
Lines 159 to 162 in a4f777b
If I recall correctly, C++ cannot befriend with templated class, and it prevents doing that.
But I may be wrong.
Your suggestion: https://godbolt.org/z/7h9d1a (does not work)
Current code: https://godbolt.org/z/GcP6bc (works)
It may work if investigated more accurately. I don't find it is an important change, actually.
Like that: https://godbolt.org/z/oevPso
I suppose there are simpler ways. In this case usingexecute_foo<Datapath<int>>(&instr)
instead of execute_foo<Instruction<int>>(&instr)
solves the problem.
I'll think about it more precisely although
Your return of investment would be low, a lot of mechanical work without much value.
Consider investing your time in #304, for example