Skip to content

Implement ALU as a template class #1410

Closed
graudtv opened this issue Nov 17, 2020 · 6 comments
Closed

Implement ALU as a template class #1410

graudtv opened this issue Nov 17, 2020 · 6 comments
Assignees
Labels
1 Usually one-liner tasks, but may require some deep into infrastructure. code Enhances infrastructure or refines, Requires almost no knowledge in CPU microarchitecture. good first issue Good task to start with MIPT-MIPS development S1 — C++ To solve the issue, you barely need knowledge about CPU microarchitecture, just C++ coding.

Comments

@graudtv
Copy link
Contributor

graudtv commented Nov 17, 2020

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> /* ... */
    // ...
};
@pavelkryukov
Copy link
Member

ALU has to access I internals, so we define it as a friend class:

public:
friend struct ALU;
friend struct RISCVMultALU;
friend struct MIPSMultALU;

If I recall correctly, C++ cannot befriend with templated class, and it prevents doing that.
But I may be wrong.

@pavelkryukov
Copy link
Member

Your suggestion: https://godbolt.org/z/7h9d1a (does not work)
Current code: https://godbolt.org/z/GcP6bc (works)

@pavelkryukov pavelkryukov added 1 Usually one-liner tasks, but may require some deep into infrastructure. code Enhances infrastructure or refines, Requires almost no knowledge in CPU microarchitecture. S1 — C++ To solve the issue, you barely need knowledge about CPU microarchitecture, just C++ coding. good first issue Good task to start with MIPT-MIPS development labels Nov 17, 2020
@pavelkryukov
Copy link
Member

pavelkryukov commented Nov 17, 2020

It may work if investigated more accurately. I don't find it is an important change, actually.

@pavelkryukov
Copy link
Member

Like that: https://godbolt.org/z/oevPso

@graudtv
Copy link
Contributor Author

graudtv commented Nov 17, 2020

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

@graudtv graudtv self-assigned this Nov 17, 2020
@pavelkryukov
Copy link
Member

Your return of investment would be low, a lot of mechanical work without much value.
Consider investing your time in #304, for example

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 Usually one-liner tasks, but may require some deep into infrastructure. code Enhances infrastructure or refines, Requires almost no knowledge in CPU microarchitecture. good first issue Good task to start with MIPT-MIPS development S1 — C++ To solve the issue, you barely need knowledge about CPU microarchitecture, just C++ coding.
Projects
None yet
Development

No branches or pull requests

2 participants