Function code size
Advice from programmer Rika.
Pascal function binary size can be measured (to within the procedure entry alignment... usually 16 bytes) with:
procedure MyProc;
begin
// ...
end;
// Must immediately follow MyProc in the source!
// Uses the implementation detail that the linker will lay them out in the same order (which is not guaranteed by any linker, so this may not work).
procedure MyProcEnd;
begin
end;
begin
writeln('MyProc code size: ', pointer(@MyProcEnd) - pointer(@MyProc), ' b');
end.For assembler routines, either do the same but make MyProcEnd assembler too (still not sure if it works, I use the method below... but it definitely doesn’t work when mixing Pascal and assembler procedures). Or do the following (finer and more future-compatible way that sadly does not compile with Pascal routines):
label MyAsmProcEnd;
procedure MyAsmProc; assembler;
asm// ...
// ...
MyAsmProcEnd:
END;
begin
writeln('MyAsmProc code size: ', pointer(@MyAsmProcEnd) - pointer(@MyAsmProc), ' b');
end.This method misses the epilogue size, but the epilogue is negligible (1-digit) and constant; and if you have X bytes, after adding 17 more bytes of instructions you will have exactly X + 17.
From the Free Pascal wiki, page "Function code size", as it stood on 2023-09-17 after a change by Jonas, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.