You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/technical.rst
+20-5Lines changed: 20 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -232,14 +232,23 @@ Some notes and references into the compiler's source code modules:
232
232
233
233
Run-time memory profiling with the X16 emulator
234
234
-----------------------------------------------
235
+
236
+
The compiler has the ``-dumpvars`` switch that will print a list of all variables and where they are placed into memory.
237
+
This can be useful to track which variables end up in zeropage for instance. But it doesn't really show if the choices
238
+
made are good, i.e. if the variables that are actually the most used in your program, are placed in zeropage.
239
+
240
+
But there is a way to actually *measure* the behavior of your program as it runs on the X16.
241
+
See it as a simple way of *profiling* your program to find the hotspots that maybe need optimizing:
242
+
235
243
The X16 emulator has a ``-memorystats`` option that enables it to keep track of memory access count statistics,
236
244
and write the accumulated counts to a file on exit.
237
-
Prog8 includes a Python script ``profiler.py`` (find it in the "scripts" subdirectory of the source code distribution)
238
-
that can cross-reference that file with an assembly listing produced by the compiler with the ``-asmlist`` option.
245
+
Prog8 then provides a Python script ``profiler.py`` (find it in the "scripts" subdirectory of the source code distribution,
246
+
or `online here <https://github.com/irmen/prog8/blob/master/scripts/profiler.py>`_).
247
+
This script cross-references the memory stats file with an assembly listing of the program, produced by the Prog8 compiler with the ``-asmlist`` option.
239
248
It then prints the top N lines in your (assembly) program source that perform the most reads and writes,
240
249
which you can use to identify possible hot spots/bottlenecks/variables that should be better placed in zeropage etc.
241
-
Note that the profiler just works with the number of accesses to memory locations, this is *not* the same
242
-
as the most run-time (cpu instructions cycle times aren't taken into account at all).
250
+
Note that the profiler simply works with the total number of accesses to memory locations.
251
+
This is *not* the same as the most run-time (cpu instructions cycle times aren't taken into account at all)!
@@ -274,4 +283,10 @@ Here is an example of the output it generates::
274
283
$01e7 (1280140) : cpu stack
275
284
$0264 (1258159) : unknown
276
285
277
-
Apparently the most cpu activity while running this program is spent in a division routine.
286
+
Apparently the most cpu activity while running this program is spent in a division routine which uses the 'remainder' and 'dividend' variables.
287
+
As you can see, sometimes even actual assembly instructions end up in the tables above if they are in a routine that is executed very often (the 'stz' instructions in this example).
288
+
The tool isn't powerful enough to see what routine the variables or instructions are part of, but it prints the line number in the assembly listing file so you can investigate that manually.
289
+
290
+
You can see in the example above that the variables that are among the most used are neatly placed in zeropage already.
291
+
If you see for instance a variable that is heavily used and that is *not* in zeropage, you
292
+
could consider adding ``@zp`` to that variable's declaration to prioritize it to be put into zeropage.
Copy file name to clipboardExpand all lines: docs/source/todo.rst
+1-2Lines changed: 1 addition & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,6 @@
1
1
TODO
2
2
====
3
3
4
-
- write something in the docs about how to optimize your program on the x16 using the -dumpvars option,
5
-
the emulator's memory profiler + the profiler.py script to find hotspots for routines and variables that could be placed into zeropage
6
4
- announce prog8 on the 6502.org site?
7
5
8
6
...
@@ -24,6 +22,7 @@ Future Things and Ideas
24
22
But all library code written in asm uses .proc already..... (textual search/replace when writing the actual asm?)
25
23
Once new codegen is written that is based on the IR, this point is mostly moot anyway as that will have its own dead code removal on the IR level.
26
24
25
+
- Allow normal subroutines to return multiple values as well (just as asmsubs already can)
27
26
- Change scoping rules for qualified symbols so that they don't always start from the root but behave like other programming languages (look in local scope first)
28
27
- Fix missing cases where regular & has to return the start of the split array in memory whatever byte comes first. Search TODO("address of split word array")
29
28
- something to reduce the need to use fully qualified names all the time. 'with' ? Or 'using <prefix>'?
0 commit comments