1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int SATURATE(x)
{
    return (x == (short)x ? x : (x >> 31) ^ 0x7FFF);
}

m68k-elf-gcc saturate.c -m5206e -O1 -S

SATURATE:
  link.w %a6,#0
  move.l 8(%a6),%d1
  move.w %d1,%a0 <-- isn't the upper word of a0 anything here?
  move.l %d1,%d0
  cmp.l %a0,%d1  <-- so this is unreliable(?)
  jbeq .L3
  add.l %d0,%d0
  subx.l %d0,%d0
  eor.l #32767,%d0
.L3:
  unlk %a6
  rts