linux2.6.34のswitch_to()を見てたら、インラインアセンブラで見慣れない記述があったので、ちょっと確認してみた。
test1()は通常通りに0番目、1番目って感じで変数を使ってるパターンで、test2()は名前を付けてアクセスする方法。こんなやり方って前からあったっけ? まぁ、名前をつけれる方が分かりやすくて良いのですが。
#include <iostream>
using namespace std;
void test1(int src)
{
int dest = 0;
__asm__ __volatile__("mov %0, %1;\n\t"
:"=r"(dest)
:"r"(src)
);
cout << "dest is " << dest << " : src is << " << src << endl;
}
void test2(int src)
{
int dest = 0;
__asm__ __volatile__("mov %[output], %[input];\n\t"
: [output] "=r"(dest)
: [input] "r"(src)
);
cout << "dest is " << dest << " : src is << " << src << endl;
}
int main(int argc, char **argv)
{
test1(10);
test2(10);
return 0;
}実行結果はこんな感じ。
[masami@moon]~% ./a.out ./a.out dest is 10 : src is << 10 dest is 10 : src is << 10