Guest User

Untitled

a guest
Sep 11th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. test:cnt
  2.  
  3. "__gmpf_add (mpfr_t gmpfr, mpfr_t op1, mpfr_t op2)"
  4.     <primitive: #primitiveNativeCall module: #NativeBoostPlugin>
  5.    
  6.     ^ NBFFICallout cdecl: #( void (mpfr_t gmpfr, ulong cnt))
  7.     emitCall: [:gen | | asm  proxy smpfr scnt|
  8.         asm := gen asm.
  9.         proxy := gen proxy.
  10.        
  11.         "reserve temps for parameters passed in from Smalltalk"
  12.         smpfr := gen reserveTemp.
  13.         scnt := gen reserveTemp.
  14.        
  15.         "move parameters into temps"
  16.  
  17.         asm
  18.                  mov: asm ESP ptr to:  asm EAX;
  19.                 mov: asm EAX to: smpfr;   "gmpfr -> smpfr"
  20.                 mov: asm ESP ptr + 4 to: asm EAX;
  21.             mov: asm EAX to: scnt.  "cnt -> scnt"
  22.            
  23.            
  24.                 "setup loop compare and jmp or push ECX and pass through to function call"
  25.         asm
  26.             mov: scnt to: asm ECX;
  27.             label: #top;
  28.             cmp: asm ECX with: 0;
  29.             jz: #bottom;
  30.             push: asm ECX.
  31.        
  32.         "call function"
  33.        
  34.         asm cdeclCall: [:call | | gmpfrAddFcnPtr |   "handles stack alignment"
  35.  
  36.         "push function arguments (note, cdecl push order is from right to left ) "
  37.         asm
  38.             push: smpfr;
  39.             push: smpfr;
  40.             push: smpfr.
  41.  
  42.         "get a function address"
  43.         gmpfrAddFcnPtr := self nbGetSymbolAddress: 'mpfr_add' module:self nbLibraryNameOrHandle.
  44.  
  45.  
  46.         "put a function address into EAX, and call function "
  47.  
  48.          asm mov: gmpfrAddFcnPtr asUImm to: asm EAX.
  49.         asm call: asm EAX.
  50.  
  51.  
  52.     ] alignment: gen stackAlignment .
  53.  
  54.     "restore ECX and jump to top for test"
  55.  
  56.     asm
  57.         pop: asm ECX;
  58.         dec: asm ECX;
  59.         jmp: #top.
  60.        
  61.     asm label: #bottom.
  62.  
  63.     ]
Add Comment
Please, Sign In to add comment