CnUnix

[알림판목록 I] [알림판목록 II] [글목록][이 전][다 음]
[ CnUnix ] in KIDS
글 쓴 이(By): 구르미 (구르미)
날 짜 (Date): 2006년 2월  2일 목요일 오전 06시 22분 22초
제 목(Title): [질] 64bit inline assembly, bitops.h


bitmap관련된 operation을 많이 써서 이번에 32bit코드를 64bit용으로 
porting하면서 문제가 생겼습니다.


다음의 kernel에 있는 inline assembly code를 제 코드에 덧붙여 쓸려는데
컴파일할 때 에러가 나는군요.

http://lxr.linux.no/source/arch/x86_64/lib/bitops.c?a=x86_64#L4 

---
9 /**
10  * find_first_zero_bit - find the first zero bit in a memory region
11  * @addr: The address to start the search at
12  * @size: The maximum size to search
13  *
14  * Returns the bit-number of the first zero bit, not the number of the 
byte
15  * containing a bit.
16  */
17 inline long find_first_zero_bit(const unsigned long * addr, unsigned 
long size)
18 {
19         long d0, d1, d2;
20         long res;
21 
22         if (!size)
23                 return 0;
24         asm volatile(
25                 "  repe; scasq\n"
26                 "  je 1f\n"
27                 "  xorq -8(%%rdi),%%rax\n"
28                 "  subq $8,%%rdi\n"
29                 "  bsfq %%rax,%%rdx\n"
30                 "1:  subq %[addr],%%rdi\n"
31                 "  shlq $3,%%rdi\n"
32                 "  addq %%rdi,%%rdx"
33                 :"=d" (res), "=&c" (d0), "=&D" (d1), "=&a" (d2)
34                 :"" (0ULL), "1" ((size + 63) >> 6), "2" (addr), "3" 
(-1ULL),
35                  [addr] "r" (addr) : "memory");
36         return res;
37 }
---


예전같으면 
#include "asm/bitops.h"
만 집어 넣어주면 문제가 없어야 하는데

묘하게도 find_first_zero_bit() 은 /usr/include/asm-i386/bitops.h와
/usr/include/asm-x86_64/bitops.h가 32bit 버젼으로 일치합니다.

/proc/version의 내용은 다음과 같습니다.

Linux version 2.6.9-11.ELsmp (bhcompile@crowe.devel.redhat.com) (gcc 
version 3.4.3 20050227 (Red Hat 3.4.3-22)) #1 SMP Fri May 20 18:25:30 EDT 
2005



에러 메세지는 다음과 같습니다.

% icc -o test64 test64.c
test64.c(34): error: asm operand has no constraint letter
        :"" (0ULL), "1" ((size + 63) >> 6), "2" (addr), "3" (-1ULL),
         ^

test64.c(35): error: expected an asm operand
        [addr] "r" (addr) : "memory");
        ^

compilation aborted for test64.c (code 2)

% gcc -o test64 test64.c
test64.c: In function `find_first_zero_bit2':
test64.c:24: warning: asm operand 4 probably doesn't match constraints
test64.c:24: error: impossible constraint in `asm'

64bit에 맞추어 inline assembly가 바뀐게 있다 하더라도 gcc(3.4.4)가 에러는
내는 것은 이해할 수가 없네요.

[알림판목록 I] [알림판목록 II] [글 목록][이 전][다 음]
키 즈 는 열 린 사 람 들 의 모 임 입 니 다.