FFI questions

2005-06-06 Thread Gary Morris
Hello everyone,

Apologies in advance if I'm asking an incredibly simple question, but

I'm using GHC 6.4 on Windows XP SP2.  I was recently playing with
implementing the Kocher attack on RSA in Haskell, and along the way I
needed a reasonable way to time operations -- the built-in Windows
functions don't do such a good job.  I wrote a very simple function
that uses the rdtsc instruction:

--- begin: AccuTime.c

#include windows.h

__declspec(dllexport) ULONGLONG accuticks() {
LARGE_INTEGER i;
ULONG lo, hi;
__asm {
rdtsc
mov hi, edx
mov lo, eax
}
i.HighPart = hi;
i.LowPart = lo;
return i.QuadPart;
}

--- end

--- begin: AccuTime.h

#ifndef __accutime_h
#define __acutime_h

#include windows.h

ULONGLONG accuticks();

#endif /* __accutime_h */

--- end

and compiled it to AccuTime.dll.  I then attempted to piece together
the file I'd need to import this function into Haskell:

--- begin: AccuTime.hs

module AccuTime where

import Foreign.C.Types

foreign import stdcall unsafe accutime.h accuticks c_accuticks :: IO CULLong

accuticks :: IO Integer
accuticks = do ull - c_accuticks
   return (fromIntegral ull)

--- end

And then, after passing the correct -L and -l flags to ghci, attempted
to load that module.  Unfortunately, I got:

   ___ ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |  GHC Interactive, version 6.4, for Haskell 98.
/ /_\\/ __  / /___| |  http://www.haskell.org/ghc/
\/\/ /_/\/|_|  Type :? for help.

Loading package base-1.0 ... linking ... done.
Loading object (dynamic) AccuTime ... done
final link ... done
Prelude :l AccuTime.hs
Compiling AccuTime ( AccuTime.hs, interpreted )
ghc.exe: panic! (the `impossible' happened, GHC version 6.4):
ByteCodeFFI.mkMarshalCode_wrk(x86) L_

Please report it as a compiler bug to glasgow-haskell-bugs@haskell.org,
or http://sourceforge.net/projects/ghc/.




At this point, I'm quite confused.  Does anyone else know what I'm
doing to cause this panic?

Thanks,

 /g
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: GHC hang

2005-06-06 Thread Robert van Herk

John Goerzen wrote:


On 2005-06-06, Simon Peyton-Jones [EMAIL PROTECTED] wrote:
 


Lots of people seem to have had problems compiling Wash with GHC 6.4.
   



Another person told me, perhaps in private, that it just takes GHC 15
minutes to compile the specific file in question on amd64.  It turns out
that there is not a hang bug with this.

There were various other bugs with Wash, and I think I have got it to at
least a buildable state.  See my announcement on that topic in this list
for more.
 


Yep I told you that. However, I sent a cc to the wrong mailing list :-).

But indeed it takes a long lng time, but it compiles.

Robert
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users