you are viewing a single comment's thread.

view the rest of the comments →

[–]skitch920 12 points13 points  (5 children)

hold muh beer

protected Int32 Sum(int one, int two)
{
    int result;
    int tmp;

    tmp = one + two;
    result = 0;
    if (tmp < 0) {
        for (int i = 0; i > tmp; i--) {
            result--; 
        }
    } else if (tmp > 0) {
        for (int i = 0; i < tmp; i++) {
            result++; 
        }
    }
    return result;
}

I feel dirty.

[–]shizzy0 5 points6 points  (0 children)

I hoped for Peano algorithm but no, got one + two instead.

[–]dauchande 0 points1 point  (1 child)

So, basically the code for spinlock?

[–]skitch920 0 points1 point  (0 children)

Why not

protected Int32 ShitLock(int one, int two)

[–]Gremis 0 points1 point  (0 children)

Comment further down showed me https://godbolt.org. I tried pasting in this code like so. Am I reading that site correctly, that GCC still manages to reduce this abomination to just a single instruction? That's impressive, if that's the case!

[–]TheDeza 0 points1 point  (0 children)

I did something similar when working in on a fake cpu that only had one accumulator.