Thread: [GnuWin32-Users] [gnuwin32 - Help] GSL in assembler
Provides native Win32 open source ports and utilities
Brought to you by:
gnuwin32
From: SourceForge.net <no...@so...> - 2012-02-11 22:14:17
|
Read and respond to this message at: https://sourceforge.net/projects/gnuwin32/forums/forum/74807/topic/5012933 By: jj2007 Hello, I am mostly programming in Masm on Windows, and stumbled over gsl a while ago. Fantastic work! So I decided to make it more accessible in assembler, and wrote some macros. Here is a demo how to use the macro with Microsoft Masm or [url=http://www.japheth.de/JWasm.html]JWasm[/url], taken 1:1 from the [url=http://www.gnu.org/software/gsl/manual/gsl-ref.html#An-Example-Program]gsl example program[/url]: [quote][size=12pt]include \masm32\MasmBasic\MasmBasic.inc [color=grey]; [/color][url=http://www.masm32.com/board/index.php?topic=12460]download[/url] [color=blue] [/color]; [url=http://gnuwin32.sourceforge.net/packages/gsl.htm]libgsl.dll download[/url] : open Binaries zip, and extract ; libgsl.dll and libgslcblas.dll to \masm32\MasmBasic\GnuScLib\DLL [color=grey] ; define the gsl function(s) you need using the syntax of the [/color][url=http://www.gnu.org/software/gsl/manual/gsl-ref.html]GNU Scientific Library Reference[/url] [/size][size=14pt][b]gsl double [color=red]gsl_sf_bessel_J0[/color] (double x)[/size][size=12pt] [/b] .data x REAL8 5.0 [color=grey]; in C, this would be [/color][color=red]double x = 5.0;[/color] [/size][size=14pt][b][color=blue]Init[/size][size=12pt][/b] [/color][b] [/size][size=14pt][color=blue]gsl_INIT[/size][size=12pt] [/b] [/color][/size][size=14pt][b][color=red]gsl_sf_bessel_J0[/color](x)[/size][size =12pt] [/b] [color=blue]PrintLine[/color] "GNU expected:", Tb$, "-0.1775967713143382920" [color=blue]PrintLine[/color] "On FPU: ", Tb$, "-0.1775967713143383198" [color=blue]Inkey Str$[/color]("MB Str$() \t%If", ST(0))[color=grey] [/color][b] [/size][size=14pt][color=blue]gsl_EXIT[/color][/size][size=12pt] [/b] [/size][size=14pt][b][color=blue]Exit[/color][/size][size=12pt][/b] end start [/size][/quote] _____________________________________________________________________________________ You are receiving this email because you elected to monitor this topic or entire forum. To stop monitoring this topic visit: https://sourceforge.net/projects/gnuwin32/forums/forum/74807/topic/5012933/unmonitor To stop monitoring this forum visit: https://sourceforge.net/projects/gnuwin32/forums/forum/74807/unmonitor |
From: SourceForge.net <no...@so...> - 2012-02-17 20:02:08
|
Read and respond to this message at: https://sourceforge.net/projects/gnuwin32/forums/forum/74807/topic/5012933 By: mz2ptc0 I don't understand why GSL users would want to write code in MASM or Nasm assembler language except maybe for industrial applications. I would say that for most "open source" developers Nasm is preferred over MASM; for example OpenSSL no longer supports MSVC/C++ building with MASM with the latest version 1.0.0g. _____________________________________________________________________________________ You are receiving this email because you elected to monitor this topic or entire forum. To stop monitoring this topic visit: https://sourceforge.net/projects/gnuwin32/forums/forum/74807/topic/5012933/unmonitor To stop monitoring this forum visit: https://sourceforge.net/projects/gnuwin32/forums/forum/74807/unmonitor |
From: SourceForge.net <no...@so...> - 2012-02-21 21:54:27
|
Read and respond to this message at: https://sourceforge.net/projects/gnuwin32/forums/forum/74807/topic/5012933 By: jj2007 See it the other way round: Why should a Masm coder want to use the GSL library? Simply because occasionally you may need some math functions. Besides, while the code below is assembler (i.e. ML.EXE recognises it as valid code and [i]assembles[/i] it...), it undeniably bears some resemblence to, well, BASIC ;-) include \masm32\MasmBasic\MasmBasic.inc [color=grey]; [/color][url=http://www.masm32.com/board/index.php?topic=12460]download[/url] ; [url=http://gnuwin32.sourceforge.net/packages/gsl.htm]libgsl.dll download[/url] : open Binaries zip, and extract the two files ; libgsl.dll and libgslcblas.dll to \masm32\MasmBasic\GnuScLib\DLL [color=grey]; define your required gsl function(s) using the syntax of the [/color][url=http://www.gnu.org/software/gsl/manual/gsl-ref.html]GNU Scientific Library Reference[/url] [color=blue]gsl[/color] double [color=red]gsl_stats_mean[/color] (const double data[], size_t [color=red]stride[/color], size_t [color=blue]n[/color]) [color=grey]; stride in doubles[/color] [color=blue]gsl[/color] double [color=red]gsl_stats_variance[/color] (const double data[], size_t [color=red]stride[/color], size_t [color=blue]n[/color]) [color=blue]gsl[/color] double [color=red]gsl_stats_sd[/color] (const double data[], size_t [color=red]stride[/color], size_t [color=blue]n[/color]) [color=blue]gsl[/color] double [color=red]gsl_stats_skew[/color] (const double data[], size_t [color=red]stride[/color], size_t [color=blue]n[/color]) [color=blue]gsl[/color] double [color=red]gsl_sf_bessel_J0[/color] (double x) [color=grey]; double x means a pointer to a REAL8 is required[/color] [b] [color=blue]Init [/color] [color=blue]gsl_INIT[/color] [/b] ; [color=blue]Kill[/color] "MyDoubles.dat" [color=grey]; activate if you want to create a new file with every run[/color] .if ![color=blue]Exist[/color]("MyDoubles.dat") [color=grey]; generate a new data file in \Masm32\MasmBasic\GnuScLib\DLL[/color] [color=blue]NumDoubles=1[/color][color=red]000[/color][color=blue]000 [/color ][color=grey]; one Million items - should take a while...[/color] [color=blue]Rand[/color]() [color=grey]; optional: set a seed using rdtsc [/color] [color=blue]Dim[/color] MyDoubles([color=blue]NumDoubles-1[/color]) As REAL8 [color=blue]For_[/color] ebx=0 To [color=blue]NumDoubles-1[/color] [color=blue]Rand[/color](0, 200, MyDoubles(ebx)) [color=grey]; create a double between 0 (inclusive) and 200 (exclusive)[/color] [color=blue] Next[/color] [color=grey]; for numeric arrays, Recall and Store need the #x syntax, i.e. Store "myfile.dat", MyDoubles() is not possible [/color] [color=blue]Open[/color] "O", [color=blue]#1,[/color] "MyDoubles.dat" [color=grey]; write the [/color][color=blue]NumDoubles[/color][color=grey] items to file[/color] [color=blue]Store[/color] #1, MyDoubles() [color=blue]Close[/color] #1 [color=blue]Erase[/color] MyDoubles() [color=grey]; this array no longer needed[/color] [color=blue]PrintLine[/color] "New dataset created in ", [color=blue]CurDir$[/color](0), CrLf$ .endif [color=blue]Open[/color] "I", [color=blue]#1,[/color] "MyDoubles.dat" mov [color=blue]ebx[/color], [color=blue]Lof[/color]([color=blue]#1)[/color] [color=grey]; we need the size in a permanent register[/color] sar [color=blue]ebx[/color], 3 [color=grey]; divide size by 8[/color] [color=blue]PrintLine[/color] "Analysing ", [color=blue]CurDir$[/color](), [color=blue]Str$[/color]("MyDoubles.dat with %i entries", [color=blue]ebx[/color]) [color=blue]Dim[/color] MyDoubles[color=red]2[/color]([color=blue]ebx[/color]) As REAL8 [color=grey]; read an array of doubles from file[/color] [color=blue]Recall[/color] #1, MyDoubles2() [color=blue]Close[/color] #1 lea ecx, MyDoubles2(0) [color=grey]; get pointer to start of data [/color][color=blue] [/color][color=red]gsl_stats_mean[/color](ecx, [color=red]1[/color], [color=blue]ebx[/color]) [color=grey]; [/color][color=red]stride 1 double[/color][color=grey], [/color][color=blue]NumDoubles items[/color] [color=blue]Print Str$[/color]("\nstats_mean= \t [color=blue]%5f[/color]", ST(0)) [color=grey]; show as float, [/color][color=blue]5[/color][color=grey] digits precision[/color] [color=blue]fstp st [/color][color=grey]; clean up the FPU - gsl uses many, sometimes all 8 FPU registers[/color] [color=blue] [/color][color=red]gsl_stats_variance[/color](ecx, [color=red]1[/color], [color=blue]ebx[/color]) [color=grey]; [/color][color=red]stride 1 double[/color][color=grey], [/color][color=blue]NumDoubles items[/color] [color=blue]Print Str$[/color]("\ns_variance= \t [color=blue]%5f[/color]", ST(0)) [color=grey]; show as float, [/color][color=blue]5[/color][color=grey] digits precision[/color] [color=blue]fstp st[/color] [color=blue] [/color][color=red]gsl_stats_sd[/color](ecx, [color=red]1[/color], [color=blue]ebx[/color]) [color=grey]; [/color][color=red]stride 1 double[/color][color=grey], [/color][color=blue]NumDoubles items _____________________________________________________________________________________ You are receiving this email because you elected to monitor this topic or entire forum. To stop monitoring this topic visit: https://sourceforge.net/projects/gnuwin32/forums/forum/74807/topic/5012933/unmonitor To stop monitoring this forum visit: https://sourceforge.net/projects/gnuwin32/forums/forum/74807/unmonitor |