This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import strutils | |
from os import DirSep | |
proc static_cast*[U](a: U, T: typedesc): T {.importcpp: "static_cast<'1>(#)".} | |
proc reinterpret_cast*[U](a: U, T: typedesc): T {.importcpp: "reinterpret_cast<'1>(#)".} | |
{.passC: "-std=c++11".} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## From: https://stackoverflow.com/questions/43648718/burnikel-and-ziegler-algorithm-2-not-working | |
############################################################################################# | |
import bitops, strformat | |
proc divmod*(x, y: SomeInteger): tuple[quot, rem: SomeInteger] {.noSideEffect, inline.}= | |
# hopefully the compiler fuse that in a single op | |
(x div y, x mod y) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template defineIntConstructor(typ: typedesc, name: untyped{nkIdent}) = | |
template name*(a: int64): typ = initInt[typ](a) | |
template name*(a: cstring): typ = initInt[typ](a) | |
template `+`*(a: typ, b: int{lit}): typ = a + initInt[typ](b) | |
template `+`*(a: int{lit}, b: typ): typ = initInt[typ](a) + b | |
template `-`*(a: typ, b: int{lit}): typ = a - initInt[typ](b) | |
template `-`*(a: int{lit}, b: typ): typ = initInt[typ](a) - b | |
defineIntConstructor(Int256, i256) | |
defineIntConstructor(Int512, i512) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Generated by Nim Compiler v0.18.1 */ | |
/* (c) 2018 Andreas Rumpf */ | |
/* The generated code is subject to the original license. */ | |
/* Compiled for: MacOSX, amd64, clang */ | |
/* Command for C compiler: | |
clang++ -c -w -I/Users/<User>/.nimble/pkgs/ttmath-0.5.0 -I'/Users/<User>/.choosenim/toolchains/nim-#devel/lib' -o /Users/<User>/Programming/Status/nimbus/tests/nimcache/nimbus_stack_test.o /Users/<User>/Programming/Status/nimbus/tests/nimcache/nimbus_stack_test.cpp */ | |
#define NIM_NEW_MANGLING_RULES | |
#define NIM_INTBITS 64 | |
#include "nimbase.h" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proc div3n2n(a12, a3, b, b1, b2: BaseUint, n: int): tuple[quot, rem: BaseUint] {.noinit, noSideEffect.} | |
# Forward declaration | |
proc div2n1n[T, U: BaseUint](a: T, b: U, n: int): tuple[quot, rem: U] {.noinit, noSideEffect.}= | |
## Divide a 2n-bit uint with a n-bit uint. | |
## This is part of the implementation of | |
## a recursive asymptotically fast division algorithm by Burnikel and Ziegler | |
if n <= 1000: | |
return divmod(a, b) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proc replaceSymNodes(ast: NimNode): NimNode = | |
# For undistinct we need to replace the sym "MpUintImpl" or "uint64" | |
# By a newIdentNode | |
proc inspect(node: NimNode): NimNode = | |
case node.kind: | |
of nnkSym: | |
return newIdentNode($node) | |
of {nnkIdent, nnkEmpty}: | |
return node | |
else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// author: prime ([email protected]) | |
// License: MIT License | |
#include <iostream> | |
#include <vector> | |
#include <bitset> | |
#include <x86intrin.h> | |
#include <boost/timer/timer.hpp> | |
inline __m256i bsr_256_8_naive(__m256i x); | |
inline __m256i bsr_256_8_cvtfloat(__m256i x); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type | |
MpUint64 = object | |
lo, hi: uint32 | |
# proc toMpUint64(u: uint64): MpUint64 {.noSideEffect, inline.}= | |
# cast[MpUint64](u) | |
# proc asMpUint64(u: uint64): MpUint64 {.noSideEffect, inline.}= | |
# (cast[ptr MpUint64](unsafeAddr u))[] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import macros | |
proc getSubType(T: NimNode): NimNode = | |
# Get the subtype T of an input | |
result = getTypeInst(T)[1] | |
proc injectParam(param: NimNode): NimNode = | |
nnkPragmaExpr.newTree( | |
newIdentNode($param), | |
nnkPragma.newTree(ident("inject")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import typetraits | |
type | |
BitsHolder[bits: static[int]] = object | |
template `div`[bits: static[int]](bh: typedesc[BitsHolder[bits]], n: static[int]): typedesc = | |
BitsHolder[bits div n] | |
type | |
MpUintImpl*[bh] = object |