Skip to content

Instantly share code, notes, and snippets.

how long does it take until a 32/64 bit integer wraps when incrementing at a constant rate?

2^32:

 frequency | period | years | days    | hours     | minutes    | seconds      | milliseconds
-----------+--------+-------+---------+-----------+------------+--------------+-----------------
     1 Hz  |   1 s  | 136.1 | 49710.3 | 1193046.5 | 71582788.3 | 4294967296.0 | 4294967296000.0
    10 Hz  | 100 ms |  13.6 |  4971.0 |  119304.6 |  7158278.8 |  429496729.6 |  429496729600.0
   100 Hz  |  10 ms |   1.4 |   497.1 |   11930.5 |   715827.9 |   42949673.0 |   42949672960.0
use core::ptr::NonNull;
use core::alloc::Layout;
pub trait Alloc {
/// allocates a block of memory.
///
/// - if the call succeeds:
/// - the returned pointer refers to a live allocation.
/// - `layout` is the active layout of the returned memory block.
const SPEEEEEED: bool = 1==1;
pub mod reg {
#[derive(Clone, Copy, Debug)]
#[repr(align(4))]
pub enum Instruction {
LoadInt { dst: u8, value: i16 },
import {Layout, LayoutProps} from "@motion-canvas/2d/lib/components"
import {Rect, Vector2} from "@motion-canvas/core/lib/types";
import {initial, property} from "@motion-canvas/2d/lib/decorators"
import {all, delay, sequence, waitFor} from "@motion-canvas/core/lib/flow";
import {Signal} from "@motion-canvas/core/lib/utils";
import {drawRoundRect} from "@motion-canvas/2d/lib/utils";
import {linear} from "@motion-canvas/core/lib/tweening";
import {decorate, threadable} from "@motion-canvas/core/lib/decorators"
import {ThreadGenerator} from "@motion-canvas/core/lib/threading";
import {Layout, LayoutProps} from "@motion-canvas/2d/lib/components"
import {Rect, Vector2} from "@motion-canvas/core/lib/types";
import {property} from "@motion-canvas/2d/lib/decorators"
import {all, sequence} from "@motion-canvas/core/lib/flow";
import {Signal, SignalValue} from "@motion-canvas/core/lib/utils";
import {drawRect} from "@motion-canvas/2d/lib/utils";
import {easeOutCubic, linear} from "@motion-canvas/core/lib/tweening";
import {decorate, threadable} from "@motion-canvas/core/lib/decorators"
@leddoo
leddoo / reg_vm.rs
Created December 29, 2022 11:03
a very simple register vm
// a very minimal instruction set.
// it has just enough operations to implement a recursive
// fibonacci function - what a coincidence :D
// NOTE: in my VM, i don't use an `enum`.
// this is just for simplicity.
#[derive(Clone, Copy, Debug)]
enum Instruction {
LoadInt { dst: u8, value: i16 },
Copy { dst: u8, src: u8 },
Add { dst: u8, src1: u8, src2: u8 },