Looking at assembly listings of the Linux kernel I see thousands of
places where function returns are checked to be non-zero to indicate
errors. For example something like this:
mov bx, 0
.L1
call foo
test ax,ax
jnz .Lerror
inc bx
cmp bx, 10
jne .L1
....
.Lerror
process error
A new calling convention could push two return addresses for functions
that return their status in EAX. On EAX=0 you take the first return,
EAX != 0 you take the second.
So the above code becomes:
push .Lerror
mov bx, 0
.L1
call foo
inc bx
cmp bx, 10
jne .L1
add sp, 2
.Lerror
process error
The called function then does 'ret' or 'ret 4' depending on the status
of EAX != 0.
Of course there are many further optimizations that can be done, but
this illustrates the concept.
Has work been done to evaluate a calling convention that takes error
checks like this into account? Are there size/performance wins? Or am
I just reinventing a variation on exception handling?
--
Jon Smirl
[EMAIL PROTECTED]