From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1641 invoked by alias); 21 Jan 2014 10:23:59 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 1621 invoked by uid 89); 21 Jan 2014 10:23:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: relay2.uni-heidelberg.de Received: from relay2.uni-heidelberg.de (HELO relay2.uni-heidelberg.de) (129.206.210.211) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Tue, 21 Jan 2014 10:23:58 +0000 Received: from extmail.urz.uni-heidelberg.de (extmail.urz.uni-heidelberg.de [129.206.100.140]) by relay2.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id s0LANrL8010782 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 21 Jan 2014 11:23:53 +0100 Received: from [147.142.39.44] (hoff.ziti.uni-heidelberg.de [147.142.39.44]) (authenticated bits=0) by extmail.urz.uni-heidelberg.de (8.13.4/8.13.1) with ESMTP id s0LANq9u022866 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 21 Jan 2014 11:23:53 +0100 Message-ID: <52DE4AB8.1060203@ziti.uni-heidelberg.de> Date: Tue, 21 Jan 2014 10:23:00 -0000 From: Stephan Walter User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: gcc-help@gcc.gnu.org Subject: How to use the KNC Vectorregisters with GCC? Race condition with ICC & KNC? References: <1390297511.8654.ezmlm@gcc.gnu.org> In-Reply-To: <1390297511.8654.ezmlm@gcc.gnu.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2014-01/txt/msg00081.txt.bz2 Hi, i am new to the gcc mailinglist, so i hope i am right here. As the subject shows, i work with KNC. My problem is, that i have developed a kernel modul for a NIC and now want to use the 512Bit registers of KNC for some memcopy jobs. I have experience how to use the GCC to compile der KNC-linux and kernel moduls. So no problem at the moment. Everything works fine. Before i started to write inline assembler with the 512Bit registers, i have written some minimal examples. On a normal i5-3470 everything works fine together with the gcc. Also on KNC everything works. The problem now is, that when i try to use the 512Bit registers, it looks like GCC doesn't know the register names and instructions. To solve the problem with the instructions i think is no problem, because i have the instruction manual, but i have no idea how to solve the register problem. So i try to use the ICC with -mmic. The source compiles, but when i measure the clock cycles with rdtsc, the two first check work, but the 3. and 4. not. I tried to solve the problem with the gdb, but when i use -g the mistake no longer occur. Also when i use a printf, sleep(1) or usleep(1), the problem is fixed. So i think there is a race condition with the write of the value into the memory, because 1 or even 100 nops have no effects. My inline assembler knowledge is rudimental, so i don't know if i have some problems with the use of clobber registers and so on or if there is a bug in gcc or icc. That the -g with the icc solve the problem makes it impossible for me to debug the problem. So i hope somebody is able to help me. My favourite is to use gcc together with the 512Bit registers, if there is a bug in my inline assembler, a solution/hint would be also fine. So there is my code: #include #include #include int rdtsc_count(void){ int count; __asm__ __volatile__( "rdtsc; \n\t" "movl %%eax, %0; \n\t" :"=m"(count)//, "=r"(brd), "=r"(crd), "=r"(drd) : :"%eax", "memory"//, "cc"//, "%ebx", "%ecx" ); return count; } int main(int argc, char *argv[]){ int starta=0, startb=0, stopa=0, stopb=0; int buffer_size=32; uint64_t* buffer; uint32_t buflen=atoi(argv[1]); /////////////setup buffer = (uint64_t*) malloc (buffer_size*sizeof(uint64_t)); packet_buffer = (uint64_t*) malloc (buffer_size*sizeof(uint64_t)); packet_buffer_ref= (uint64_t*) malloc (buffer_size*sizeof(uint64_t));//REF waddr=0; //printf("Adresse von packet_buffer %x", waddr); printf("Orginaldaten\n"); for(i=0; i120){ printf("buflen too big or too small\n"); return 0; } ######################################## starta=rdtsc_count(); memcpy(&(packet_buffer_ref[waddr+1]), buffer, sizeof(uint64_t)*(buflen));//REF stopa=rdtsc_count(); printf("memcpy took\t%d\tclocks\n", stopa-starta); ######################################## ##Here everything is fine ######################################## ######################################## startb=rdtsc_count(); __asm__ ( "movq %1, %%rsi; \n\t" "movq %0, %%rdi; \n\t" "movl %2, %%ecx; \n\t" "addq $8, %%rdi; \n\t" // "shl $3, %%ecx; \n\t" "Schleife: movsq; \n\t" "loop Schleife; \n\t" :"=m"(packet_buffer) :"r"(buffer), "r"(buflen) :"%rsi", "%rdi", "%rcx", "memory" ); stopb=rdtsc_count(); ######################################### If i use one of this functions, everything is fine. //usleep(1); //printf("stopa %d\n", stopa); //printf("fdsagfa\n"); ######################################### printf("asm movsq took\t%d\tclocks\n", stopb-startb); ######################################## ##Here i have the problem. It looks like stopb or startb is still 0, when i use no function between the output and the rdtsc_count() ########################################