inline assembly 에서 early clobber 의 역할

inline assembly 를 컴파일할 때 Gcc는 항상 모든 input 변수들이 다 사용된 후에 output 변수들이 쓰인다고 가정해서 input 변수와 output 변수를 같은 operand register 에 할당하기도 합니다.
즉, inline assembly 를 해독하여 assembly code 로 펼쳐놓을 때, input 인자를 저장하거나 하는데 쓰이는 register 가 다시 중복하여 output 용 register 로 사용될 수 있도록 코드를 생성하기도 한다는 것입니다.
그런데, 이렇게 Input, output이 하나의 operand register 에 할당되고 만약 input보다 output으로 먼저쓰이게 되면 틀린 결과가 나올 수 있습니다.
이런 경우에는 gcc에게 그 output 변수는 input의 값들이 모두 사용되기 전에 값이 바뀔 수 있다는 것을 알려주어야 하는데, 이것을 알려주기 위한 modifier가 early clobber modifier '&' 입니다.

References:
1. http://keep2smile.tistory.com/28
2. http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html
(6.2 Constraint Modifiers)

You may also like...

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x