Wednesday, October 3, 2012

Lock-free queue benchmark

My Lock and lock-free queue benchmark in Java: https://github.com/exhu/miscalg/tree/master/lockfreej Possibly contains ABA problem, but did not show itself while tests -)

Tuesday, October 2, 2012

online compiler/disasm

http://gcc.godbolt.org/

Sunday, September 16, 2012

Android backup

http://www.android.gs/how-to-update-the-lg-optimus-one-p500-with-cyanogen-mod-9-firmware/ http://www.android.gs/download-call-logs-backup-restore-app-for-android/ http://www.android.gs/download-sms-backup-restore-app-for-android/

Friday, August 31, 2012

Defective C++ FQA

http://yosefk.com/c++fqa/defective.html

Monday, August 27, 2012

Lock-free, wait-free, hazard pointers

Articles on the topic: http://www.drdobbs.com/lock-free-data-structures-with-hazard-po/184401890 http://www.research.ibm.com/people/m/michael/ieeetpds-2004.pdf http://www.ibm.com/developerworks/java/library/j-jtp10264/

Tuesday, August 14, 2012

Useful links

http://graphics.stanford.edu/~seander/bithacks.html http://fgiesen.wordpress.com/2011/01/17/texture-tiling-and-swizzling/ http://fgiesen.wordpress.com/2009/12/13/decoding-morton-codes/

Useful geometry functions -)

void ProjectPointOnPlane(const Vector3 & p, const Plane & plane, Vector3 & projected)
{
    float d = plane.DistanceToPoint(p);
    projected = p - d*plane.n;
}


float CalcVectorAngle(const Vector2 & a, const Vector2 & b)
{
    float c = atan2f(b.y,b.x) - atan2f(a.y,a.x);

    if (c < -PI)
        c += 2.f*PI;
    else
        if (c > PI)
            c -= 2.f*PI;

    return c;
}


Saturday, July 14, 2012

Thinkpad x220

Bought Lenovo Thinkpad x220 (with core i5, tn-film display, no ips configurations where available for less than $2000), installed xubuntu. Everything works out of the box, had to tune hdd power management: hdparm -B 254 /dev/sda to extend hdd's live. Also installed hdapsd for active shock protection and tp-smapi-dkms. Really good device for work and hobby.

Friday, June 15, 2012

Nimrod macro

So finally some macro stuff in Nimrod programming language I managed to write.
import macros

when false:
    dumpTree:
        type
            PMyObj* = ref TMyObj 
            TMyObj* = object of TObject
                a, b : int

        proc newTMyObj*() : PMyObj =
            var o : PMyObj
            new(o)
            #initTMyObj(o[])
            return o    
    
#proc initTMyObj*(o : var TMyObj) = nil
    
when false:
    proc newTMyObj*() : PMyObj =
        var o : PMyObj
        new(o)
        #initTMyObj(o[])
        return o
    
    
macro objdecl(clsbase : expr) : stmt =
    result = newNimNode(nnkStmtList)#, clsbase)
    #for i in 1..clsbase.len-1:
    #echo(repr(clsbase[i]))
    let clsName = repr(clsbase[1])
    let baseName = repr(clsbase[2])
    let tname = "T" & clsName
    let pname = "P" & clsName
    echo("base = " & baseName & ", type = " & tname)
    var fields = clsbase[3][0][0] # [0] skip stmt list, [0] skip var section
    
    
    echo("fields = " & repr(fields))
    
    
    # start 'type' section
    var tsection = newNimNode(nnkTypeSection)
    result.add(tsection)
    
    block:
        # define 'type' node for Pclass * = ref Tclass
        var tnode = newNimNode(nnkTypeDef)
        tsection.add(tnode)
        
        # define type name with * operator
        var tpostf = newNimNode(nnkPostfix)
        tpostf.add(newIdentNode("*"))
        tpostf.add(newIdentNode(pname))
        tnode.add(tpostf)
        
        # don't know why but need an empty node
        tnode.add(newNimNode(nnkEmpty))
        
        # the actual type = ref
        var reft = newNimNode(nnkRefTy)
        reft.add(newIdentNode(tname))
        tnode.add(reft)
    
    
    block:
        # define 'type' node for Tclass * = object of base
        var tnode = newNimNode(nnkTypeDef)
        tsection.add(tnode)
        
        # define type name with * operator
        var tpostf = newNimNode(nnkPostfix)
        tpostf.add(newIdentNode("*"))
        tpostf.add(newIdentNode(tname))
        tnode.add(tpostf)
        
        # don't know why but need an empty node
        tnode.add(newNimNode(nnkEmpty))
        
        # the actual type = object of
        var objt = newNimNode(nnkObjectTy)
        tnode.add(objt)
        
        # needed, don't know why
        objt.add(newNimNode(nnkEmpty))
        
        var inh = newNimNode(nnkOfInherit)
        objt.add(inh)
        inh.add(newIdentNode(baseName))
        
        var recs = newNimNode(nnkRecList)
        objt.add(recs)
        
        recs.add(fields)
        
        #var identDefs = newNimNode(nnkIdentDefs)
        #recs.add(identDefs)
        
        #identDefs.add(getAST(fields))
        #for i in 0..len(fields)-1:
        #    identDefs.add(fields[i])
            
            
        # needed, don't know why
        #identDefs.add(newNimNode(nnkEmpty))
        
    
    #echo(fields.len)
    echo(treeRepr(tsection))
    #echo(repr(tsection))
    
    
    
    
    
    #tnode.add(new
    
    
