Skip to content

Instantly share code, notes, and snippets.

@cahirwpz
Created April 25, 2016 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cahirwpz/19c6ea0033a1685f72f03025874530fc to your computer and use it in GitHub Desktop.
Save cahirwpz/19c6ea0033a1685f72f03025874530fc to your computer and use it in GitHub Desktop.
m68k GCC assembly inline for abs function without jump instruction
static inline int absl(int x) {
int t;
asm("move.l %0,%1\n\t"
"add.l %1,%1\n\t"
"subx.l %1,%1\n\t"
"eor.l %1,%0\n\t"
"sub.l %1,%0\n\t"
: "+r" (x), "=r" (t));
return x;
}
@cahirwpz
Copy link
Author

cahirwpz commented Apr 25, 2016

Should be exactly five cycles on M68060, however simplier version with asr.l will take two cycles. On M68000 version with jump will be slightly faster, so again - this trick is not very useful :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment