LINUX.ORG.RU

История изменений

Исправление SZT, (текущая версия) :

Пока вся работа в одном процессе - использую ret и не беспокоюсь. Все правильно понял?

Вообще да, но не совсем. Инструкцию ret не рекомендуется так использовать. Рассогласование call/ret будет, это не очень хорошо для производительности.

Тут описано

The P1 has no return stack buffer, but uses the same method for returns as for indirect jumps. Later processors have a return stack buffer. The size of this buffer is 4 in the PMMX, 8in Atom, 12 in AMD k8, 16 in PPro, P2, P3, P4, P4E, PM, Core2 and Nehalem, and 24 in AMD k10. This size may seem rather small, but it is sufficient in most cases because only the innermost subroutines matter in terms of execution time. The return stack buffer may be insufficient, though, in the case of a deeply nesting recursive function.

In order to make this mechanism work, you must make sure that all calls are matched with returns. Never jump out of a subroutine without a return and never use a return as an indirect jump. It is OK, however, to replace a CALL MYPROC/ RETsequence with JMP MYPROC in 16 and 32 bit mode. In 64 bit mode, obeying the stack alignment standard, you can replace SUB RSP,8 / CALL MYPROC / ADD RSP,8 / RET with JMP MYPROC.

Исходная версия SZT, :

Пока вся работа в одном процессе - использую ret и не беспокоюсь. Все правильно понял?

Вообще да, но не совсем. Инструкцию ret не рекомендуется так использовать. Рассогласование call/ret будет, это не очень хорошо для производительности.

Тут описано

The P1 has no return stack buffer, but uses the same method for returns as for indirect jumps. Later processors have a return stack buffer. The size of this buffer is 4 in the PMMX, 8in Atom, 12 in AMD k8, 16 in PPro, P2, P3, P4, P4E, PM, Core2 and Nehalem, and 24 in AMD k10. This size may seem rather small, but it is sufficient in most cases because only the innermost subroutines matter in terms of execution time. The return stack buffer may be insufficient, though, in the case of a deeply nesting recursive function.

In order to make this mechanism work, you must make sure that all calls are matched with returns. Never jump out of a subroutine without a return and never use a return as an indirect jump. It is OK, however, to replace a CALL MYPROC/ RETsequence with JMP MYPROC in 16 and 32 bit mode. In 64 bit mode, obeying the stack alignment standard, you can replaceSUB RSP,8 / CALL MYPROC / ADD RSP,8 / RET withJMP MYPROC.