Add pascal binding (#75)
This commit is contained in:
parent
87dd138312
commit
357011e579
52
README.md
52
README.md
@ -370,6 +370,58 @@ fn main() {
|
|||||||
</td></tr>
|
</td></tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
### ruapu with Pascal
|
||||||
|
|
||||||
|
<table>
|
||||||
|
|
||||||
|
<tr><td>
|
||||||
|
|
||||||
|
Compile ruapu library
|
||||||
|
|
||||||
|
```shell
|
||||||
|
cd pascal
|
||||||
|
sudo apt install fpc
|
||||||
|
cmake .
|
||||||
|
make
|
||||||
|
fpc ruapu.lpr
|
||||||
|
```
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Use ruapu in Pascal
|
||||||
|
|
||||||
|
```pascal
|
||||||
|
program ruapu;
|
||||||
|
|
||||||
|
uses ruapu_pascal;
|
||||||
|
|
||||||
|
var
|
||||||
|
has_avx2: integer;
|
||||||
|
supported: PPAnsiChar;
|
||||||
|
begin
|
||||||
|
// initialize ruapu once
|
||||||
|
ruapu_init();
|
||||||
|
|
||||||
|
// now, tell me if this cpu has avx2
|
||||||
|
has_avx2 := ruapu_supports('avx2');
|
||||||
|
|
||||||
|
// loop all supported features
|
||||||
|
supported := ruapu_rua();
|
||||||
|
while supported^ <> nil do
|
||||||
|
begin
|
||||||
|
writeln(supported^);
|
||||||
|
inc(supported);
|
||||||
|
end;
|
||||||
|
|
||||||
|
readln();
|
||||||
|
end.
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
</td></tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>Github-hosted runner result (Linux)</summary>
|
<summary>Github-hosted runner result (Linux)</summary>
|
||||||
|
|
||||||
|
12
pascal/CMakeLists.txt
Normal file
12
pascal/CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.0)
|
||||||
|
|
||||||
|
project(ruapu)
|
||||||
|
|
||||||
|
include_directories(../)
|
||||||
|
|
||||||
|
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
|
||||||
|
|
||||||
|
add_library(ruapu
|
||||||
|
ruapu-binding.c
|
||||||
|
)
|
||||||
|
|
9
pascal/Readme.md
Normal file
9
pascal/Readme.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
How to use:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo apt install fpc
|
||||||
|
cmake .
|
||||||
|
make
|
||||||
|
fpc ruapu.lpr
|
||||||
|
./ruapu
|
||||||
|
```
|
30
pascal/ruapu-binding.c
Normal file
30
pascal/ruapu-binding.c
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
|
||||||
|
#ifndef DLL_EXPORT
|
||||||
|
#ifdef _WIN32
|
||||||
|
#ifdef _WINDLL
|
||||||
|
#define DLL_EXPORT __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define DLL_EXPORT
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define DLL_EXPORT __attribute__((visibility("default")))
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define RUAPU_IMPLEMENTATION
|
||||||
|
#include "ruapu.h"
|
||||||
|
|
||||||
|
DLL_EXPORT void ruapu_init_c()
|
||||||
|
{
|
||||||
|
ruapu_init();
|
||||||
|
}
|
||||||
|
|
||||||
|
DLL_EXPORT int ruapu_supports_c(const char* isa)
|
||||||
|
{
|
||||||
|
return ruapu_supports(isa);
|
||||||
|
}
|
||||||
|
|
||||||
|
DLL_EXPORT const char* const* ruapu_rua_c()
|
||||||
|
{
|
||||||
|
return ruapu_rua();
|
||||||
|
}
|
25
pascal/ruapu.lpr
Normal file
25
pascal/ruapu.lpr
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
program ruapu;
|
||||||
|
|
||||||
|
uses ruapu_pascal;
|
||||||
|
|
||||||
|
var
|
||||||
|
has_avx2: integer;
|
||||||
|
supported: PPAnsiChar;
|
||||||
|
begin
|
||||||
|
// initialize ruapu once
|
||||||
|
ruapu_init();
|
||||||
|
|
||||||
|
// now, tell me if this cpu has avx2
|
||||||
|
has_avx2 := ruapu_supports('avx2');
|
||||||
|
|
||||||
|
// loop all supported features
|
||||||
|
supported := ruapu_rua();
|
||||||
|
while supported^ <> nil do
|
||||||
|
begin
|
||||||
|
writeln(supported^);
|
||||||
|
inc(supported);
|
||||||
|
end;
|
||||||
|
|
||||||
|
readln();
|
||||||
|
end.
|
||||||
|
|
31
pascal/ruapu_pascal.pas
Normal file
31
pascal/ruapu_pascal.pas
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
unit ruapu_pascal;
|
||||||
|
|
||||||
|
{$mode ObjFPC}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
uses
|
||||||
|
Classes, SysUtils;
|
||||||
|
|
||||||
|
const
|
||||||
|
{$IFDEF MSWINDOWS}
|
||||||
|
ruapu_lib = 'ruapu.dll';
|
||||||
|
{$ELSE}
|
||||||
|
{$IFDEF DARWIN}
|
||||||
|
ruapu_lib = 'libruapu.dylib';
|
||||||
|
{$ENDIF}
|
||||||
|
{$IFDEF ANDROID}
|
||||||
|
ruapu_lib = 'libruapu.so';
|
||||||
|
{$ENDIF}
|
||||||
|
{$IFDEF linux}
|
||||||
|
ruapu_lib = 'libruapu.so';
|
||||||
|
{$ENDIF}
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
|
procedure ruapu_init(); cdecl; external ruapu_lib name 'ruapu_init_c';
|
||||||
|
function ruapu_supports(const isa: PAnsiChar): Integer; cdecl; external ruapu_lib name 'ruapu_supports_c';
|
||||||
|
function ruapu_rua(): PPAnsiChar; cdecl; external ruapu_lib name 'ruapu_rua_c';
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
end.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user