LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-02-2010, 08:44 AM   #1
mlpa
Member
 
Registered: May 2008
Location: Aveiro
Distribution: Slackware
Posts: 542

Rep: Reputation: 50
ASM Code Problems


Hi everyone, I'm making a multimedia library to speedup vector and matrix computation.

But I'm getting a strange error, in this code
Code:
void memcpy_unrolled_sse2(void *dst, void *src, int size)
{
	int i = 0,
	    length = (size/16)*16,
	    length2 = (size/32)*32,
	    length4 = (size/64)*64,
	    length8 = (size/128)*128;

	char *a = (char *)src;
	char *b = (char *)dst;

	for(i = 0; i < length8; i+=128)
	{
		__asm__ volatile
                ( // instruction             comment
                "\n\t movdqa     %8,%%xmm0         \t#"
		"\n\t movdqa     %9,%%xmm1         \t#"
		"\n\t movdqa     %10,%%xmm2        \t#"
		"\n\t movdqa     %11,%%xmm3        \t#"
		"\n\t movdqa     %12,%%xmm4        \t#"
		"\n\t movdqa     %13,%%xmm5        \t#"
		"\n\t movdqa     %14,%%xmm6        \t#"
		"\n\t movdqa     %15,%%xmm7        \t#"
                "\n\t movdqa     %%xmm0,%0         \t#"
		"\n\t movdqa     %%xmm1,%1         \t#"
		"\n\t movdqa     %%xmm2,%2         \t#"
		"\n\t movdqa     %%xmm3,%3         \t#"
		"\n\t movdqa     %%xmm4,%4         \t#"
		"\n\t movdqa     %%xmm5,%5         \t#"
		"\n\t movdqa     %%xmm6,%6         \t#"
		"\n\t movdqa     %%xmm7,%7         \t#"
		: "=m" (b[i]),     // %0
		  "=m" (b[i+16]),  // %1
		  "=m" (b[i+32]),  // %2
		  "=m" (b[i+48]),  // %3
		  "=m" (b[i+64]),  // %4
		  "=m" (b[i+80]),  // %5
		  "=m" (b[i+96]),  // %6
		  "=m" (b[i+112])  // %7
		: "m"  (a[i]),     // %8
		  "m"  (a[i+16]),  // %9
		  "m"  (a[i+32]),  // %10
		  "m"  (a[i+48]),  // %11
		  "m"  (a[i+64]),  // %12
		  "m"  (a[i+80]),  // %13
		  "m"  (a[i+96]),  // %14
		  "m"  (a[i+112])  // %15
		);
	}

	for(i = length8; i < length4; i+=64)
	{
		__asm__ volatile
                ( // instruction             comment
                "\n\t movdqa     %4,%%xmm0         \t#"
		"\n\t movdqa     %5,%%xmm1         \t#"
		"\n\t movdqa     %6,%%xmm2         \t#"
		"\n\t movdqa     %7,%%xmm3         \t#"
	        "\n\t movdqa     %%xmm0,%0         \t#"
		"\n\t movdqa     %%xmm1,%1         \t#"
		"\n\t movdqa     %%xmm2,%2         \t#"
		"\n\t movdqa     %%xmm3,%3         \t#"
		: "=m" (b[i]),     // %0
		  "=m" (b[i+16]),  // %1
		  "=m" (b[i+32]),  // %2
		  "=m" (b[i+48])   // %3
		: "m"  (a[i]),     // %4
		  "m"  (a[i+16]),  // %5
		  "m"  (a[i+32]),  // %6
		  "m"  (a[i+48])   // %7
		);
	}
	
	for(i = length4; i < length2; i+=32)
	{
		__asm__ volatile
                ( // instruction             comment
                "\n\t movdqa     %2,%%xmm0         \t#"
		"\n\t movdqa     %3,%%xmm1         \t#"
                "\n\t movdqa     %%xmm0,%0         \t#"
		"\n\t movdqa     %%xmm1,%1         \t#"
		: "=m" (b[i]),     // %0
		  "=m" (b[i+16])   // %1
		: "m"  (a[i]),     // %2
		  "m"  (a[i+16])   // %3
		);
	}

	for(i = length2; i < length; i+=16)
	{
		__asm__ volatile
                ( // instruction             comment
                "\n\t movdqa     %1,%%xmm0         \t#"
                "\n\t movdqa     %%xmm0,%0         \t#"
		: "=m" (b[i])      // %0
		: "m"  (a[i])      // %1
		);
	}


	for(i = length; i < size; i++)
		b[i] = a[i];
}
When I compile without -O1,2,3 I get this error:

