Skip to content

Instantly share code, notes, and snippets.

@kravchik
kravchik / Executor.java
Created June 20, 2012 20:26
Primitively simple lisp implementation
package simple;
import par.ParParser;
import java.util.List;
import java.util.Map;
import static yk.Util.copy;
import static yk.Util.list;
import static yk.Util.map;
package common.search;
import yk.Util;
import java.util.*;
import static yk.Util.list;
import static yk.Util.map;
public class Lift {
@kravchik
kravchik / OptimizeMatrixMultiplication.java
Last active September 9, 2016 13:53
First example of my optimizing code generator.
//Test of the automatic program optimization generator.
//Here is function multiply44 is deeply inlined and optimized.
//It uses just one call with constant parameters and it resolves to series of recursive inlines,
// constants calculations and other optimizations.
public static void set(int ww, float[] data, int row, int column, float d) {
data[(row-1) * ww + column-1] = d;
}
public static float get(int ww, float[] data, int row, int column) {
@kravchik
kravchik / O4Matrix.java
Last active September 10, 2016 07:26
Mystery of the JVM
// Round 1: unoptimized version
// why is here first cycle is too short and rest are too long?
// 1.639
// 3.333
// 3.298
// 3.289
//
// Round 2: unoptimized version (again!)
// why each cycle takes longer than first cycle of first round?
// and less than others?
@kravchik
kravchik / O4Matrix.java
Last active September 10, 2016 08:54
Unswer
// Round 1: unoptimized version
// 1.685
// 1.633
// 1.669
// 1.667
//
// Round 2: unoptimized version (again!)
// 1.684
// 1.693
// 1.668
@kravchik
kravchik / O4Vec2f.java
Created September 12, 2016 14:14
Another test of optimizer
public float getProj(O4Obj mdA, O4Obj mdB) {
return mdA.pos.sub(mdB.pos).normalized().complexDiv1(mdA.impulse).x / mdA.mass;
}
float getProjOptimized(O4Obj mdA, O4Obj mdB) {
float newVar_4_x = (mdA.pos.x - mdB.pos.x);
float newVar_4_y = (mdA.pos.y - mdB.pos.y);
float forPare_42 = STANDARD.sqrt((newVar_4_x * newVar_4_x + newVar_4_y * newVar_4_y));
float newVar_3_x = newVar_4_x / forPare_42;
float newVar_3_y = newVar_4_y / forPare_42;
public class FloatValue {
public boolean dirty = true;
public float baseValue; //before any buffs
public float value; //with all buffs
transient private YSet<FloatAffector> affectors = hs();
public void recalc() {
float mul = affectors.reduce(0f, (cur, affector) -> cur + affector.mul);
float add = affectors.reduce(0f, (cur, affector) -> cur + affector.add);
value = baseValue * mul + add;