template declClass(clsName : expr, baseCls : expr, fields : stmt) : stmt = 
    
    
    objdecl(clsName, baseCls, fields)
    when false:
        #`P clsName`* = ref `T clsName`
        #`T clsName`* = object of baseCls
        #    putfields

    proc `new clsName`() : `P clsName` =
        var o : `P clsName`
        new(o)
        return o
        
    
        
# ----- the usage:
    
 
declClass MyTempClass, TObject:
    var x, y : int
    

      
var o = newMyTempClass()
o.x = 3
echo("x,y = " & $o.x & " " & $o.y)

Wednesday, May 23, 2012

Nimrod programming language

Very interesting language, spotted when looking for Vala (generates C code) -)

http://nimrod-code.org/index.html

Tuesday, May 22, 2012

Java image editor

With sources for filters etc.

http://www.jhlabs.com/ie/

Monday, May 14, 2012

Dangerous C++ preprocessor

It took me three weeks to find this mistake in a huge code base. Program suddenly crashes after the changes  that look obviously innocent. And the root of all evil was not memory leaks or so but the #ifdef.

header.h

struct mystruct : somebasestruct {
   mystruct();

#ifdef FEATURE_X

int somefield;

#endif

};


module1.cpp

#include ....
#include "header.h"

sizeof(mystruct) = 8

module2.cpp

#include ....
#include "header.h"

sizeof(mystruct) = 4



And guess why? Yes, check building settings, what is defined or not...

Tuesday, March 20, 2012

Collision detection, 2d physics

http://gdlinks.hut.ru/cdfaq/
http://www.wildbunny.co.uk/blog/2011/04/20/collision-detection-for-dummies/
http://www.wildbunny.co.uk/blog/2011/05/12/how-to-make-angry-birds-part-1/

Monday, March 5, 2012

Panasonic HM-TA2

Absolutely love this mini camcorder! Although there are no manual settings you can adjust except for video resolution (fullhd, 720p25, iFrame) and turn on/off LED light.

iFrame mode produces big files suitable for editing with maximum quality.

I use 720p mode and the video is really awsome clear and detailed when outdoors. Stereo sound quality is also way better than any smartphone's.

I'll publish sample video as soon as something interesting gets into sight.

Saturday, February 11, 2012

C++ vs FPC vs Java vs C# benchmarking

There were a lot of microbenchmarks etc. in the net to prove which solution is better -- Java or .NET, yet I decided to write a simple yet useful program (An image processing tool we use in developing games for OpenGL ES devices) and port it to several languages. I've put it into a public repo under

https://github.com/exhu/alimg

My results were so that the fastest solution under Linux was in Java (7 secs), then C++  and FreePascal (11-10 secs average). Yes, C++ slower here, of course you can optimize C++ into unreadable code and get most of the hardware, but the code will be unmaintainable and cryptic, while now it's a balanced solution, and still Java sources are the most user-friendly.

Mono was 4 times slower than Java under Linux (28-30 secs), and .NET was as fast as Java under Windows XP 32-bit under VirtualBox (both do the job for about 17 secs), yet the FreePascal version was even faster than both of them (10 secs -- about the same speed in the VirtualBox as on the real Linux).


Linux:
1) Java (OpenJDK 6)
2) C++, FPC
4) Mono

Windows (under Linux VirtualBox):
1) FPC
2) Java (Oracle Java 6), .NET 4

Assume C++ version would be the fastest under Windows too.

I also need to note that .NET 4 offline installation was rather hard to complete under Windows XP 32-bit SP2, it required several downloads for Windows Installer, Windows Imaging and took 20 minutes to install. Meanwhile Java offline installer (~20 megs) was easy and fast and did not require restarting the OS.


To sum up I would pick FPC for native small to medium applications and Java for cross-platform medium to complex applications. Although Java is surprisingly fast on netbooks it's too memory hungry.

Thursday, January 26, 2012

HDD power off disable for HP 6510b

 sudo hdparm -B 254 /dev/sda

That prevents drive parking at sec interval when running on battery.

Tuesday, January 3, 2012

OpenGL tutorials

http://ogldev.atspace.co.uk/index.html

http://www.arcsynthesis.org/gltut/index.html  -- book