PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

Calling Assembler routine per pgiug.pdf

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
Ken Miller



Joined: 20 May 2005
Posts: 4

PostPosted: Tue Sep 27, 2005 5:42 am    Post subject: Calling Assembler routine per pgiug.pdf Reply with quote

Hi,

I'm trying to test the calling of an assembler routine on AMD (x86_64) both from C and FORTRAN. Your User's Guide provides a C --> Assembler example which I've tried and *almost* works. Namely, the arguments are returned but the results appear incorrect. My attempt at getting FORTRAN appears to fail miserably, which I'm not surprised as I haven't done Assembler since IBM 370s ;) . Can you:


1. Tell me what the results should be from your example and, if different from mine, why?

2. Tell me what I need to do to demonstrate the equivalent for FORTRAN calling assembler.

Thanks in advance,

Quote:

[miller@n1044 asm]$ make
echo "C Program Calling Assembler"
C Program Calling Assembler
cat c_asm.c
#include <stdio.h>
main()
{
printf("C Main calling Assembler Routine:\n");
long l_para1 = 0x3f800000;
float f_para2 = 1.0;
double d_para3 = 0.5;
float f_return;
extern float sum_3 (long para1, float para2, double para3);
f_return = sum_3(l_para1, f_para2, d_para3);
printf("Parameter one, type long = %08x\n", l_para1);
printf("Parameter two, type float = %f\n", f_para2);
printf("Parameter three, type double = %g\n", d_para3);
printf("The sum after conversion = %f\n", f_return);
exit(0);
}

cat asmfunc2c.s
# File: sum_3.s
# Computes ( para1 + para2 ) + para3
.text
.align 16
.globl sum_3
sum_3:
pushq %rbp
movq %rsp, %rbp
cvtsi2ssq %rdi, %xmm2
addss %xmm0, %xmm2
cvtss2sd %xmm2, %xmm2
addsd %xmm1, %xmm2
cvtsd2ss %xmm2, %xmm2
movaps %xmm2, %xmm0
popq %rbp
ret
.type sum_3,@function
.size sum_3,.-sum_3
as -o asmfunc2c.o asmfunc2c.s
pgcc -o c_asm.out asmfunc2c.o c_asm.c
c_asm.c:
./c_asm.out
C Main calling Assembler Routine:
Parameter one, type long = 3f800000
Parameter two, type float = 1.000000
Parameter three, type double = 0.5
The sum after conversion = 1065353216.000000
echo "FORTRAN Program Assembler"
FORTRAN Program Assembler
cat ftn_asm.f
integer*8 numl1
real numf2
real numfret
double precision numd3
external sum_3
print *, 'FORTRAN Main Calling Assembler Routine:'
numfret = sum_3 (numl1, numf2, numd3)
write( *, "(I12, F6.1, F6.1, F15.1)")
& numl1, numf2, numd3, numfret
end
cat asmfunc2ftn.s
# File: sum_3.s
# Computes ( para1 + para2 ) + para3
.text
.align 16
.globl sum_3_
sum_3_:
pushq %rbp
movq %rsp, %rbp
cvtsi2ssq %rdi, %xmm2
addss %xmm0, %xmm2
cvtss2sd %xmm2, %xmm2
addsd %xmm1, %xmm2
cvtsd2ss %xmm2, %xmm2
movaps %xmm2, %xmm0
popq %rbp
ret
.type sum_3_,@function
.size sum_3_,.-sum_3_
as -o asmfunc2ftn.o asmfunc2ftn.s
pgf90 -o ftn_asm.out asmfunc2ftn.o ftn_asm.f
ftn_asm.f:
./ftn_asm.out
FORTRAN Main Calling Assembler Routine:
220130790464 0.0 0.0 548682072064.0
[miller@n1044 asm]$
[miller@n1044 asm]$ uname -a
Linux n1044 2.6.9-11.4hp.XCsmp #1 SMP Thu Sep 1 01:26:12 EDT 2005 x86_64 x86_64
x86_64 GNU/Linux
[miller@n1044 asm]$

[miller@n1044 asm]$ cat Makefile
all: c_asm.out ftn_asm.out

c_asm.out:
echo "C Program Calling Assembler"
cat c_asm.c
cat asmfunc2c.s
as -o asmfunc2c.o asmfunc2c.s
pgcc -o c_asm.out asmfunc2c.o c_asm.c
./c_asm.out

ftn_asm.out:
echo "FORTRAN Program Assembler"
cat ftn_asm.f
cat asmfunc2ftn.s
as -o asmfunc2ftn.o asmfunc2ftn.s
pgf90 -o ftn_asm.out asmfunc2ftn.o ftn_asm.f
./ftn_asm.out

clean:
rm -f *.out *.o

[miller@n1044 asm]$


Best Regards,

== ken miller ==
[/code]
Back to top
View user's profile
Ken Miller



Joined: 20 May 2005
Posts: 4

PostPosted: Tue Sep 27, 2005 9:30 am    Post subject: Nevermind! Reply with quote

Hi,

This turns out to be completely pilot error. I wasn't noticing what was actually being done in the assembler routines, and found after the fact that I wasn't initializing the values being passed to the assembler routine.

Thanks any way. Please feel free to delete this topic entirely.

Regards,

== ken miller ==
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group