Skip to content

Instantly share code, notes, and snippets.

View xacrimon's full-sized avatar

Joel Wejdenstål xacrimon

View GitHub Profile
local format, insert, remove, concat, sort = string.format, table.insert, table.remove, table.concat, table.sort
local floor = math.floor
-- Vec2 "class": every arithmetic op allocates a fresh table.
local Vec2 = {}
Vec2.__index = Vec2
function Vec2.new(x, y) return setmetatable({x = x, y = y}, Vec2) end
function Vec2:add(o) return Vec2.new(self.x + o.x, self.y + o.y) end
function Vec2:sub(o) return Vec2.new(self.x - o.x, self.y - o.y) end
function Vec2:scale(s) return Vec2.new(self.x * s, self.y * s) end
-- "Typical" Lua benchmark: a small particle simulation written the way game
-- scripts usually are. Deliberately exercises what the numeric benches don't:
-- metatable method dispatch, per-call table allocation (GC churn), closures
-- with mutable upvalues, pairs/ipairs, dynamic string hash keys, and the
-- Lua<->native boundary (string.format, table.insert/remove/concat/sort).
local format, insert, remove, concat, sort = string.format, table.insert, table.remove, table.concat, table.sort
local floor = math.floor
-- Vec2 "class": every arithmetic op allocates a fresh table.
-- The Great Computer Language Shootout
-- http://shootout.alioth.debian.org/
-- contributed by Isaac Gouy, tuned by Mike Pall
local sqrt = math.sqrt
local PI = 3.141592653589793
local SOLAR_MASS = 4 * PI * PI
local DAYS_PER_YEAR = 365.24
tcvm::vm::interp::invoke_native:
Lfunc_begin754:
sub sp, sp, #192
stp x28, x27, [sp, #96]
stp x26, x25, [sp, #112]
stp x24, x23, [sp, #128]
stp x22, x21, [sp, #144]
stp x20, x19, [sp, #160]
stp x29, x30, [sp, #176]
add x29, sp, #176
select! {
_ = int1.tick() => println!("one"),
_ = int2.tick() => println!("two"),
}
// Recursive expansion of select! macro
// =====================================
{
#[doc(hidden)]
macro_rules! opcode {
(
$(#[$attr:meta])*
$name:ident { $($init:ident = $iv:expr),* $(,)? };
$($fields:tt)*
) => {
$(#[$attr])*
#[derive(Debug, Clone, Copy)]
pub struct $name(sys::Sqe);
-- no-transaction
--
-- This file must contain exactly one statement. sqlx sends a migration as a
-- single simple query, and a multi statement simple query runs inside an
-- implicit transaction block, where the COMMIT below is rejected. Settings are
-- applied with set_config for the same reason.
DO $$
DECLARE
batch_size constant bigint := 20000;
int4_max constant bigint := 2147483647;
-- no-transaction
--
-- This file must contain exactly one statement. sqlx sends a migration as a
-- single simple query, and a multi statement simple query runs inside an
-- implicit transaction block, where the COMMIT below is rejected. Settings are
-- applied with set_config for the same reason.
DO $$
DECLARE
batch_size constant bigint := 20000;
; --- prologue ---
0: push rbx
1: push rbp
2: push r12 ; only 3 callee-saved regs needed this time
4: mov r8, rsi ; r8 = frame base
7: mov r9, [r8] ; r9 = x
a: mov r10d, 0x2 ; i = 2
10: mov r11d, 0x1
16: mov rax, r9
19: sub rax, r11 ; rax = x - 1 (loop limit)
asm
; ── prologue ─────────────────────────────────────────────────────────
00: stp x29, x30, [sp, #-0x10]! ; save FP/LR
04: mov x29, sp
08: sub sp, sp, #0x10 ; one spill slot
0c: mov x9, x1 ; x9 = frame base
10: str x9, [sp] ; spill base to [sp] (reloaded before every slot access)
; ── for-loop setup: i = 2, limit = x-1, step = 1 ──────────────────
14: ldr x9, [sp]