Email or username:

Password:

Forgot your password?
Devine Lu Linvega

GTHk LIT ADD ADD #00 STR

10 comments | Expand all CWs
Devine Lu Linvega

if(a > b) {
return a + b;
}
else {
return a - b;
}

It quotes the add function and transforms it to a subtraction without branching.

cancel

@neauoire blursed?

Devine Lu Linvega

@cancel curlsed

andreer

@neauoire @neauoire For what it does, it seems to be a very consise implementation (and likely fast too, at least in a non-pipelined execution). I pondered over it for a while though ... Can you reveal any of what it is used for? Some transformation of coordinates?

Devine Lu Linvega

@andreer It's used in a routine that returns an offset to be used to find a routine in a lookup table of pointers. It's part of a project that uses cons cells.

manuelcaeiro ☕

@neauoire
You will never know how useful that might have been for me - who was overthinking some solution. 👍

DHeadshot's Alt

@neauoire
This feels very "Story of Mel"...

charlie

@neauoire from the people that brought you pointer arithmetic: opcode arithmetic

screwlisp

@neauoire ( wiki.xxiivv.com/site/uxntal_re )

Hans X

@neauoire Hm, so if I understand correctly, this only works because the opcodes for ADD and SUB are 18 and 19. Were those values to change in a future release, most code would still work, but this piece would break. 🤔

It's interesting how "code = data" is true in both assembly and Lisp, but their takes on it are entirely different. 🙂

Go Up