anchor.diff:          Log.line "factor: %A" speedup
   
   
  -
  +module Test =
  +
  +    type MyDelegate = delegate of float32 * float32 * int * float32 * int * float32 * int * float32 -> unit
  +
  +    let callback =
  +        MyDelegate (fun a b c d e f g h ->
  +            Log.start "call"
  +            Log.line "a: %A" a
  +            Log.line "b: %A" b
  +            Log.line "c: %A" c
  +            Log.line "d: %A" d
  +            Log.line "e: %A" e
  +            Log.line "f: %A" f
  +            Log.line "g: %A" g
  +            Log.line "h: %A" h
  +            Log.stop()
  +        )
  +
  +    let ptr = Marshal.PinDelegate(callback)
  +
  +    let run () =
  +        let store = NativePtr.alloc 1
  +        NativePtr.write store 100.0f
  +
  +        use stream = new NativeStream()
  +        use asm = AssemblerStream.ofStream stream
  +
  +        asm.BeginFunction()
  +
  +        asm.BeginCall(8)
  +        asm.PushFloatArg(NativePtr.toNativeInt store)
  +        asm.PushArg(6)
  +        asm.PushArg(5.0f)
  +        asm.PushArg(4)
  +        asm.PushArg(3.0f)
  +        asm.PushArg(2)
  +        asm.PushArg(1.0f)
  +        asm.PushArg(0.0f)
  +        asm.Call(ptr.Pointer)
  + 
  +        asm.BeginCall(8)
  +        asm.PushArg(17.0f)
  +        asm.PushArg(16)
  +        asm.PushArg(15.0f)
  +        asm.PushArg(14)
  +        asm.PushArg(13.0f)
  +        asm.PushArg(12)
  +        asm.PushArg(11.0f)
  +        asm.PushArg(10.0f)
  +        asm.Call(ptr.Pointer)
  +
  +        asm.WriteOutput(1234)
  +        asm.EndFunction()
  +        asm.Ret()
  +        
  +        let size = Fun.NextPowerOfTwo stream.Length |> nativeint
  +        let mem = ExecutableMemory.alloc size
  +        Marshal.Copy(stream.Pointer, mem, stream.Length)
  +
  +        let managed : int -> int = UnmanagedFunctions.wrap mem
  +        Log.start "run(3)"
  +
  +        if sizeof<nativeint> = 4 then Log.warn "32 bit"
  +        else Log.warn "64 bit"
  +
  +
  +        let res = managed 3
  +        Log.line "ret: %A" res
  +        Log.stop()
  +
  +        ExecutableMemory.free mem size
  +
  +        Environment.Exit 0
  +
  +
  +open AMD64
   
   [<EntryPoint; STAThread>]
   let main argv = 
  +    Test.run()
   
       Benchmark.run()
       Environment.Exit 0
  
positive.code:     type AssemblerStream(stream : Stream, leaveOpen : bool) =
          let writer = new BinaryWriter(stream, Text.Encoding.UTF8, leaveOpen)
  
          let mutable stackOffset = 0
          let mutable callPadded = []
          let mutable paddingPtr = []
  
negative.code:         Marshal.Copy(buffer, o, store + offset, count)
          length <- length + nativeint count
          offset <- offset + nativeint count
  
  
  type IAssemblerStream =
      inherit IDisposable
  
      abstract member BeginFunction : unit -> unit
      abstract member EndFunction : unit -> unit
      abstract member BeginCall : args : int -> unit
      abstract member Call : ptr : nativeint -> unit
      abstract member PushPtrArg : location : nativeint -> unit
      abstract member PushIntArg : location : nativeint -> unit
      abstract member PushFloatArg : location : nativeint -> unit
      abstract member PushArg : value : nativeint -> unit
      abstract member PushArg : value : int -> unit
      abstract member PushArg : value : float32 -> unit
      abstract member Ret : unit -> unit
      abstract member WriteOutput : value : nativeint -> unit
      abstract member WriteOutput : value : int -> unit
      abstract member WriteOutput : value : float32 -> unit
  
  module AMD64 =
  
  