-4
The task is simple: Create an if-statement from scratch in x86 assembly that runs in as few clock-cycles as possible.
- Must be x86 assembly.
- Can't use any of the conditional jump/branch instructions (e.g.
je,jne,jz,jg,jge,jl,jle). - Can use
jmpto jump to existing blocks of code. - Can use
cmpif necessary. - Can't call any external libraries or functions.
- Can't use
call. - Free to use any of the other available instructions in the Intel docs.
- No C.
- Any of the ~7 Intel Core architectures are acceptable (listed on page 10). Ideally Nehalem (Intel Core i7).
- The
ifstatement needs to check arbitrary conditions. Basically replicating the functionality of any one of theje,jge, etc. conditional jumps.
The winning answer is one that uses the fewest clock cycles possible. That is, it can have the most operations per second. Approximate clock cycle summaries are here: http://www.agner.org/optimize/instruction_tables.pdf. Calculating clock cycles can happen after the answer is posted.
2, [tag:fastest-algorithm] is about asymptotic complexity, which can't apply here because everything is O(1). – user202729 – 2018-07-06T02:01:49.777
Now... what exactly does "equivalent to an
if-statement" mean? Would something likejmp [eax]be ok? – user202729 – 2018-07-06T02:59:51.783The
ifstatement needs to check arbitrary conditions. Basically replicating the functionality of any one of theje,jge, etc. conditional jumps. – Lance Pollard – 2018-07-06T03:05:08.657