[clean-list] htoclean sorrows

Matthew Bromberg mattcbro at earthlink.net
Tue May 30 19:56:06 MEST 2006


Does using MS link.exe as the linker affect the :V:  argument for 
passing around states?  I start getting #NAN#s out of my code when I 
attempt to
add the extra state variable like this:

module matrix
import StdEnv
import StdList
import StdArray
// import code from library "atlas_library"

:: *State :== Int;


 
cblas_daxpy :: !Int !Real !{#Real}  !Int !{#Real} !Int !State -> State 
cblas_daxpy a0 a1 a2 a3 a4 a5 a6 = code {
    ccall cblas_daxpy "IRAIAI:V:I"
}

 

x :: {#Real}
x = {0.5, -0.5, 1.0, -1.0}


// unboxed array IO, uniqueness

y :: *{#Real}
y = {0.0}

st0 :: State
st0 = 0



Start :: (*{#Real}, Int)
Start
# y = {1.0, 2.0, 3.0, 4.0}
#! st0 = cblas_daxpy 4 -2.0 x 1 y 1 st0
= (y, st0)

Perhaps I'll just go back to treating void returns as an Int.  For most 
implementations an Int return should be a value in a register and should not
affect the stack.  The convention changes dramatically however if you 
try to return a large structure.  Also I find FFI a lot easier when I 
simply include the abc code specification rather than go through 
htoclean.  Should I expect this specification to change as far as the 
ccall instruction is concerned?


John van Groningen wrote:
> Matthew Bromberg wrote:
>   
>> Thank you for this information.  I have verified that the atlas .dll library files are definately in ccall format. No doubt all the
>> other C compatible blas libraries are in this format as well.  Now the strange thing
>> is that due to the limitations of the various library tools it is not really possible to get them into a stdcall format in what I'd
>> call a finite amount of time.  One could ask the question, how would you fix a third party .dll that uses a cdecl calling convention so that it works with clean?
>>     
>
> You don't have to. If you use ccall without a P at the beginning, the compiler
> will use the cdecl calling convention. This should also work if the other function is in a dll.
>
> For example if I compile:
>
> module daxpy
>
> import StdEnv
>
> import code from library "libacm_library";
>
> daxpy :: !Int !Real !{#Real} !Int !{#Real} !Int -> Int;
> daxpy nlen alpha x x_d y y_d = code {
> 	ccall daxpy "IRAIAI:I"
> }
>
> rmac :: !Real !{#Real} !{#Real} -> {#Real};
> rmac a x y
> 	# n = daxpy (size x) a x 1 y 1;
> 	| n==n
> 		= y;
>
> Start
> 	= (
> 		rmac 2.0 {0.5, -0.5, 1.0, -1.0} { 1.0,  2.0,  3.0 , 4.0},
> 		rmac 3.0 {0.5, -0.5, 1.0, -1.0} {11.0, 12.0, 13.0, 14.0}
> 	)
>
>
>
> With file libacm_library in the Clean System Files folder consisting of:
>
> libacml.dll
> daxpy
>
>
> The program calls the daxpy function in the acml library from amd,
> and prints the correct results (on windows xp x64).
>
> Kind regards,
>
> John van Groningen
>
>
>   


More information about the clean-list mailing list