Code:
libMultimedia.cpp: In function 'void memcpy_unrolled_sse2(void*, void*, int)':
libMultimedia.cpp:5033: error: can't find a register in class 'GENERAL_REGS' while reloading 'asm'
libMultimedia.cpp:5033: error: 'asm' operand has impossible constraints
make: *** [libMultimedia.o] Error 1
Can some one help me?

Last edited by XavierP; 09-02-2010 at 11:48 AM. Reason: Moved to Programming
 
Old 09-03-2010, 12:59 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
As we obviously don't have the more than 5000 lines of code where the error is, are you able to identify which line it is in the code you have presented?
 
Old 09-03-2010, 03:02 AM   #3
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Rep: Reputation: 56
It doesn't look like it's the full source code. It looks like a single function, possibly defined even before main() is declared. So we know the error is somewhere within that function.
 
Old 09-03-2010, 03:31 AM   #4
mlpa
Member
 
Registered: May 2008
Location: Aveiro
Distribution: Slackware
Posts: 542

Original Poster
Rep: Reputation: 50
The error is in the first block of asm code the line with );
This project is hosted in google code here.

I searched google but all I can find is pieces of asm code with the same error, never a solution.
 
Old 09-05-2010, 10:07 AM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
When compiling without optimization (-O0) gcc ends up allocating one register per operand, but there are only 15 registers in total including the stack and frame pointers, thus the error. You can rewrite the assembly so only 2 registers are used:
Code:
            asm
                ( // instruction             comment
                 "\n\t movdqa 0x00(%1), %%xmm0           \t#"
                 "\n\t movdqa 0x10(%1), %%xmm1           \t#"
                 "\n\t movdqa 0x20(%1), %%xmm2           \t#"
                 "\n\t movdqa 0x30(%1), %%xmm3           \t#"
                 "\n\t movdqa 0x40(%1), %%xmm4           \t#"
                 "\n\t movdqa 0x50(%1), %%xmm5           \t#"
                 "\n\t movdqa 0x60(%1), %%xmm6           \t#"
                 "\n\t movdqa 0x70(%1), %%xmm7           \t#"

                 "\n\t movdqa %%xmm0,0x00(%0)         \t#"
                 "\n\t movdqa %%xmm1,0x10(%0)         \t#"
                 "\n\t movdqa %%xmm2,0x20(%0)         \t#"
                 "\n\t movdqa %%xmm3,0x30(%0)         \t#"
                 "\n\t movdqa %%xmm4,0x40(%0)         \t#"
                 "\n\t movdqa %%xmm5,0x50(%0)         \t#"
                 "\n\t movdqa %%xmm6,0x60(%0)         \t#"
                 "\n\t movdqa %%xmm7,0x70(%0)         \t#"
                 : "=r" (b) : "r" (a)
                 : "xmm0", "xmm1", "xmm2", "xmm3",
                   "xmm4", "xmm5", "xmm6", "xmm7"
		);
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to combine ASM and C code? MTK358 Programming 27 04-11-2010 10:37 AM
Is there a C/C++ code --> ASM code chart ??? RipClaw Programming 7 05-09-2006 06:36 PM
Have you seen such asm code? snowing Programming 2 07-07-2005 05:13 AM
Using asm code in C program. grub Programming 2 04-03-2003 11:00 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration