Skip to content

Instantly share code, notes, and snippets.

@SingleAccretion
SingleAccretion / Questions.md
Last active September 9, 2020 19:12
On writing a game

Проект

Итак, решено создать игру. Игра - програмнное обеспечение, а потому, как и для любого другого ПО, для успешного завершения проекта необходимо обозначить цели его создания, желаемый конечный результат, обозначить план разработки и круг обязанностей участников.

Цели

Очень важно понимать - без чётко обозначенных целей проект не может существовать. Причин тому несколько:

  1. Feature creep - цели должны ограничивать вашу команду от желания добавлять то, что в общем-то не очень нужно, но было бы неплохо. Надо понимать, что сложность добавления чего-либо нового возрастает с увеличением количества строк кода (по какой функции, зависит от архитектуры - может и по экспоненте, может и по сублинейной), следовательно, добавляя что-то "не из спецификации" вы не просто задерживаете добавление запланированных вещей, но делаете это сложнее. Это абсолютно не значит что вы должны сесть и написать свою ["ECMA 333"](https://www.ecma-international.org/publications
@SingleAccretion
SingleAccretion / PreparationNotes.md
Last active December 26, 2020 20:33
Analysis preparation notes

Done

General

  • Run the analyzer with the dotnet host so that it is long path aware.

dotnet/runtime

  • Build the CLR in debug and release.
  • Build libs in debug and release, both src and ref.
  • Add TargetRefPath MSBuild property to eng\BeforeTargetFrameworkInference.targets.
@SingleAccretion
SingleAccretion / GeneratingTestsForValueNumeringCheckedOps.cs
Created March 30, 2021 21:24
Generating tests for value numering checked ops
using Microsoft.Toolkit.HighPerformance.Extensions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Numerics;
#pragma warning disable
@SingleAccretion
SingleAccretion / small-types-in-ir.md
Last active September 6, 2022 05:00
What do small types mean in RyuJit IR?

Small types in RyuJit IR

The IR, for simplicity and efficiency reasons, largely follows the IL model, where only 32 and 64 bit integers are tracked as distinct types, while integers smaller than that exist only for storage locations, and are implictly widened on load and narrowed on store.

Thus, you will not see primitive arithmetic operations of, for example, type SHORT in the IR - they only exist for INT and LONG (ignoring BYREFs).

The following is a list of IR nodes known to use small types and what semantics they have:

  1. INDs on the RHS of an assignment (and always in LIR): specify the width of the indirection. Signedness of the type determines whether the load will use sign extension or zero extension. These nodes always produce INTs.
  2. INDs on the LHS of an assigment (STOREIND in LIR): specify the width of the storage location.
@SingleAccretion
SingleAccretion / morph-opts-guide.md
Last active November 19, 2021 09:52
Guidelines for writing morph optimizations

Background

Among many other things, morph (fgMorphTree, fgMorphSmpOp, fgMorphSmpOpOptional and others) performs simple optimizing tree transformations, like turning MOD(x, 2^k) !=/== 0 into AND(x, 2^k - 1) !=/== 0. Because morphing functions are called during the optimizations phases, they have to be careful when maintaining the IR state.

Rules

  1. Trees that are marked as CSE candidates cannot be deleted from the IR and their type cannot change. Use gtIsActiveCSE_Candidate to check if any particular node can be removed. For non-trivial transforms, a full !optValnumCSE_phase guard may be more appropriate.
  2. Value numbers must be maintained (including when the tree is being retyped). If you are changing a value of a constant, you can update it via the fgUpdateConstTreeValueNumber helper method. SetVNsFromNode method can be used to quickly transfer a VN from one tree to another, for example if the root tree is being replaced with one of its children. For transforms that cannot easil
@SingleAccretion
SingleAccretion / MSBuildTargets.md
Last active September 18, 2025 19:02
MSBuild target execution algorithm in pseudocode
void ExecuteTarget(Target tgt)
{
    // Each target only runs once during an MSBuild invocation.
    if (tgt.State == Executed)
        return;

    // Note how the condition is evaluated prior to running the depended-on targets.
    if (Evaluate(tgt.Condition))
    {
@SingleAccretion
SingleAccretion / MallocProfiling.md
Last active September 7, 2025 11:21
[NativeAOT-LLVM] WASI SDK malloc profiling with stack traces

!!!WARNING!!! FOR DEMOSTRATION PURPOSES ONLY !!!WARNING!!!

The idea is to leverage the fact the linker will NOT error out with duplicate symbol definition if it doesn't need to touch the libc's dlmalloc.o.

Csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>