-
Notifications
You must be signed in to change notification settings - Fork 7
/
hashtree_abi.nim
49 lines (39 loc) · 1.81 KB
/
hashtree_abi.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# hashtree nim bindings
# Copyright (c) 2024 Status Research & Development GmbH
# Licensed and distributed under
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# This file may not be copied, modified, or distributed except according to those terms.
{.pragma: hashtreedecl, importc, cdecl, gcsafe, raises: [].}
import std/[os, strutils]
const srcDir = currentSourcePath.parentDir.replace('\\', '/') & "/src/"
{.compile: srcDir & "hashtree.c".}
# The assember files use gnu/binutils-specific macros and lack mac support in
# general
when
((defined(linux) or defined(windows)) and defined(gcc)) or
(defined(linux) and defined(clang)) or
(defined(macosx) and defined(clang) and defined(arm64)):
const cflags =
when defined(clang) and defined(linux):
# The integrated `clang` assembler uses a different macro syntax but on
# linux we can convince it to use the system assembler which _tends_ to be
# the binutils variant
"-fno-integrated-as"
else:
""
when defined(arm64):
{.compile(srcDir & "sha256_armv8_crypto.S", cflags).}
{.compile(srcDir & "sha256_armv8_neon_x1.S", cflags).}
{.compile(srcDir & "sha256_armv8_neon_x4.S", cflags).}
elif defined(amd64):
{.compile(srcDir & "sha256_avx_x1.S", cflags).}
{.compile(srcDir & "sha256_avx_x4.S", cflags).}
{.compile(srcDir & "sha256_avx_x8.S", cflags).}
{.compile(srcDir & "sha256_avx_x16.S", cflags).}
{.compile(srcDir & "sha256_shani.S", cflags).}
{.compile(srcDir & "sha256_sse_x1.S", cflags).}
type HashFcn* = proc(output: pointer, input: pointer, count: uint64) {.
cdecl, noSideEffect, gcsafe, raises: [].}
proc hashtree_init*(override: HashFcn): cint {.hashtreedecl.}
func hashtree_hash*(output: pointer, input: pointer, count: uint64) {.
hashtreedecl.}