Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment with branchless logic #49

Open
fengb opened this issue May 14, 2020 · 1 comment
Open

Experiment with branchless logic #49

fengb opened this issue May 14, 2020 · 1 comment

Comments

@fengb
Copy link
Owner

fengb commented May 14, 2020

https://stackoverflow.com/a/5432624

This is leveraging modern CPU designs:

  • Branch misses are extremely costly, so no branches!
  • CPUs have multiple logical units, so let's maximize parallelism
  • Finally select the correct branch at the very end

We will need a strong microp architecture:

  • Reads / writes must be linear offsets — MMU and registers must be siblings
  • Writes must be u8 only — u16 needs to convert to 2x u8 microps
  • Flag changes could be represented as 2x masks
  • What about special logic?
    • jump / ret / call / rst
    • EI / DI
    • HALT / STOP
@fengb
Copy link
Owner Author

fengb commented May 14, 2020

const Offset = magic_numbers(u17) {
    0x0_0000: null,
    0x0_100*: temp, // first microp can store here and be consumed by the second
    0x1_FFF*: registers,
    0x1_****: mmu,
};

const Microp = struct {
    id: enum { add, sub, cp },
    dst: Offset,
    args: [2]Offset,
};

const Op = struct {
    code: u8,
    length: u8,
    durations: [2]u8,
    id: Id,
    microps: [2]Microp,
    flag: enum{}
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant