hex.sub.init¶
This is where the sub “truth” tables are. must be called once if you want to use hex.sub (hex.init calls it).
Its 9-bits are expected to be {carry<<8 | src<<4 | dst} at the jump to it (for the src,dst hexes, and the carry bit, of the sub operation).
Its 9-bits are expected to be {new_carry<<8} after the jump to it.
Signature¶
def init @ switch__without_carry, switch__with_carry, flip_carry, clean_table_entry, end < ..tables.res > dst { ... }
Defined in hex/math.fj — lines 260–289 (view on GitHub).
Complexity¶
Time:
8 (when jumping to dst, until finished)Space:
1570
See the complexity glossary for what @, w, dw, dbit, n mean.
Requires init¶
The following must be initialised before this macro is invoked:
hex.tables.init_shared (or hex.init)
Output labels¶
This macro exposes labels into the caller’s scope via >:
dst— This variable is an 9-bit variable (in a single op, [dbit,dbit+9)).
Source¶
Click to view the macro body
def init @ switch__without_carry, switch__with_carry, flip_carry, clean_table_entry, end < ..tables.res > dst {
;end
dst: ;.switch__without_carry
pad 512
// The next lines are the subtraction flipping-tables.
// The [carry<<8 | src<<4 | dst] entry sets hex.tables.res (assumed to be 0) to (dst - src - carry) ^ dst,
// so that xoring it with dst will update it to the sub-result.
// also, it updates the carry (.dst+dbit+8) to the next carry. (subtraction's carry is also known as the borrow).
// Upon entering here, .dst was xored with the correct table-entry, and was jumped into.
switch__without_carry:
// Space Complexity / total table ops: 528.
rep(256, d) stl.wflip_macro ..tables.res+w, \
((((d&0xf)-(d>>4) )&0xf)^(d&0xf))*dw, \
(((d&0xf)-(d>>4) < 0) ? (flip_carry+d*dw) : (clean_table_entry+d*dw))
switch__with_carry:
// Space Complexity / total table ops: 528.
rep(256, d) stl.wflip_macro ..tables.res+w, \
((((d&0xf)-(d>>4)-1)&0xf)^(d&0xf))*dw, \
(((d&0xf)-(d>>4)-1 < 0) ? (clean_table_entry+d*dw) : (flip_carry+d*dw))
flip_carry:
// if got here - flip the carry; then clean the table-entry.
// in about half of the times, we'll get here.
rep(256, i) stl.fj .dst+dbit+8, clean_table_entry+i*dw
clean_table_entry:
// xors back the table-entry from .dst
..tables.clean_table_entry__table .dst
end:
}
Depends on¶
Used by¶
Example uses¶
hex.tables.init_allinhex/tables_init.fj
← Previous: hex.sub.set_carry