Skip to content

Instantly share code, notes, and snippets.

View MrSmith33's full-sized avatar

Andrey Penechko MrSmith33

View GitHub Profile
@MrSmith33
MrSmith33 / codegen.d
Created April 13, 2018 16:34
Release vs Debug build
i32 sign(i32 number)
{
i32 result;
if (number < 0) result = 0-1;
else if (number > 0) result = 1;
else result = 0;
return result;
}
// Release
@MrSmith33
MrSmith33 / .asm
Created March 9, 2018 22:51
Demonstration of if/else jump optimization (removes extra jump)
i32 sign(i32 number) {
i32 result;
if (number < 0) result = 0-1;
else if (number > 0) result = 1;
else result = 0;
return result;
}
83 F9 00 0F 8C 05 00 00 00 E9 0A 00 00 00 B8 FF
FF FF FF E9 1D 00 00 00 83 F9 00 0F 8F 05 00 00
| MODULE | push scope Module
void e() | FUNC e | insert e @ line 2 col 3
{ | BLOCK | push scope e
i32 a; | VAR i32 a | push scope Block
i32 b; | VAR i32 b | insert a @ line 4 col 4
i32 c; | VAR i32 c | insert b @ line 5 col 4
| FUNC f | insert c @ line 6 col 4
void f() { | BLOCK | insert f @ line 8 col 4
i32 a; | VAR i32 a | push scope f
i32 b; | VAR i32 b | push scope Block
@MrSmith33
MrSmith33 / main.d
Created October 10, 2017 15:03
unresolved external symbol internal. (Smaller test case)
// dmd -m64 -lib -of="lib.lib" -debug -g -w -I="./" texteditor.d
// dmd -m64 -of="app.exe" -debug -g -w -I="./" lib.lib main.d
import texteditor;
void main() {}
@MrSmith33
MrSmith33 / chunkedrange.d
Created October 10, 2017 14:52
unresolved external symbol internal
module chunkedrange;
struct ChunkedRange(T) { size_t itemsLeft; }
@MrSmith33
MrSmith33 / main.d
Created September 22, 2017 13:56
Game of life with voxelman GUI
module main;
import voxelman.graphics;
import voxelman.gui;
import voxelman.log;
import voxelman.math;
import voxelman.text.scale;
void main(string[] args)
{
Links:
http://www.sparksandflames.com/files/x86InstructionChart.html
https://defuse.ca/online-x86-assembler.htm Online [dis]assembler
http://wiki.osdev.org/X86-64_Instruction_Encoding
https://www3.nd.edu/~dthain/courses/cse40243/fall2015/intel-intro.html Introduction to X86-64 Assembly for Compiler Writers
http://www.intel.com/products/processor/manuals/ Intel manuals
http://www.x86-64.org/documentation.html amd64 ABI
Vol 1. Chapter 3.4
EAX — Accumulator for operands and results data
import std.stdio;
void main()
{
HighLevel h;
writeln(h.fun());
}
struct HighLevel
{
@MrSmith33
MrSmith33 / bench_result.md
Last active February 22, 2017 12:04
Results of EntityPlus benchmark on my datadriven lib (ECS)
i7-4510U @ 2.00 GHz
Entity Count | Iterations | Probability | EntityPlus | EntityX   |
-----------------------------------------------------------------+
    1 000    | 1 000 000  |    1 in 3   |   1484 ms  |  20959 ms |
   10 000    | 1 000 000  |    1 in 3   |  15916 ms  | 208156 ms |
   30 000    |   100 000  |    1 in 3   |   5092 ms  |  63012 ms |
  100 000    |   100 000  |    1 in 5   |  13946 ms  | 133365 ms |
   10 000    | 1 000 000  |  1 in 1000  |   5334 ms  |  16883 ms |
  100 000    | 1 000 000  |  1 in 1000  |  86312 ms  | 170271 ms |
@MrSmith33
MrSmith33 / my_jit.d
Last active February 9, 2017 18:10
Random JIT playground
module main;
import std.stdio;
void main()
{
run_from_rwx();
}
version(Posix)