Skip to content

Commit

Permalink
Sloppy mod and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pubby committed Jun 27, 2023
1 parent 48c698b commit 1afc938
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
21 changes: 20 additions & 1 deletion doc/doc.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,21 @@ pause = 1
To make NESFab always pause on Microsoft Windows, first create a shortcut to the NESFab executable.
Then, in the shortcut's properties, put `--pause` after the target path.

=== `sloppy`

This option improves compilation speed at the cost of program optimization.
It can be disabled on a per-function basis with the modifier <<mod_flags, `-sloppy`>>.

*Command-line usage:*
----
nesfab --sloppy
----

*Configuration file usage:*
----
sloppy = 1
----

== Supported Mappers [[mappers]]

NESFab supports a small set of https://www.nesdev.org/wiki/Mapper[mappers],
Expand Down Expand Up @@ -2600,6 +2615,7 @@ Unlike other programming languages, functions in NESFab cannot be nested or recu
- <<mod_flags, `+graphviz`>>
- <<mod_flags, `+info`>>
- <<mod_flags, `+static`>>
- <<mod_flags, `+sloppy`, `-sloppy`>>

Example:
----
Expand Down Expand Up @@ -2700,6 +2716,7 @@ While the mode function is executing, NMIs will be handled using the supplied `n
- <<mod_flags, `+graphviz`>>
- <<mod_flags, `+info`>>
- <<mod_flags, `+static`>>
- <<mod_flags, `+sloppy`, `-sloppy`>>

Example:
----
Expand Down Expand Up @@ -2773,6 +2790,7 @@ nmi identifier()
- <<mod_flags, `+graphviz`>>
- <<mod_flags, `+info`>>
- <<mod_flags, `+static`>>
- <<mod_flags, `+sloppy`, `-sloppy`>>

*Why do NMI interrupt functions exist?*

Expand Down Expand Up @@ -2834,6 +2852,7 @@ irq identifier()
- <<mod_flags, `+graphviz`>>
- <<mod_flags, `+info`>>
- <<mod_flags, `+static`>>
- <<mod_flags, `+sloppy`, `-sloppy`>>

=== `asm` [[kw_asm]]

Expand Down Expand Up @@ -2879,7 +2898,6 @@ asm fn waste_time()
- <<mod_data>>.
- <<mod_vars>>.
- <<mod_flags, `+zero_page`, `-zero_page`>>
- <<mod_flags, `+graphviz`>>
- <<mod_flags, `+info`>>

The labels of an `asm` function are visible using the <<member_access, `.` operator>>.
Expand Down Expand Up @@ -3668,6 +3686,7 @@ The following flags exist:
You must validate this yourself.
- `palette_3`: Converts 4-byte palettes into 3-byte palettes.
- `palette_25`: Converts 32-byte palettes into 25-byte palettes.
- `+sloppy`, `-sloppy`: Enables / disables faster compilation speed, at the cost of performance.

Example:
----
Expand Down
2 changes: 1 addition & 1 deletion src/cg_isel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4811,7 +4811,7 @@ std::size_t select_instructions(log_t* log, fn_t& fn, ir_t& ir)
static TLS rh::batman_map<cross_transition_t, result_t> rebuilt;
static TLS std::vector<rh::apair<cross_cpu_t, isel_cost_t>> new_out_states;

bool const sloppy = compiler_options().sloppy;
bool const sloppy = fn.sloppy();
unsigned const BASE_SEL_SIZE = sloppy ? 4 : 32;
unsigned const BASE_MAP_SIZE = sloppy ? 8 : 128;
auto const SELS_COST_BOUND = sloppy ? cost_fn(NOP_IMPLIED) : cost_fn(LDA_ABSOLUTE) * 2;
Expand Down
5 changes: 4 additions & 1 deletion src/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,9 @@ fn_t::fn_t(global_t& global, type_t type, fn_def_t&& fn_def, std::unique_ptr<mod
case FN_NMI: m_pimpl.reset(new nmi_impl_t()); break;
case FN_IRQ: m_pimpl.reset(new irq_impl_t()); break;
}

m_sloppy = compiler_options().sloppy || mod_test(this->mods(), MOD_sloppy);
m_sloppy &= !mod_test(this->mods(), MOD_sloppy, false);
}

fn_ht fn_t::mode_nmi() const
Expand Down Expand Up @@ -1189,7 +1192,7 @@ void fn_t::compile()
} while(false)

unsigned iter = 0;
unsigned const MAX_ITER = compiler_options().sloppy ? 10 : 100;
unsigned const MAX_ITER = sloppy() ? 10 : 100;
bool changed;

// Do this first, to reduce the size of the IR:
Expand Down
4 changes: 4 additions & 0 deletions src/globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ friend class global_t;
unsigned irq_index() const;
xbitset_t<fn_ht> const& irq_used_in_modes() const;

bool sloppy() const { return m_sloppy; }

precheck_tracked_t const& precheck_tracked() const { assert(m_precheck_tracked); return *m_precheck_tracked; }
auto const& precheck_group_vars() const { assert(m_precheck_group_vars); return m_precheck_group_vars; }
auto const& precheck_parent_modes() const {assert(compiler_phase() > PHASE_PRECHECK); return m_precheck_parent_modes; }
Expand Down Expand Up @@ -518,6 +520,8 @@ friend class global_t;
bool m_precheck_wait_nmi = false;
bool m_precheck_fences = false;

bool m_sloppy = false;

// Bitsets of all global vars read/written in fn (deep)
// These get assigned by 'calc_reads_writes_purity'.
// The thread synchronization is implicit in the order of compilation.
Expand Down
1 change: 1 addition & 0 deletions src/mods.inc
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ MOD(7, static)
MOD(8, palette_3)
MOD(9, palette_25)
MOD(10, sram)
MOD(11, sloppy)
8 changes: 4 additions & 4 deletions src/pass1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ class pass1_t
{
default: return 0;
case FN_CT: return 0;
case FN_FN: return MOD_zero_page | MOD_align | MOD_inline | MOD_graphviz | MOD_static | MOD_info;
case FN_MODE: return MOD_zero_page | MOD_align | MOD_graphviz | MOD_static | MOD_info;
case FN_NMI: return MOD_zero_page | MOD_align | MOD_graphviz | MOD_static | MOD_info;
case FN_IRQ: return MOD_zero_page | MOD_align | MOD_graphviz | MOD_static | MOD_info;
case FN_FN: return MOD_zero_page | MOD_align | MOD_inline | MOD_graphviz | MOD_static | MOD_info | MOD_sloppy;
case FN_MODE: return MOD_zero_page | MOD_align | MOD_graphviz | MOD_static | MOD_info | MOD_sloppy;
case FN_NMI: return MOD_zero_page | MOD_align | MOD_graphviz | MOD_static | MOD_info | MOD_sloppy;
case FN_IRQ: return MOD_zero_page | MOD_align | MOD_graphviz | MOD_static | MOD_info | MOD_sloppy;
}
}

Expand Down

0 comments on commit 1afc938

Please sign in to comment.