Thread overview
Template Arguments in inline ASM
Sep 07, 2007
John Kiro
Sep 09, 2007
Don Clugston
Sep 09, 2007
John Kiro
September 07, 2007
Hell There

I made the following example to see how far can inline asm blocks use template args:
	========================================
	void asm_template(T)(T Tval,T* pDest)
	{
		asm{
			fld Tval;
			mov EAX,pDest;
			fstp T ptr[EAX];             //#1
			fstp float ptr[EAX];        //#2
			mov EDX,T.sizeof;        //#3
			mov ECX,float.sizeof;   //#4
		}//asm
	}//asm_template

	void main()
	{
	  float f1=4.0;
	  float f2=5.0;

	  asm_template!(float)(f1,&f2);
	}
	========================================
Here is the compilation result of the 4 statements marked above:
#1: ERROR: "cannot use type float as an operand"
#2: OK
#3: OK!!!
#4: ERROR: "ptr expected"

For me, if #1 would be illegal, then the error should not have mentioned "type float". In other words, why would it fail if T is correctly interpreted to float?
I also see that it's surprising that #3 compiles while #4 doesn't (the reverse would be more natural).
In conclusion, I see that template args are partially (and unclearly) supported inside ASM blocks. Me, I hope to have better support for aliases & template args in ASM blocks.
What do you think friends?

Regards,
John
September 09, 2007
John Kiro wrote:
> Hell There
> 
> I made the following example to see how far can inline asm blocks use template args:
> 	========================================
> 	void asm_template(T)(T Tval,T* pDest)
> 	{
> 		asm{
> 			fld Tval;
> 			mov EAX,pDest;
> 			fstp T ptr[EAX];             //#1
> 			fstp float ptr[EAX];        //#2
> 			mov EDX,T.sizeof;        //#3
> 			mov ECX,float.sizeof;   //#4
> 		}//asm
> 	}//asm_template
> 		
> 	void main()
> 	{
> 	  float f1=4.0;
> 	  float f2=5.0;
> 	
> 	  asm_template!(float)(f1,&f2);
> 	}
> 	========================================
> Here is the compilation result of the 4 statements marked above:
> #1: ERROR: "cannot use type float as an operand"
> #2: OK
> #3: OK!!!
> #4: ERROR: "ptr expected"
> 
> For me, if #1 would be illegal, then the error should not have mentioned "type float". In other words, why would it fail if T is correctly interpreted to float?
> I also see that it's surprising that #3 compiles while #4 doesn't (the reverse would be more natural).
> In conclusion, I see that template args are partially (and unclearly) supported inside ASM blocks. Me, I hope to have better support for aliases & template args in ASM blocks.
> What do you think friends?
> 
> Regards,
> John
Yup. #1 and #4 are bugs. Put them into Bugzilla.
There are several bugs related to asm and templates. Bug #1125, in particular, is giving me a lot of grief at the moment. And in the last DMD, there's a new bad code generation bug with using tuple parameters from asm.
September 09, 2007
Don Clugston Wrote:

> John Kiro wrote:
> > Hell There
> > 
> > I made the following example to see how far can inline asm blocks use template args:
> > 	========================================
> > 	void asm_template(T)(T Tval,T* pDest)
> > 	{
> > 		asm{
> > 			fld Tval;
> > 			mov EAX,pDest;
> > 			fstp T ptr[EAX];             //#1
> > 			fstp float ptr[EAX];        //#2
> > 			mov EDX,T.sizeof;        //#3
> > 			mov ECX,float.sizeof;   //#4
> > 		}//asm
> > 	}//asm_template
> > 
> > 	void main()
> > 	{
> > 	  float f1=4.0;
> > 	  float f2=5.0;
> > 
> > 	  asm_template!(float)(f1,&f2);
> > 	}
> > 	========================================
> > Here is the compilation result of the 4 statements marked above:
> > #1: ERROR: "cannot use type float as an operand"
> > #2: OK
> > #3: OK!!!
> > #4: ERROR: "ptr expected"
> > 
> > For me, if #1 would be illegal, then the error should not have mentioned "type float". In other words, why would it fail if T is correctly interpreted to float?
> > I also see that it's surprising that #3 compiles while #4 doesn't (the reverse would be more natural).
> > In conclusion, I see that template args are partially (and unclearly) supported inside ASM blocks. Me, I hope to have better support for aliases & template args in ASM blocks.
> > What do you think friends?
> > 
> > Regards,
> > John
> Yup. #1 and #4 are bugs. Put them into Bugzilla.
> There are several bugs related to asm and templates. Bug #1125, in particular,
> is giving me a lot of grief at the moment. And in the last DMD, there's a new
> bad code generation bug with using tuple parameters from asm.

Thanks Don.. that would be my first bugs to report.. I'll check how to do so.

Regards,
John