Merge pull request #5 from Karaka-Management/develop

Develop
This commit is contained in:
Dennis Eichhorn 2024-04-24 20:02:54 +02:00 committed by GitHub
commit 4bd8c4217a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
43 changed files with 3909 additions and 827 deletions

View File

@ -30,33 +30,9 @@ jobs:
run: | run: |
chmod +x ./tests/test.sh chmod +x ./tests/test.sh
./tests/test.sh ./tests/test.sh
codestyle-tests: general_module_workflow_c:
runs-on: ubuntu-latest uses: Karaka-Management/Karaka/.github/workflows/c_template.yml@develop
if: "!contains(github.event.head_commit.message, 'NO_CI')" secrets:
strategy: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
fail-fast: false GH_PAT: ${{ secrets.GH_PAT }}
max-parallel: 3 CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
steps:
- name: Checkout Repository
uses: actions/checkout@main
with:
fetch-depth: 0
submodules: recursive
token: ${{ secrets.GH_TOKEN }}
- name: Checkout Build Repository
uses: actions/checkout@main
with:
fetch-depth: 1
ref: develop
repository: Karaka-Management/Build
path: Build
- name: Copy config file
run: |
cp ./Build/Config/.clang-format ./.clang-format
- name: Lint Code Base
uses: github/super-linter/slim@v5
env:
VALIDATE_ALL_CODEBASE: false
VALIDATE_CLANG_FORMAT : true
DEFAULT_BRANCH: develop
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

View File

@ -14,8 +14,8 @@
#include <stdlib.h> #include <stdlib.h>
#include "../DataStorage/Database/Connection/ConnectionAbstract.h" #include "../DataStorage/Database/Connection/ConnectionAbstract.h"
#include "../Utils/Parser/Json.h"
#include "../Threads/Thread.h" #include "../Threads/Thread.h"
#include "../Utils/Parser/Json.h"
namespace Application namespace Application
{ {
@ -24,6 +24,6 @@ namespace Application
nlohmann::json config; nlohmann::json config;
Threads::ThreadPool *pool; Threads::ThreadPool *pool;
} ApplicationAbstract; } ApplicationAbstract;
} } // namespace Application
#endif #endif

View File

@ -1,9 +1,9 @@
#ifndef HASH_MD5_H #ifndef HASH_MD5_H
#define HASH_MD5_H #define HASH_MD5_H
#include <string.h>
#include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h>
#include <string.h>
// https://www.rfc-editor.org/rfc/rfc1321 // https://www.rfc-editor.org/rfc/rfc1321
@ -12,19 +12,17 @@
#define H(x, y, z) ((x) ^ (y) ^ (z)) #define H(x, y, z) ((x) ^ (y) ^ (z))
#define I(x, y, z) ((y) ^ ((x) | ~(z))) #define I(x, y, z) ((y) ^ ((x) | ~(z)))
#define ROUND_OP(f, a, b, c, d, x, t, s) \ #define ROUND_OP(f, a, b, c, d, x, t, s) \
(a) += f((b), (c), (d)) + (x) + (t); \ (a) += f((b), (c), (d)) + (x) + (t); \
(a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \ (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \
(a) += (b); (a) += (b);
#define SET_BLOCK(n) \ #define SET_BLOCK(n) \
(ctx->block[(n)] = \ (ctx->block[(n)] = (uint32_t) ptr[(n) * 4] | ((uint32_t) ptr[(n) * 4 + 1] << 8) | \
(uint32_t)ptr[(n) * 4] | \ ((uint32_t) ptr[(n) * 4 + 2] << 16) | ((uint32_t) ptr[(n) * 4 + 3] << 24))
((uint32_t)ptr[(n) * 4 + 1] << 8) | \
((uint32_t)ptr[(n) * 4 + 2] << 16) | \
((uint32_t)ptr[(n) * 4 + 3] << 24))
namespace Hash { namespace Hash
{
typedef struct { typedef struct {
uint32_t lo, hi; uint32_t lo, hi;
uint32_t a, b, c, d; uint32_t a, b, c, d;
@ -173,13 +171,13 @@ namespace Hash {
} }
memcpy(&ctx->buffer[used], data, free); memcpy(&ctx->buffer[used], data, free);
data = (unsigned char *) data + free; data = (unsigned char *) data + free;
size -= free; size -= free;
body(ctx, ctx->buffer, 64); body(ctx, ctx->buffer, 64);
} }
if (size >= 64) { if (size >= 64) {
data = body(ctx, data, size & ~(size_t) 0x3f); data = body(ctx, data, size & ~(size_t) 0x3f);
size &= 0x3f; size &= 0x3f;
} }
@ -190,9 +188,9 @@ namespace Hash {
{ {
uint32_t used, free; uint32_t used, free;
used = ctx->lo & 0x3f; used = ctx->lo & 0x3f;
ctx->buffer[used++] = 0x80; ctx->buffer[used++] = 0x80;
free = 64 - used; free = 64 - used;
if (free < 8) { if (free < 8) {
memset(&ctx->buffer[used], 0, free); memset(&ctx->buffer[used], 0, free);
@ -203,28 +201,28 @@ namespace Hash {
memset(&ctx->buffer[used], 0, free - 8); memset(&ctx->buffer[used], 0, free - 8);
ctx->lo <<= 3; ctx->lo <<= 3;
ctx->buffer[56] = ctx->lo; ctx->buffer[56] = ctx->lo;
ctx->buffer[57] = ctx->lo >> 8; ctx->buffer[57] = ctx->lo >> 8;
ctx->buffer[58] = ctx->lo >> 16; ctx->buffer[58] = ctx->lo >> 16;
ctx->buffer[59] = ctx->lo >> 24; ctx->buffer[59] = ctx->lo >> 24;
ctx->buffer[60] = ctx->hi; ctx->buffer[60] = ctx->hi;
ctx->buffer[61] = ctx->hi >> 8; ctx->buffer[61] = ctx->hi >> 8;
ctx->buffer[62] = ctx->hi >> 16; ctx->buffer[62] = ctx->hi >> 16;
ctx->buffer[63] = ctx->hi >> 24; ctx->buffer[63] = ctx->hi >> 24;
body(ctx, ctx->buffer, 64); body(ctx, ctx->buffer, 64);
result[0] = ctx->a; result[0] = ctx->a;
result[1] = ctx->a >> 8; result[1] = ctx->a >> 8;
result[2] = ctx->a >> 16; result[2] = ctx->a >> 16;
result[3] = ctx->a >> 24; result[3] = ctx->a >> 24;
result[4] = ctx->b; result[4] = ctx->b;
result[5] = ctx->b >> 8; result[5] = ctx->b >> 8;
result[6] = ctx->b >> 16; result[6] = ctx->b >> 16;
result[7] = ctx->b >> 24; result[7] = ctx->b >> 24;
result[8] = ctx->c; result[8] = ctx->c;
result[9] = ctx->c >> 8; result[9] = ctx->c >> 8;
result[10] = ctx->c >> 16; result[10] = ctx->c >> 16;
result[11] = ctx->c >> 24; result[11] = ctx->c >> 24;
result[12] = ctx->d; result[12] = ctx->d;
@ -254,7 +252,7 @@ namespace Hash {
for (int i = 0; i < 16; ++i) { for (int i = 0; i < 16; ++i) {
hexHash[i * 2] = hexChars[hash[i] >> 4]; hexHash[i * 2] = hexChars[hash[i] >> 4];
hexHash[(i * 2) + 1] = hexChars[hash[i] & 0x0F]; hexHash[(i * 2) + 1] = hexChars[hash[i] & 0x0F];
} }
hexHash[16 * 2] = '\0'; hexHash[16 * 2] = '\0';
@ -262,7 +260,7 @@ namespace Hash {
return hexHash; return hexHash;
} }
}; }; // namespace Hash
#undef F #undef F
#undef G #undef G

View File

@ -140,9 +140,9 @@
#if __x86_64__ || _M_AMD64 #if __x86_64__ || _M_AMD64
#define meow_umm long long unsigned #define meow_umm long long unsigned
#define MeowU64From(A, I) (_mm_extract_epi64((A), (I))) #define MeowU64From(A, I) (_mm_extract_epi64((A), (I)))
#elif __i386__ || _M_IX86 #elif __i386__ || _M_IX86
#define meow_umm int unsigned #define meow_umm int unsigned
#define MeowU64From(A, I) (*(meow_u64 *)&(A)) #define MeowU64From(A, I) (*(meow_u64 *) &(A))
#else #else
#error Cannot determine architecture to use! #error Cannot determine architecture to use!
#endif #endif
@ -166,106 +166,102 @@
#define MEOW_PREFETCH_LIMIT 0x3ff #define MEOW_PREFETCH_LIMIT 0x3ff
#endif #endif
#define prefetcht0(A) _mm_prefetch((char *)(A), _MM_HINT_T0) #define prefetcht0(A) _mm_prefetch((char *) (A), _MM_HINT_T0)
#define movdqu(A, B) A = _mm_loadu_si128((__m128i *)(B)) #define movdqu(A, B) A = _mm_loadu_si128((__m128i *) (B))
#define movdqu_mem(A, B) _mm_storeu_si128((__m128i *)(A), B) #define movdqu_mem(A, B) _mm_storeu_si128((__m128i *) (A), B)
#define movq(A, B) A = _mm_set_epi64x(0, B); #define movq(A, B) A = _mm_set_epi64x(0, B);
#define aesdec(A, B) A = _mm_aesdec_si128(A, B) #define aesdec(A, B) A = _mm_aesdec_si128(A, B)
#define pshufb(A, B) A = _mm_shuffle_epi8(A, B) #define pshufb(A, B) A = _mm_shuffle_epi8(A, B)
#define pxor(A, B) A = _mm_xor_si128(A, B) #define pxor(A, B) A = _mm_xor_si128(A, B)
#define paddq(A, B) A = _mm_add_epi64(A, B) #define paddq(A, B) A = _mm_add_epi64(A, B)
#define pand(A, B) A = _mm_and_si128(A, B) #define pand(A, B) A = _mm_and_si128(A, B)
#define palignr(A, B, i) A = _mm_alignr_epi8(A, B, i) #define palignr(A, B, i) A = _mm_alignr_epi8(A, B, i)
#define pxor_clear(A, B) A = _mm_setzero_si128(); // NOTE(casey): pxor_clear is a nonsense thing that is only here because compilers don't detect xor(a, a) is clearing a :( #define pxor_clear(A, B) \
A = _mm_setzero_si128(); // NOTE(casey): pxor_clear is a nonsense thing that is only here because compilers
// don't detect xor(a, a) is clearing a :(
#define MEOW_MIX_REG(r1, r2, r3, r4, r5, i1, i2, i3, i4) \ #define MEOW_MIX_REG(r1, r2, r3, r4, r5, i1, i2, i3, i4) \
aesdec(r1, r2); \ aesdec(r1, r2); \
INSTRUCTION_REORDER_BARRIER; \ INSTRUCTION_REORDER_BARRIER; \
paddq(r3, i1); \ paddq(r3, i1); \
pxor(r2, i2); \ pxor(r2, i2); \
aesdec(r2, r4); \ aesdec(r2, r4); \
INSTRUCTION_REORDER_BARRIER; \ INSTRUCTION_REORDER_BARRIER; \
paddq(r5, i3); \ paddq(r5, i3); \
pxor(r4, i4); pxor(r4, i4);
#define MEOW_MIX(r1, r2, r3, r4, r5, ptr) \ #define MEOW_MIX(r1, r2, r3, r4, r5, ptr) \
MEOW_MIX_REG(r1, r2, r3, r4, r5, _mm_loadu_si128( (__m128i *) ((ptr) + 15) ), _mm_loadu_si128( (__m128i *) ((ptr) + 0) ), _mm_loadu_si128( (__m128i *) ((ptr) + 1) ), _mm_loadu_si128( (__m128i *) ((ptr) + 16) )) MEOW_MIX_REG(r1, r2, r3, r4, r5, _mm_loadu_si128((__m128i *) ((ptr) + 15)), \
_mm_loadu_si128((__m128i *) ((ptr) + 0)), _mm_loadu_si128((__m128i *) ((ptr) + 1)), \
_mm_loadu_si128((__m128i *) ((ptr) + 16)))
#define MEOW_SHUFFLE(r1, r2, r3, r4, r5, r6) \ #define MEOW_SHUFFLE(r1, r2, r3, r4, r5, r6) \
aesdec(r1, r4); \ aesdec(r1, r4); \
paddq(r2, r5); \ paddq(r2, r5); \
pxor(r4, r6); \ pxor(r4, r6); \
aesdec(r4, r2); \ aesdec(r4, r2); \
paddq(r5, r6); \ paddq(r5, r6); \
pxor(r2, r3) pxor(r2, r3)
#endif #endif
namespace Hash::Meow namespace Hash::Meow
{ {
#if MEOW_DUMP #if MEOW_DUMP
struct meow_dump struct meow_dump {
{ meow_u128 xmm[8];
meow_u128 xmm[8]; void *Ptr;
void *Ptr; char const *Title;
char const *Title;
};
extern "C" meow_dump *MeowDumpTo;
meow_dump *MeowDumpTo;
#define MEOW_DUMP_STATE(T, xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, ptr) \
if(MeowDumpTo) \
{ \
MeowDumpTo->xmm[0] = xmm0; \
MeowDumpTo->xmm[1] = xmm1; \
MeowDumpTo->xmm[2] = xmm2; \
MeowDumpTo->xmm[3] = xmm3; \
MeowDumpTo->xmm[4] = xmm4; \
MeowDumpTo->xmm[5] = xmm5; \
MeowDumpTo->xmm[6] = xmm6; \
MeowDumpTo->xmm[7] = xmm7; \
MeowDumpTo->Ptr = ptr; \
MeowDumpTo->Title = T; \
++MeowDumpTo; \
}
#else
#define MEOW_DUMP_STATE(...)
#endif
static meow_u8 MeowShiftAdjust[32] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
static meow_u8 MeowMaskLen[32] = {255,255,255,255, 255,255,255,255, 255,255,255,255, 255,255,255,255, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0};
// NOTE(casey): The default seed is now a "nothing-up-our-sleeves" number for good measure. You may verify that it is just an encoding of Pi.
static meow_u8 MeowDefaultSeed[128] =
{
0x32, 0x43, 0xF6, 0xA8, 0x88, 0x5A, 0x30, 0x8D,
0x31, 0x31, 0x98, 0xA2, 0xE0, 0x37, 0x07, 0x34,
0x4A, 0x40, 0x93, 0x82, 0x22, 0x99, 0xF3, 0x1D,
0x00, 0x82, 0xEF, 0xA9, 0x8E, 0xC4, 0xE6, 0xC8,
0x94, 0x52, 0x82, 0x1E, 0x63, 0x8D, 0x01, 0x37,
0x7B, 0xE5, 0x46, 0x6C, 0xF3, 0x4E, 0x90, 0xC6,
0xCC, 0x0A, 0xC2, 0x9B, 0x7C, 0x97, 0xC5, 0x0D,
0xD3, 0xF8, 0x4D, 0x5B, 0x5B, 0x54, 0x70, 0x91,
0x79, 0x21, 0x6D, 0x5D, 0x98, 0x97, 0x9F, 0xB1,
0xBD, 0x13, 0x10, 0xBA, 0x69, 0x8D, 0xFB, 0x5A,
0xC2, 0xFF, 0xD7, 0x2D, 0xBD, 0x01, 0xAD, 0xFB,
0x7B, 0x8E, 0x1A, 0xFE, 0xD6, 0xA2, 0x67, 0xE9,
0x6B, 0xA7, 0xC9, 0x04, 0x5F, 0x12, 0xC7, 0xF9,
0x92, 0x4A, 0x19, 0x94, 0x7B, 0x39, 0x16, 0xCF,
0x70, 0x80, 0x1F, 0x2E, 0x28, 0x58, 0xEF, 0xC1,
0x66, 0x36, 0x92, 0x0D, 0x87, 0x15, 0x74, 0xE6
}; };
extern "C" meow_dump *MeowDumpTo;
meow_dump *MeowDumpTo;
#define MEOW_DUMP_STATE(T, xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, ptr) \
if (MeowDumpTo) { \
MeowDumpTo->xmm[0] = xmm0; \
MeowDumpTo->xmm[1] = xmm1; \
MeowDumpTo->xmm[2] = xmm2; \
MeowDumpTo->xmm[3] = xmm3; \
MeowDumpTo->xmm[4] = xmm4; \
MeowDumpTo->xmm[5] = xmm5; \
MeowDumpTo->xmm[6] = xmm6; \
MeowDumpTo->xmm[7] = xmm7; \
MeowDumpTo->Ptr = ptr; \
MeowDumpTo->Title = T; \
++MeowDumpTo; \
}
#else
#define MEOW_DUMP_STATE(...)
#endif
static meow_u8 MeowShiftAdjust[32] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
static meow_u8 MeowMaskLen[32] = {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
// NOTE(casey): The default seed is now a "nothing-up-our-sleeves" number for good measure. You may verify that it
// is just an encoding of Pi.
static meow_u8 MeowDefaultSeed[128] = {
0x32, 0x43, 0xF6, 0xA8, 0x88, 0x5A, 0x30, 0x8D, 0x31, 0x31, 0x98, 0xA2, 0xE0, 0x37, 0x07, 0x34,
0x4A, 0x40, 0x93, 0x82, 0x22, 0x99, 0xF3, 0x1D, 0x00, 0x82, 0xEF, 0xA9, 0x8E, 0xC4, 0xE6, 0xC8,
0x94, 0x52, 0x82, 0x1E, 0x63, 0x8D, 0x01, 0x37, 0x7B, 0xE5, 0x46, 0x6C, 0xF3, 0x4E, 0x90, 0xC6,
0xCC, 0x0A, 0xC2, 0x9B, 0x7C, 0x97, 0xC5, 0x0D, 0xD3, 0xF8, 0x4D, 0x5B, 0x5B, 0x54, 0x70, 0x91,
0x79, 0x21, 0x6D, 0x5D, 0x98, 0x97, 0x9F, 0xB1, 0xBD, 0x13, 0x10, 0xBA, 0x69, 0x8D, 0xFB, 0x5A,
0xC2, 0xFF, 0xD7, 0x2D, 0xBD, 0x01, 0xAD, 0xFB, 0x7B, 0x8E, 0x1A, 0xFE, 0xD6, 0xA2, 0x67, 0xE9,
0x6B, 0xA7, 0xC9, 0x04, 0x5F, 0x12, 0xC7, 0xF9, 0x92, 0x4A, 0x19, 0x94, 0x7B, 0x39, 0x16, 0xCF,
0x70, 0x80, 0x1F, 0x2E, 0x28, 0x58, 0xEF, 0xC1, 0x66, 0x36, 0x92, 0x0D, 0x87, 0x15, 0x74, 0xE6};
// //
// NOTE(casey): Single block version // NOTE(casey): Single block version
// //
static meow_u128 static meow_u128 MeowHash(void *Seed128Init, meow_umm Len, void *SourceInit)
MeowHash(void *Seed128Init, meow_umm Len, void *SourceInit)
{ {
meow_u128 xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7; // NOTE(casey): xmm0-xmm7 are the hash accumulation lanes meow_u128 xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6,
meow_u128 xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15; // NOTE(casey): xmm8-xmm15 hold values to be appended (residual, length) xmm7; // NOTE(casey): xmm0-xmm7 are the hash accumulation lanes
meow_u128 xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14,
xmm15; // NOTE(casey): xmm8-xmm15 hold values to be appended (residual, length)
meow_u8 *rax = (meow_u8 *)SourceInit; meow_u8 *rax = (meow_u8 *) SourceInit;
meow_u8 *rcx = (meow_u8 *)Seed128Init; meow_u8 *rcx = (meow_u8 *) Seed128Init;
// //
// NOTE(casey): Seed the eight hash registers // NOTE(casey): Seed the eight hash registers
@ -288,41 +284,38 @@ namespace Hash::Meow
// //
meow_umm BlockCount = (Len >> 8); meow_umm BlockCount = (Len >> 8);
if(BlockCount > MEOW_PREFETCH_LIMIT) if (BlockCount > MEOW_PREFETCH_LIMIT) {
{ // NOTE(casey): For large input, modern Intel x64's can't hit full speed without prefetching, so we use this
// NOTE(casey): For large input, modern Intel x64's can't hit full speed without prefetching, so we use this loop // loop
while(BlockCount--) while (BlockCount--) {
{
prefetcht0(rax + MEOW_PREFETCH + 0x00); prefetcht0(rax + MEOW_PREFETCH + 0x00);
prefetcht0(rax + MEOW_PREFETCH + 0x40); prefetcht0(rax + MEOW_PREFETCH + 0x40);
prefetcht0(rax + MEOW_PREFETCH + 0x80); prefetcht0(rax + MEOW_PREFETCH + 0x80);
prefetcht0(rax + MEOW_PREFETCH + 0xc0); prefetcht0(rax + MEOW_PREFETCH + 0xc0);
MEOW_MIX(xmm0,xmm4,xmm6,xmm1,xmm2, rax + 0x00); MEOW_MIX(xmm0, xmm4, xmm6, xmm1, xmm2, rax + 0x00);
MEOW_MIX(xmm1,xmm5,xmm7,xmm2,xmm3, rax + 0x20); MEOW_MIX(xmm1, xmm5, xmm7, xmm2, xmm3, rax + 0x20);
MEOW_MIX(xmm2,xmm6,xmm0,xmm3,xmm4, rax + 0x40); MEOW_MIX(xmm2, xmm6, xmm0, xmm3, xmm4, rax + 0x40);
MEOW_MIX(xmm3,xmm7,xmm1,xmm4,xmm5, rax + 0x60); MEOW_MIX(xmm3, xmm7, xmm1, xmm4, xmm5, rax + 0x60);
MEOW_MIX(xmm4,xmm0,xmm2,xmm5,xmm6, rax + 0x80); MEOW_MIX(xmm4, xmm0, xmm2, xmm5, xmm6, rax + 0x80);
MEOW_MIX(xmm5,xmm1,xmm3,xmm6,xmm7, rax + 0xa0); MEOW_MIX(xmm5, xmm1, xmm3, xmm6, xmm7, rax + 0xa0);
MEOW_MIX(xmm6,xmm2,xmm4,xmm7,xmm0, rax + 0xc0); MEOW_MIX(xmm6, xmm2, xmm4, xmm7, xmm0, rax + 0xc0);
MEOW_MIX(xmm7,xmm3,xmm5,xmm0,xmm1, rax + 0xe0); MEOW_MIX(xmm7, xmm3, xmm5, xmm0, xmm1, rax + 0xe0);
rax += 0x100; rax += 0x100;
} }
} } else {
else // NOTE(casey): For small input, modern Intel x64's can't hit full speed _with_ prefetching (because of port
{ // pressure), so we use this loop.
// NOTE(casey): For small input, modern Intel x64's can't hit full speed _with_ prefetching (because of port pressure), so we use this loop. while (BlockCount--) {
while(BlockCount--) MEOW_MIX(xmm0, xmm4, xmm6, xmm1, xmm2, rax + 0x00);
{ MEOW_MIX(xmm1, xmm5, xmm7, xmm2, xmm3, rax + 0x20);
MEOW_MIX(xmm0,xmm4,xmm6,xmm1,xmm2, rax + 0x00); MEOW_MIX(xmm2, xmm6, xmm0, xmm3, xmm4, rax + 0x40);
MEOW_MIX(xmm1,xmm5,xmm7,xmm2,xmm3, rax + 0x20); MEOW_MIX(xmm3, xmm7, xmm1, xmm4, xmm5, rax + 0x60);
MEOW_MIX(xmm2,xmm6,xmm0,xmm3,xmm4, rax + 0x40); MEOW_MIX(xmm4, xmm0, xmm2, xmm5, xmm6, rax + 0x80);
MEOW_MIX(xmm3,xmm7,xmm1,xmm4,xmm5, rax + 0x60); MEOW_MIX(xmm5, xmm1, xmm3, xmm6, xmm7, rax + 0xa0);
MEOW_MIX(xmm4,xmm0,xmm2,xmm5,xmm6, rax + 0x80); MEOW_MIX(xmm6, xmm2, xmm4, xmm7, xmm0, rax + 0xc0);
MEOW_MIX(xmm5,xmm1,xmm3,xmm6,xmm7, rax + 0xa0); MEOW_MIX(xmm7, xmm3, xmm5, xmm0, xmm1, rax + 0xe0);
MEOW_MIX(xmm6,xmm2,xmm4,xmm7,xmm0, rax + 0xc0);
MEOW_MIX(xmm7,xmm3,xmm5,xmm0,xmm1, rax + 0xe0);
rax += 0x100; rax += 0x100;
} }
@ -345,15 +338,15 @@ namespace Hash::Meow
// //
// NOTE(casey): First, we have to load the part that is _not_ 16-byte aligned // NOTE(casey): First, we have to load the part that is _not_ 16-byte aligned
meow_u8 *Last = (meow_u8 *)SourceInit + (Len & ~0xf); meow_u8 *Last = (meow_u8 *) SourceInit + (Len & ~0xf);
int unsigned Len8 = (Len & 0xf); int unsigned Len8 = (Len & 0xf);
if(Len8) if (Len8) {
{
// NOTE(casey): Load the mask early // NOTE(casey): Load the mask early
movdqu(xmm8, &MeowMaskLen[0x10 - Len8]); movdqu(xmm8, &MeowMaskLen[0x10 - Len8]);
meow_u8 *LastOk = (meow_u8*)((((meow_umm)(((meow_u8 *)SourceInit)+Len - 1)) | (MEOW_PAGESIZE - 1)) - 16); meow_u8 *LastOk =
int Align = (Last > LastOk) ? ((int)(meow_umm)Last) & 0xf : 0; (meow_u8 *) ((((meow_umm) (((meow_u8 *) SourceInit) + Len - 1)) | (MEOW_PAGESIZE - 1)) - 16);
int Align = (Last > LastOk) ? ((int) (meow_umm) Last) & 0xf : 0;
movdqu(xmm10, &MeowShiftAdjust[Align]); movdqu(xmm10, &MeowShiftAdjust[Align]);
movdqu(xmm9, Last - Align); movdqu(xmm9, Last - Align);
pshufb(xmm9, xmm10); pshufb(xmm9, xmm10);
@ -363,8 +356,7 @@ namespace Hash::Meow
} }
// NOTE(casey): Next, we have to load the part that _is_ 16-byte aligned // NOTE(casey): Next, we have to load the part that _is_ 16-byte aligned
if(Len & 0x10) if (Len & 0x10) {
{
xmm11 = xmm9; xmm11 = xmm9;
movdqu(xmm9, Last - 0x10); movdqu(xmm9, Last - 0x10);
} }
@ -373,7 +365,7 @@ namespace Hash::Meow
// NOTE(casey): Construct the residual and length injests // NOTE(casey): Construct the residual and length injests
// //
xmm8 = xmm9; xmm8 = xmm9;
xmm10 = xmm9; xmm10 = xmm9;
palignr(xmm8, xmm11, 15); palignr(xmm8, xmm11, 15);
palignr(xmm10, xmm11, 1); palignr(xmm10, xmm11, 1);
@ -390,11 +382,12 @@ namespace Hash::Meow
MEOW_DUMP_STATE("Residuals", xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 0); MEOW_DUMP_STATE("Residuals", xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 0);
// NOTE(casey): To maintain the mix-down pattern, we always Meow Mix the less-than-32-byte residual, even if it was empty // NOTE(casey): To maintain the mix-down pattern, we always Meow Mix the less-than-32-byte residual, even if it
MEOW_MIX_REG(xmm0, xmm4, xmm6, xmm1, xmm2, xmm8, xmm9, xmm10, xmm11); // was empty
MEOW_MIX_REG(xmm0, xmm4, xmm6, xmm1, xmm2, xmm8, xmm9, xmm10, xmm11);
// NOTE(casey): Append the length, to avoid problems with our 32-byte padding // NOTE(casey): Append the length, to avoid problems with our 32-byte padding
MEOW_MIX_REG(xmm1, xmm5, xmm7, xmm2, xmm3, xmm12, xmm13, xmm14, xmm15); MEOW_MIX_REG(xmm1, xmm5, xmm7, xmm2, xmm3, xmm12, xmm13, xmm14, xmm15);
MEOW_DUMP_STATE("PostAppend", xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, 0); MEOW_DUMP_STATE("PostAppend", xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, 0);
@ -402,19 +395,40 @@ namespace Hash::Meow
// NOTE(casey): Hash all full 32-byte blocks // NOTE(casey): Hash all full 32-byte blocks
// //
int unsigned LaneCount = (Len >> 5) & 0x7; int unsigned LaneCount = (Len >> 5) & 0x7;
if(LaneCount == 0) goto MixDown; MEOW_MIX(xmm2,xmm6,xmm0,xmm3,xmm4, rax + 0x00); --LaneCount; if (LaneCount == 0)
if(LaneCount == 0) goto MixDown; MEOW_MIX(xmm3,xmm7,xmm1,xmm4,xmm5, rax + 0x20); --LaneCount; goto MixDown;
if(LaneCount == 0) goto MixDown; MEOW_MIX(xmm4,xmm0,xmm2,xmm5,xmm6, rax + 0x40); --LaneCount; MEOW_MIX(xmm2, xmm6, xmm0, xmm3, xmm4, rax + 0x00);
if(LaneCount == 0) goto MixDown; MEOW_MIX(xmm5,xmm1,xmm3,xmm6,xmm7, rax + 0x60); --LaneCount; --LaneCount;
if(LaneCount == 0) goto MixDown; MEOW_MIX(xmm6,xmm2,xmm4,xmm7,xmm0, rax + 0x80); --LaneCount; if (LaneCount == 0)
if(LaneCount == 0) goto MixDown; MEOW_MIX(xmm7,xmm3,xmm5,xmm0,xmm1, rax + 0xa0); --LaneCount; goto MixDown;
if(LaneCount == 0) goto MixDown; MEOW_MIX(xmm0,xmm4,xmm6,xmm1,xmm2, rax + 0xc0); --LaneCount; MEOW_MIX(xmm3, xmm7, xmm1, xmm4, xmm5, rax + 0x20);
--LaneCount;
if (LaneCount == 0)
goto MixDown;
MEOW_MIX(xmm4, xmm0, xmm2, xmm5, xmm6, rax + 0x40);
--LaneCount;
if (LaneCount == 0)
goto MixDown;
MEOW_MIX(xmm5, xmm1, xmm3, xmm6, xmm7, rax + 0x60);
--LaneCount;
if (LaneCount == 0)
goto MixDown;
MEOW_MIX(xmm6, xmm2, xmm4, xmm7, xmm0, rax + 0x80);
--LaneCount;
if (LaneCount == 0)
goto MixDown;
MEOW_MIX(xmm7, xmm3, xmm5, xmm0, xmm1, rax + 0xa0);
--LaneCount;
if (LaneCount == 0)
goto MixDown;
MEOW_MIX(xmm0, xmm4, xmm6, xmm1, xmm2, rax + 0xc0);
--LaneCount;
// //
// NOTE(casey): Mix the eight lanes down to one 128-bit hash // NOTE(casey): Mix the eight lanes down to one 128-bit hash
// //
MixDown: MixDown:
MEOW_DUMP_STATE("PostLanes", xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, 0); MEOW_DUMP_STATE("PostLanes", xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, 0);
@ -443,15 +457,14 @@ namespace Hash::Meow
MEOW_DUMP_STATE("PostFold", xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, 0); MEOW_DUMP_STATE("PostFold", xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, 0);
return(xmm0); return (xmm0);
} }
// //
// NOTE(casey): Streaming construction // NOTE(casey): Streaming construction
// //
typedef struct meow_state typedef struct meow_state {
{
meow_u128 xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7; meow_u128 xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7;
meow_u64 TotalLengthInBytes; meow_u64 TotalLengthInBytes;
@ -461,10 +474,9 @@ namespace Hash::Meow
meow_u128 Pad[2]; // NOTE(casey): So we know we can over-read Buffer as necessary meow_u128 Pad[2]; // NOTE(casey): So we know we can over-read Buffer as necessary
} meow_state; } meow_state;
static void static void MeowBegin(meow_state *State, void *Seed128)
MeowBegin(meow_state *State, void *Seed128)
{ {
meow_u8 *rcx = (meow_u8 *)Seed128; meow_u8 *rcx = (meow_u8 *) Seed128;
movdqu(State->xmm0, rcx + 0x00); movdqu(State->xmm0, rcx + 0x00);
movdqu(State->xmm1, rcx + 0x10); movdqu(State->xmm1, rcx + 0x10);
@ -475,14 +487,14 @@ namespace Hash::Meow
movdqu(State->xmm6, rcx + 0x60); movdqu(State->xmm6, rcx + 0x60);
movdqu(State->xmm7, rcx + 0x70); movdqu(State->xmm7, rcx + 0x70);
MEOW_DUMP_STATE("Seed", State->xmm0, State->xmm1, State->xmm2, State->xmm3, State->xmm4, State->xmm5, State->xmm6, State->xmm7, 0); MEOW_DUMP_STATE("Seed", State->xmm0, State->xmm1, State->xmm2, State->xmm3, State->xmm4, State->xmm5,
State->xmm6, State->xmm7, 0);
State->BufferLen = 0; State->BufferLen = 0;
State->TotalLengthInBytes = 0; State->TotalLengthInBytes = 0;
} }
static void static void MeowAbsorbBlocks(meow_state *State, meow_umm BlockCount, meow_u8 *rax)
MeowAbsorbBlocks(meow_state *State, meow_umm BlockCount, meow_u8 *rax)
{ {
meow_u128 xmm0 = State->xmm0; meow_u128 xmm0 = State->xmm0;
meow_u128 xmm1 = State->xmm1; meow_u128 xmm1 = State->xmm1;
@ -493,39 +505,34 @@ namespace Hash::Meow
meow_u128 xmm6 = State->xmm6; meow_u128 xmm6 = State->xmm6;
meow_u128 xmm7 = State->xmm7; meow_u128 xmm7 = State->xmm7;
if(BlockCount > MEOW_PREFETCH_LIMIT) if (BlockCount > MEOW_PREFETCH_LIMIT) {
{ while (BlockCount--) {
while(BlockCount--)
{
prefetcht0(rax + MEOW_PREFETCH + 0x00); prefetcht0(rax + MEOW_PREFETCH + 0x00);
prefetcht0(rax + MEOW_PREFETCH + 0x40); prefetcht0(rax + MEOW_PREFETCH + 0x40);
prefetcht0(rax + MEOW_PREFETCH + 0x80); prefetcht0(rax + MEOW_PREFETCH + 0x80);
prefetcht0(rax + MEOW_PREFETCH + 0xc0); prefetcht0(rax + MEOW_PREFETCH + 0xc0);
MEOW_MIX(xmm0,xmm4,xmm6,xmm1,xmm2, rax + 0x00); MEOW_MIX(xmm0, xmm4, xmm6, xmm1, xmm2, rax + 0x00);
MEOW_MIX(xmm1,xmm5,xmm7,xmm2,xmm3, rax + 0x20); MEOW_MIX(xmm1, xmm5, xmm7, xmm2, xmm3, rax + 0x20);
MEOW_MIX(xmm2,xmm6,xmm0,xmm3,xmm4, rax + 0x40); MEOW_MIX(xmm2, xmm6, xmm0, xmm3, xmm4, rax + 0x40);
MEOW_MIX(xmm3,xmm7,xmm1,xmm4,xmm5, rax + 0x60); MEOW_MIX(xmm3, xmm7, xmm1, xmm4, xmm5, rax + 0x60);
MEOW_MIX(xmm4,xmm0,xmm2,xmm5,xmm6, rax + 0x80); MEOW_MIX(xmm4, xmm0, xmm2, xmm5, xmm6, rax + 0x80);
MEOW_MIX(xmm5,xmm1,xmm3,xmm6,xmm7, rax + 0xa0); MEOW_MIX(xmm5, xmm1, xmm3, xmm6, xmm7, rax + 0xa0);
MEOW_MIX(xmm6,xmm2,xmm4,xmm7,xmm0, rax + 0xc0); MEOW_MIX(xmm6, xmm2, xmm4, xmm7, xmm0, rax + 0xc0);
MEOW_MIX(xmm7,xmm3,xmm5,xmm0,xmm1, rax + 0xe0); MEOW_MIX(xmm7, xmm3, xmm5, xmm0, xmm1, rax + 0xe0);
rax += 0x100; rax += 0x100;
} }
} } else {
else while (BlockCount--) {
{ MEOW_MIX(xmm0, xmm4, xmm6, xmm1, xmm2, rax + 0x00);
while(BlockCount--) MEOW_MIX(xmm1, xmm5, xmm7, xmm2, xmm3, rax + 0x20);
{ MEOW_MIX(xmm2, xmm6, xmm0, xmm3, xmm4, rax + 0x40);
MEOW_MIX(xmm0,xmm4,xmm6,xmm1,xmm2, rax + 0x00); MEOW_MIX(xmm3, xmm7, xmm1, xmm4, xmm5, rax + 0x60);
MEOW_MIX(xmm1,xmm5,xmm7,xmm2,xmm3, rax + 0x20); MEOW_MIX(xmm4, xmm0, xmm2, xmm5, xmm6, rax + 0x80);
MEOW_MIX(xmm2,xmm6,xmm0,xmm3,xmm4, rax + 0x40); MEOW_MIX(xmm5, xmm1, xmm3, xmm6, xmm7, rax + 0xa0);
MEOW_MIX(xmm3,xmm7,xmm1,xmm4,xmm5, rax + 0x60); MEOW_MIX(xmm6, xmm2, xmm4, xmm7, xmm0, rax + 0xc0);
MEOW_MIX(xmm4,xmm0,xmm2,xmm5,xmm6, rax + 0x80); MEOW_MIX(xmm7, xmm3, xmm5, xmm0, xmm1, rax + 0xe0);
MEOW_MIX(xmm5,xmm1,xmm3,xmm6,xmm7, rax + 0xa0);
MEOW_MIX(xmm6,xmm2,xmm4,xmm7,xmm0, rax + 0xc0);
MEOW_MIX(xmm7,xmm3,xmm5,xmm0,xmm1, rax + 0xe0);
rax += 0x100; rax += 0x100;
} }
@ -541,29 +548,24 @@ namespace Hash::Meow
State->xmm7 = xmm7; State->xmm7 = xmm7;
} }
static void static void MeowAbsorb(meow_state *State, meow_umm Len, void *SourceInit)
MeowAbsorb(meow_state *State, meow_umm Len, void *SourceInit)
{ {
State->TotalLengthInBytes += Len; State->TotalLengthInBytes += Len;
meow_u8 *Source = (meow_u8 *)SourceInit; meow_u8 *Source = (meow_u8 *) SourceInit;
// NOTE(casey): Handle any buffered residual // NOTE(casey): Handle any buffered residual
if(State->BufferLen) if (State->BufferLen) {
{
int unsigned Fill = (sizeof(State->Buffer) - State->BufferLen); int unsigned Fill = (sizeof(State->Buffer) - State->BufferLen);
if(Fill > Len) if (Fill > Len) {
{ Fill = (int unsigned) Len;
Fill = (int unsigned)Len;
} }
Len -= Fill; Len -= Fill;
while(Fill--) while (Fill--) {
{
State->Buffer[State->BufferLen++] = *Source++; State->Buffer[State->BufferLen++] = *Source++;
} }
if(State->BufferLen == sizeof(State->Buffer)) if (State->BufferLen == sizeof(State->Buffer)) {
{
MeowAbsorbBlocks(State, 1, State->Buffer); MeowAbsorbBlocks(State, 1, State->Buffer);
State->BufferLen = 0; State->BufferLen = 0;
} }
@ -571,21 +573,19 @@ namespace Hash::Meow
// NOTE(casey): Handle any full blocks // NOTE(casey): Handle any full blocks
meow_u64 BlockCount = (Len >> 8); meow_u64 BlockCount = (Len >> 8);
meow_u64 Advance = (BlockCount << 8); meow_u64 Advance = (BlockCount << 8);
MeowAbsorbBlocks(State, BlockCount, Source); MeowAbsorbBlocks(State, BlockCount, Source);
Len -= Advance; Len -= Advance;
Source += Advance; Source += Advance;
// NOTE(casey): Store residual // NOTE(casey): Store residual
while(Len--) while (Len--) {
{
State->Buffer[State->BufferLen++] = *Source++; State->Buffer[State->BufferLen++] = *Source++;
} }
} }
static meow_u128 static meow_u128 MeowEnd(meow_state *State, meow_u8 *Store128)
MeowEnd(meow_state *State, meow_u8 *Store128)
{ {
meow_umm Len = State->TotalLengthInBytes; meow_umm Len = State->TotalLengthInBytes;
@ -605,22 +605,20 @@ namespace Hash::Meow
pxor_clear(xmm9, xmm9); pxor_clear(xmm9, xmm9);
pxor_clear(xmm11, xmm11); pxor_clear(xmm11, xmm11);
meow_u8 *Last = (meow_u8 *)rax + (Len & 0xf0); meow_u8 *Last = (meow_u8 *) rax + (Len & 0xf0);
int unsigned Len8 = (Len & 0xf); int unsigned Len8 = (Len & 0xf);
if(Len8) if (Len8) {
{
movdqu(xmm8, &MeowMaskLen[0x10 - Len8]); movdqu(xmm8, &MeowMaskLen[0x10 - Len8]);
movdqu(xmm9, Last); movdqu(xmm9, Last);
pand(xmm9, xmm8); pand(xmm9, xmm8);
} }
if(Len & 0x10) if (Len & 0x10) {
{
xmm11 = xmm9; xmm11 = xmm9;
movdqu(xmm9, Last - 0x10); movdqu(xmm9, Last - 0x10);
} }
xmm8 = xmm9; xmm8 = xmm9;
xmm10 = xmm9; xmm10 = xmm9;
palignr(xmm8, xmm11, 15); palignr(xmm8, xmm11, 15);
palignr(xmm10, xmm11, 1); palignr(xmm10, xmm11, 1);
@ -635,11 +633,12 @@ namespace Hash::Meow
MEOW_DUMP_STATE("PostBlocks", xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, 0); MEOW_DUMP_STATE("PostBlocks", xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, 0);
MEOW_DUMP_STATE("Residuals", xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 0); MEOW_DUMP_STATE("Residuals", xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 0);
// NOTE(casey): To maintain the mix-down pattern, we always Meow Mix the less-than-32-byte residual, even if it was empty // NOTE(casey): To maintain the mix-down pattern, we always Meow Mix the less-than-32-byte residual, even if it
MEOW_MIX_REG(xmm0, xmm4, xmm6, xmm1, xmm2, xmm8, xmm9, xmm10, xmm11); // was empty
MEOW_MIX_REG(xmm0, xmm4, xmm6, xmm1, xmm2, xmm8, xmm9, xmm10, xmm11);
// NOTE(casey): Append the length, to avoid problems with our 32-byte padding // NOTE(casey): Append the length, to avoid problems with our 32-byte padding
MEOW_MIX_REG(xmm1, xmm5, xmm7, xmm2, xmm3, xmm12, xmm13, xmm14, xmm15); MEOW_MIX_REG(xmm1, xmm5, xmm7, xmm2, xmm3, xmm12, xmm13, xmm14, xmm15);
MEOW_DUMP_STATE("PostAppend", xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, 0); MEOW_DUMP_STATE("PostAppend", xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, 0);
@ -647,19 +646,40 @@ namespace Hash::Meow
// NOTE(casey): Hash all full 32-byte blocks // NOTE(casey): Hash all full 32-byte blocks
// //
int unsigned LaneCount = (Len >> 5) & 0x7; int unsigned LaneCount = (Len >> 5) & 0x7;
if(LaneCount == 0) goto MixDown; MEOW_MIX(xmm2,xmm6,xmm0,xmm3,xmm4, rax + 0x00); --LaneCount; if (LaneCount == 0)
if(LaneCount == 0) goto MixDown; MEOW_MIX(xmm3,xmm7,xmm1,xmm4,xmm5, rax + 0x20); --LaneCount; goto MixDown;
if(LaneCount == 0) goto MixDown; MEOW_MIX(xmm4,xmm0,xmm2,xmm5,xmm6, rax + 0x40); --LaneCount; MEOW_MIX(xmm2, xmm6, xmm0, xmm3, xmm4, rax + 0x00);
if(LaneCount == 0) goto MixDown; MEOW_MIX(xmm5,xmm1,xmm3,xmm6,xmm7, rax + 0x60); --LaneCount; --LaneCount;
if(LaneCount == 0) goto MixDown; MEOW_MIX(xmm6,xmm2,xmm4,xmm7,xmm0, rax + 0x80); --LaneCount; if (LaneCount == 0)
if(LaneCount == 0) goto MixDown; MEOW_MIX(xmm7,xmm3,xmm5,xmm0,xmm1, rax + 0xa0); --LaneCount; goto MixDown;
if(LaneCount == 0) goto MixDown; MEOW_MIX(xmm0,xmm4,xmm6,xmm1,xmm2, rax + 0xc0); --LaneCount; MEOW_MIX(xmm3, xmm7, xmm1, xmm4, xmm5, rax + 0x20);
--LaneCount;
if (LaneCount == 0)
goto MixDown;
MEOW_MIX(xmm4, xmm0, xmm2, xmm5, xmm6, rax + 0x40);
--LaneCount;
if (LaneCount == 0)
goto MixDown;
MEOW_MIX(xmm5, xmm1, xmm3, xmm6, xmm7, rax + 0x60);
--LaneCount;
if (LaneCount == 0)
goto MixDown;
MEOW_MIX(xmm6, xmm2, xmm4, xmm7, xmm0, rax + 0x80);
--LaneCount;
if (LaneCount == 0)
goto MixDown;
MEOW_MIX(xmm7, xmm3, xmm5, xmm0, xmm1, rax + 0xa0);
--LaneCount;
if (LaneCount == 0)
goto MixDown;
MEOW_MIX(xmm0, xmm4, xmm6, xmm1, xmm2, rax + 0xc0);
--LaneCount;
// //
// NOTE(casey): Mix the eight lanes down to one 128-bit hash // NOTE(casey): Mix the eight lanes down to one 128-bit hash
// //
MixDown: MixDown:
MEOW_DUMP_STATE("PostLanes", xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, 0); MEOW_DUMP_STATE("PostLanes", xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, 0);
@ -678,8 +698,7 @@ namespace Hash::Meow
MEOW_DUMP_STATE("PostMix", xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, 0); MEOW_DUMP_STATE("PostMix", xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, 0);
if(Store128) if (Store128) {
{
movdqu_mem(Store128 + 0x00, xmm0); movdqu_mem(Store128 + 0x00, xmm0);
movdqu_mem(Store128 + 0x10, xmm1); movdqu_mem(Store128 + 0x10, xmm1);
movdqu_mem(Store128 + 0x20, xmm2); movdqu_mem(Store128 + 0x20, xmm2);
@ -700,7 +719,7 @@ namespace Hash::Meow
MEOW_DUMP_STATE("PostFold", xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, 0); MEOW_DUMP_STATE("PostFold", xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, 0);
return(xmm0); return (xmm0);
} }
// //
@ -710,17 +729,16 @@ namespace Hash::Meow
// need to create a new seed. // need to create a new seed.
// //
static void static void MeowExpandSeed(meow_umm InputLen, void *Input, meow_u8 *SeedResult)
MeowExpandSeed(meow_umm InputLen, void *Input, meow_u8 *SeedResult)
{ {
meow_state State; meow_state State;
meow_u64 LengthTab = (meow_u64)InputLen; // NOTE(casey): We need to always injest 8-byte lengths exactly, even on 32-bit builds, to ensure identical results meow_u64 LengthTab = (meow_u64) InputLen; // NOTE(casey): We need to always injest 8-byte lengths exactly, even
// on 32-bit builds, to ensure identical results
meow_umm InjestCount = (256 / InputLen) + 2; meow_umm InjestCount = (256 / InputLen) + 2;
MeowBegin(&State, MeowDefaultSeed); MeowBegin(&State, MeowDefaultSeed);
MeowAbsorb(&State, sizeof(LengthTab), &LengthTab); MeowAbsorb(&State, sizeof(LengthTab), &LengthTab);
while(InjestCount--) while (InjestCount--) {
{
MeowAbsorb(&State, InputLen, Input); MeowAbsorb(&State, InputLen, Input);
} }
MeowEnd(&State, SeedResult); MeowEnd(&State, SeedResult);
@ -730,15 +748,12 @@ namespace Hash::Meow
{ {
char *str = (char *) malloc((4 * 8 + 4 + 1) * sizeof(char)); char *str = (char *) malloc((4 * 8 + 4 + 1) * sizeof(char));
sprintf(str, "%08X-%08X-%08X-%08X", sprintf(str, "%08X-%08X-%08X-%08X", MeowU32From(Hash, 3), MeowU32From(Hash, 2), MeowU32From(Hash, 1),
MeowU32From(Hash, 3),
MeowU32From(Hash, 2),
MeowU32From(Hash, 1),
MeowU32From(Hash, 0)); MeowU32From(Hash, 0));
return (const char *) str; return (const char *) str;
} }
} } // namespace Hash::Meow
#undef INSTRUCTION_REORDER_BARRIER #undef INSTRUCTION_REORDER_BARRIER
#undef prefetcht0 #undef prefetcht0

View File

@ -10,25 +10,38 @@ extern "C" {
// Licensing Information // Licensing Information
// //
// Except as otherwise noted (below and/or in individual files), this project is licensed under the Unlicense (https://opensource.org/licenses/unlicense) or the Zero Clause BSD license (https://opensource.org/licenses/0bsd), at your option. // Except as otherwise noted (below and/or in individual files), this project is licensed under the Unlicense
// The Unlicense // (https://opensource.org/licenses/unlicense) or the Zero Clause BSD license (https://opensource.org/licenses/0bsd), at
// your option. The Unlicense
// //
// This is free and unencumbered software released into the public domain. // This is free and unencumbered software released into the public domain.
// //
// Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. // Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form
// or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
// //
// In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. // In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright
// interest in the software to the public domain. We make this dedication for the benefit of the public at large and to
// the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in
// perpetuity of all present and future rights to this software under copyright law.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// //
// For more information, please refer to http://unlicense.org // For more information, please refer to http://unlicense.org
// Zero Clause BSD License // Zero Clause BSD License
// //
// © 2021 Alain Mosnier // © 2021 Alain Mosnier
// //
// Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. // Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby
// granted.
// //
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
// AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
/* /*
* @brief Size of the SHA-256 sum. This times eight is 256 bits. * @brief Size of the SHA-256 sum. This times eight is 256 bits.
@ -96,16 +109,15 @@ static inline void consume_chunk(uint32_t *h, const uint8_t *p)
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
for (j = 0; j < 16; j++) { for (j = 0; j < 16; j++) {
if (i == 0) { if (i == 0) {
w[j] = w[j] = (uint32_t) p[0] << 24 | (uint32_t) p[1] << 16 | (uint32_t) p[2] << 8 | (uint32_t) p[3];
(uint32_t)p[0] << 24 | (uint32_t)p[1] << 16 | (uint32_t)p[2] << 8 | (uint32_t)p[3]; p += 4;
p += 4;
} else { } else {
/* Extend the first 16 words into the remaining 48 words w[16..63] of the /* Extend the first 16 words into the remaining 48 words w[16..63] of the
* message schedule array: */ * message schedule array: */
const uint32_t s0 = right_rot(w[(j + 1) & 0xf], 7) ^ right_rot(w[(j + 1) & 0xf], 18) ^ const uint32_t s0 =
(w[(j + 1) & 0xf] >> 3); right_rot(w[(j + 1) & 0xf], 7) ^ right_rot(w[(j + 1) & 0xf], 18) ^ (w[(j + 1) & 0xf] >> 3);
const uint32_t s1 = right_rot(w[(j + 14) & 0xf], 17) ^ const uint32_t s1 =
right_rot(w[(j + 14) & 0xf], 19) ^ (w[(j + 14) & 0xf] >> 10); right_rot(w[(j + 14) & 0xf], 17) ^ right_rot(w[(j + 14) & 0xf], 19) ^ (w[(j + 14) & 0xf] >> 10);
w[j] = w[j] + s0 + w[(j + 9) & 0xf] + s1; w[j] = w[j] + s0 + w[(j + 9) & 0xf] + s1;
} }
const uint32_t s1 = right_rot(ah[4], 6) ^ right_rot(ah[4], 11) ^ right_rot(ah[4], 25); const uint32_t s1 = right_rot(ah[4], 6) ^ right_rot(ah[4], 11) ^ right_rot(ah[4], 25);
@ -116,20 +128,18 @@ static inline void consume_chunk(uint32_t *h, const uint8_t *p)
* (first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311): * (first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311):
*/ */
static const uint32_t k[] = { static const uint32_t k[] = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2};
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7,
0xc67178f2};
const uint32_t temp1 = ah[7] + s1 + ch + k[i << 4 | j] + w[j]; const uint32_t temp1 = ah[7] + s1 + ch + k[i << 4 | j] + w[j];
const uint32_t s0 = right_rot(ah[0], 2) ^ right_rot(ah[0], 13) ^ right_rot(ah[0], 22); const uint32_t s0 = right_rot(ah[0], 2) ^ right_rot(ah[0], 13) ^ right_rot(ah[0], 22);
const uint32_t maj = (ah[0] & ah[1]) ^ (ah[0] & ah[2]) ^ (ah[1] & ah[2]); const uint32_t maj = (ah[0] & ah[1]) ^ (ah[0] & ah[2]) ^ (ah[1] & ah[2]);
const uint32_t temp2 = s0 + maj; const uint32_t temp2 = s0 + maj;
ah[7] = ah[6]; ah[7] = ah[6];
@ -148,25 +158,24 @@ static inline void consume_chunk(uint32_t *h, const uint8_t *p)
h[i] += ah[i]; h[i] += ah[i];
} }
/* /*
* @brief Initialize a SHA-256 streaming calculation. * @brief Initialize a SHA-256 streaming calculation.
* @param sha_256 A pointer to a SHA-256 structure. * @param sha_256 A pointer to a SHA-256 structure.
* @param hash Hash array, where the result will be delivered. * @param hash Hash array, where the result will be delivered.
* *
* @note If all of the data you are calculating the hash value on is not available in a contiguous buffer in memory, this is * @note If all of the data you are calculating the hash value on is not available in a contiguous buffer in memory,
* where you should start. Instantiate a SHA-256 structure, for instance by simply declaring it locally, make your hash * this is where you should start. Instantiate a SHA-256 structure, for instance by simply declaring it locally, make
* buffer available, and invoke this function. Once a SHA-256 hash has been calculated (see further below) a SHA-256 * your hash buffer available, and invoke this function. Once a SHA-256 hash has been calculated (see further below) a
* structure can be initialized again for the next calculation. * SHA-256 structure can be initialized again for the next calculation.
* *
* @note If either of the passed pointers is NULL, the results are unpredictable. * @note If either of the passed pointers is NULL, the results are unpredictable.
*/ */
void sha_256_init(struct Sha_256 *sha_256, uint8_t hash[SIZE_OF_SHA_256_HASH]) void sha_256_init(struct Sha_256 *sha_256, uint8_t hash[SIZE_OF_SHA_256_HASH])
{ {
sha_256->hash = hash; sha_256->hash = hash;
sha_256->chunk_pos = sha_256->chunk; sha_256->chunk_pos = sha_256->chunk;
sha_256->space_left = SIZE_OF_SHA_256_CHUNK; sha_256->space_left = SIZE_OF_SHA_256_CHUNK;
sha_256->total_len = 0; sha_256->total_len = 0;
/* /*
* Initialize hash values (first 32 bits of the fractional parts of the square roots of the first 8 primes * Initialize hash values (first 32 bits of the fractional parts of the square roots of the first 8 primes
* 2..19): * 2..19):
@ -210,18 +219,18 @@ void sha_256_write(struct Sha_256 *sha_256, const void *data, size_t len)
if (sha_256->space_left == SIZE_OF_SHA_256_CHUNK && len >= SIZE_OF_SHA_256_CHUNK) { if (sha_256->space_left == SIZE_OF_SHA_256_CHUNK && len >= SIZE_OF_SHA_256_CHUNK) {
consume_chunk(sha_256->h, p); consume_chunk(sha_256->h, p);
len -= SIZE_OF_SHA_256_CHUNK; len -= SIZE_OF_SHA_256_CHUNK;
p += SIZE_OF_SHA_256_CHUNK; p += SIZE_OF_SHA_256_CHUNK;
continue; continue;
} }
/* General case, no particular optimization. */ /* General case, no particular optimization. */
const size_t consumed_len = len < sha_256->space_left ? len : sha_256->space_left; const size_t consumed_len = len < sha_256->space_left ? len : sha_256->space_left;
memcpy(sha_256->chunk_pos, p, consumed_len); memcpy(sha_256->chunk_pos, p, consumed_len);
sha_256->space_left -= consumed_len; sha_256->space_left -= consumed_len;
len -= consumed_len; len -= consumed_len;
p += consumed_len; p += consumed_len;
if (sha_256->space_left == 0) { if (sha_256->space_left == 0) {
consume_chunk(sha_256->h, sha_256->chunk); consume_chunk(sha_256->h, sha_256->chunk);
sha_256->chunk_pos = sha_256->chunk; sha_256->chunk_pos = sha_256->chunk;
sha_256->space_left = SIZE_OF_SHA_256_CHUNK; sha_256->space_left = SIZE_OF_SHA_256_CHUNK;
} else { } else {
sha_256->chunk_pos += consumed_len; sha_256->chunk_pos += consumed_len;
@ -245,7 +254,7 @@ void sha_256_write(struct Sha_256 *sha_256, const void *data, size_t len)
*/ */
uint8_t *sha_256_close(struct Sha_256 *sha_256) uint8_t *sha_256_close(struct Sha_256 *sha_256)
{ {
uint8_t *pos = sha_256->chunk_pos; uint8_t *pos = sha_256->chunk_pos;
size_t space_left = sha_256->space_left; size_t space_left = sha_256->space_left;
uint32_t *const h = sha_256->h; uint32_t *const h = sha_256->h;
@ -264,29 +273,29 @@ uint8_t *sha_256_close(struct Sha_256 *sha_256)
if (space_left < TOTAL_LEN_LEN) { if (space_left < TOTAL_LEN_LEN) {
memset(pos, 0x00, space_left); memset(pos, 0x00, space_left);
consume_chunk(h, sha_256->chunk); consume_chunk(h, sha_256->chunk);
pos = sha_256->chunk; pos = sha_256->chunk;
space_left = SIZE_OF_SHA_256_CHUNK; space_left = SIZE_OF_SHA_256_CHUNK;
} }
const size_t left = space_left - TOTAL_LEN_LEN; const size_t left = space_left - TOTAL_LEN_LEN;
memset(pos, 0x00, left); memset(pos, 0x00, left);
pos += left; pos += left;
size_t len = sha_256->total_len; size_t len = sha_256->total_len;
pos[7] = (uint8_t)(len << 3); pos[7] = (uint8_t) (len << 3);
len >>= 5; len >>= 5;
int i; int i;
for (i = 6; i >= 0; --i) { for (i = 6; i >= 0; --i) {
pos[i] = (uint8_t)len; pos[i] = (uint8_t) len;
len >>= 8; len >>= 8;
} }
consume_chunk(h, sha_256->chunk); consume_chunk(h, sha_256->chunk);
/* Produce the final hash value (big-endian): */ /* Produce the final hash value (big-endian): */
int j; int j;
uint8_t *const hash = sha_256->hash; uint8_t *const hash = sha_256->hash;
for (i = 0, j = 0; i < 8; i++) { for (i = 0, j = 0; i < 8; i++) {
hash[j++] = (uint8_t)(h[i] >> 24); hash[j++] = (uint8_t) (h[i] >> 24);
hash[j++] = (uint8_t)(h[i] >> 16); hash[j++] = (uint8_t) (h[i] >> 16);
hash[j++] = (uint8_t)(h[i] >> 8); hash[j++] = (uint8_t) (h[i] >> 8);
hash[j++] = (uint8_t)h[i]; hash[j++] = (uint8_t) h[i];
} }
return sha_256->hash; return sha_256->hash;
} }
@ -307,7 +316,7 @@ void calc_sha_256(uint8_t hash[SIZE_OF_SHA_256_HASH], const void *input, size_t
struct Sha_256 sha_256; struct Sha_256 sha_256;
sha_256_init(&sha_256, hash); sha_256_init(&sha_256, hash);
sha_256_write(&sha_256, input, len); sha_256_write(&sha_256, input, len);
(void)sha_256_close(&sha_256); (void) sha_256_close(&sha_256);
} }
#undef TOTAL_LEN_LEN #undef TOTAL_LEN_LEN

0
ICAL.txt → ICLA.txt Executable file → Normal file
View File

View File

@ -10,8 +10,8 @@
#ifndef IMAGE_BILL_DETECTION_H #ifndef IMAGE_BILL_DETECTION_H
#define IMAGE_BILL_DETECTION_H #define IMAGE_BILL_DETECTION_H
#include <stdio.h>
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
#include <stdio.h>
#include <vector> #include <vector>
namespace Image::BillDetection namespace Image::BillDetection
@ -33,12 +33,12 @@ namespace Image::BillDetection
std::vector<cv::Vec4i> lines; std::vector<cv::Vec4i> lines;
lines.clear(); lines.clear();
cv::HoughLinesP(edges, lines, 1, CV_PI/180, 25); cv::HoughLinesP(edges, lines, 1, CV_PI / 180, 25);
std::vector<cv::Vec4i>::iterator it = lines.begin(); std::vector<cv::Vec4i>::iterator it = lines.begin();
for(; it != lines.end(); ++it) { for (; it != lines.end(); ++it) {
cv::Vec4i l = *it; cv::Vec4i l = *it;
cv::line(edges, cv::Point(l[0], l[1]), cv::Point(l[2], l[3]), cv::Scalar(255,0,0), 2, 8); cv::line(edges, cv::Point(l[0], l[1]), cv::Point(l[2], l[3]), cv::Scalar(255, 0, 0), 2, 8);
} }
std::vector<std::vector<cv::Point>> contours; std::vector<std::vector<cv::Point>> contours;
@ -60,8 +60,8 @@ namespace Image::BillDetection
// Approximate polygon // Approximate polygon
/* Question: we probably don't want a polygon all the time?! */ /* Question: we probably don't want a polygon all the time?! */
// @todo bad implementation, focus on single square // @todo bad implementation, focus on single square
std::vector<std::vector<cv::Point> > contoursDraw (contoursArea.size()); std::vector<std::vector<cv::Point>> contoursDraw(contoursArea.size());
for (int i = 0; i < contoursArea.size(); ++i){ for (int i = 0; i < contoursArea.size(); ++i) {
cv::approxPolyDP(cv::Mat(contoursArea[i]), contoursDraw[i], 40, true); cv::approxPolyDP(cv::Mat(contoursArea[i]), contoursDraw[i], 40, true);
} }
@ -73,6 +73,6 @@ namespace Image::BillDetection
return out; return out;
} }
} } // namespace Image::BillDetection
#endif #endif

View File

@ -10,8 +10,8 @@
#ifndef IMAGE_DIFF_H #ifndef IMAGE_DIFF_H
#define IMAGE_DIFF_H #define IMAGE_DIFF_H
#include <stdio.h>
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
#include <stdio.h>
#include "../Utils/MathUtils.h" #include "../Utils/MathUtils.h"
@ -19,7 +19,7 @@ namespace Image
{ {
namespace ImageUtils namespace ImageUtils
{ {
cv::Mat find_diff (cv::Mat in1, cv::Mat in2) cv::Mat find_diff(cv::Mat in1, cv::Mat in2)
{ {
cv::Mat diff; cv::Mat diff;
cv::absdiff(in1, in2, diff); cv::absdiff(in1, in2, diff);
@ -43,7 +43,7 @@ namespace Image
return out; return out;
} }
} } // namespace ImageUtils
} } // namespace Image
#endif #endif

View File

@ -10,13 +10,12 @@
#ifndef IMAGE_IMAGE_UTILS_H #ifndef IMAGE_IMAGE_UTILS_H
#define IMAGE_IMAGE_UTILS_H #define IMAGE_IMAGE_UTILS_H
#include <stdio.h>
#include <math.h> #include <math.h>
#include <stdio.h>
namespace Image::ImageUtils namespace Image::ImageUtils
{ {
inline inline float lightnessFromRgb(int r, int g, int b)
float lightnessFromRgb(int r, int g, int b)
{ {
float vR = r / 255.0; float vR = r / 255.0;
float vG = g / 255.0; float vG = g / 255.0;
@ -31,6 +30,6 @@ namespace Image::ImageUtils
return lStar / 100.0; return lStar / 100.0;
} }
} } // namespace Image::ImageUtils
#endif #endif

View File

@ -10,60 +10,38 @@
#ifndef IMAGE_KERNEL_H #ifndef IMAGE_KERNEL_H
#define IMAGE_KERNEL_H #define IMAGE_KERNEL_H
#include <stdio.h>
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
#include <stdio.h>
#include "ImageUtils.h"
#include "../Utils/MathUtils.h" #include "../Utils/MathUtils.h"
#include "ImageUtils.h"
namespace Image::Kernel namespace Image::Kernel
{ {
const float KERNEL_RIDGE_1[3][3] = { const float KERNEL_RIDGE_1[3][3] = {{0.0, -1.0, 0.0}, {-1.0, 4.0, -1.0}, {0.0, -1.0, 0.0}};
{0.0, -1.0, 0.0},
{-1.0, 4.0, -1.0},
{0.0, -1.0, 0.0}
};
const float KERNEL_RIDGE_2[3][3] = { const float KERNEL_RIDGE_2[3][3] = {{-1.0, -1.0, -1.0}, {-1.0, 8.0, -1.0}, {-1.0, -1.0, -1.0}};
{-1.0, -1.0, -1.0},
{-1.0, 8.0, -1.0},
{-1.0, -1.0, -1.0}
};
const float KERNEL_SHARPEN[3][3] = { const float KERNEL_SHARPEN[3][3] = {{0.0, -1.0, 0.0}, {-1.0, 5.0, -1.0}, {0.0, -1.0, 0.0}};
{0.0, -1.0, 0.0},
{-1.0, 5.0, -1.0},
{0.0, -1.0, 0.0}
};
const float KERNEL_BOX_BLUR[3][3] = { const float KERNEL_BOX_BLUR[3][3] = {
{1.0 / 9.0, 1.0 / 9.0, 1.0 / 9.0}, {1.0 / 9.0, 1.0 / 9.0, 1.0 / 9.0}, {1.0 / 9.0, 1.0 / 9.0, 1.0 / 9.0}, {1.0 / 9.0, 1.0 / 9.0, 1.0 / 9.0}};
{1.0 / 9.0, 1.0 / 9.0, 1.0 / 9.0},
{1.0 / 9.0, 1.0 / 9.0, 1.0 / 9.0}
};
const float KERNEL_GAUSSUAN_BLUR_3[3][3] = { const float KERNEL_GAUSSUAN_BLUR_3[3][3] = {{1.0 / 16.0, 2.0 / 16.0, 1.0 / 16.0},
{1.0 / 16.0, 2.0 / 16.0, 1.0 / 16.0}, {2.0 / 16.0, 4.0 / 16.0, 2.0 / 16.0},
{2.0 / 16.0, 4.0 / 16.0, 2.0 / 16.0}, {1.0 / 16.0, 2.0 / 16.0, 1.0 / 16.0}};
{1.0 / 16.0, 2.0 / 16.0, 1.0 / 16.0}
};
const float KERNEL_EMBOSS[3][3] = { const float KERNEL_EMBOSS[3][3] = {{-2.0, -1.0, 0.0}, {-1.0, 1.0, 1.0}, {0.0, 1.0, 2.0}};
{-2.0, -1.0, 0.0},
{-1.0, 1.0, 1.0},
{0.0, 1.0, 2.0}
};
const float KERNEL_UNSHARP_MASKING[5][5] = { const float KERNEL_UNSHARP_MASKING[5][5] = {
{-1.0 / 256.0, -4.0 / 256.0, -6.0 / 256.0, -4.0 / 256.0, -1.0 / 256.0}, {-1.0 / 256.0, -4.0 / 256.0, -6.0 / 256.0, -4.0 / 256.0, -1.0 / 256.0},
{-4.0 / 256.0, -16.0 / 256.0, -24.0 / 256.0, -16.0 / 256.0, -4.0 / 256.0}, {-4.0 / 256.0, -16.0 / 256.0, -24.0 / 256.0, -16.0 / 256.0, -4.0 / 256.0},
{-6.0 / 256.0, -24.0 / 256.0, 476.0 / 256.0, -24.0 / 256.0, -6.0 / 256.0}, {-6.0 / 256.0, -24.0 / 256.0, 476.0 / 256.0, -24.0 / 256.0, -6.0 / 256.0},
{-4.0 / 256.0, -16.0 / 256.0, -24.0 / 256.0, -16.0 / 256.0, -4.0 / 256.0}, {-4.0 / 256.0, -16.0 / 256.0, -24.0 / 256.0, -16.0 / 256.0, -4.0 / 256.0},
{-1.0 / 256.0, -4.0 / 256.0, -6.0 / 256.0, -4.0 / 256.0, -1.0 / 256.0}, {-1.0 / 256.0, -4.0 / 256.0, -6.0 / 256.0, -4.0 / 256.0, -1.0 / 256.0},
}; };
inline inline cv::Mat convolve(cv::Mat in, const float kernel[][3])
cv::Mat convolve(cv::Mat in, const float kernel[][3])
{ {
cv::Size dim = in.size(); cv::Size dim = in.size();
cv::Mat out(in.size(), in.type()); cv::Mat out(in.size(), in.type());
@ -73,6 +51,6 @@ namespace Image::Kernel
return out; return out;
} }
} } // namespace Image::Kernel
#endif #endif

View File

@ -10,8 +10,8 @@
#ifndef IMAGE_SKEW_H #ifndef IMAGE_SKEW_H
#define IMAGE_SKEW_H #define IMAGE_SKEW_H
#include <stdio.h>
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
#include <stdio.h>
#include <vector> #include <vector>
#include "../Utils/MathUtils.h" #include "../Utils/MathUtils.h"
@ -42,7 +42,8 @@ namespace Image::Skew
std::vector<float> angles; std::vector<float> angles;
for (int i = 0; i < tmpAngles.size(); ++i) { for (int i = 0; i < tmpAngles.size(); ++i) {
if (imageOrientation > 0) { if (imageOrientation > 0) {
if (oms_deg2rad(90 - maxDegree) < oms_abs(tmpAngles[i]) && oms_abs(tmpAngles[i]) < oms_deg2rad(90 + maxDegree)) { if (oms_deg2rad(90 - maxDegree) < oms_abs(tmpAngles[i]) &&
oms_abs(tmpAngles[i]) < oms_deg2rad(90 + maxDegree)) {
angles.push_back(tmpAngles[i]); angles.push_back(tmpAngles[i]);
} }
} else { } else {
@ -85,6 +86,6 @@ namespace Image::Skew
return out; return out;
} }
} } // namespace Image::Skew
#endif #endif

View File

@ -10,11 +10,11 @@
#ifndef IMAGE_THRESHOLDING_H #ifndef IMAGE_THRESHOLDING_H
#define IMAGE_THRESHOLDING_H #define IMAGE_THRESHOLDING_H
#include <stdio.h>
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
#include <stdio.h>
#include "ImageUtils.h"
#include "../Utils/MathUtils.h" #include "../Utils/MathUtils.h"
#include "ImageUtils.h"
namespace Image::Thresholding namespace Image::Thresholding
{ {
@ -58,7 +58,7 @@ namespace Image::Thresholding
count = (x2 - x1) * (y2 - y1); count = (x2 - x1) * (y2 - y1);
sum = intImg[x2 * y2] - intImg[x2 * (y1 - 1)] - intImg[(x1 - 1) * y2] + intImg[(x1 - 1) * (y1 - 1)]; sum = intImg[x2 * y2] - intImg[x2 * (y1 - 1)] - intImg[(x1 - 1) * y2] + intImg[(x1 - 1) * (y1 - 1)];
bgr = in.at<cv::Vec3b>(j, i); bgr = in.at<cv::Vec3b>(j, i);
brightness = Image::ImageUtils::lightnessFromRgb(bgr[2], bgr[1], bgr[0]); brightness = Image::ImageUtils::lightnessFromRgb(bgr[2], bgr[1], bgr[0]);
color = brightness * count <= (sum * (100.0 - t) / 100.0) && brightness < 0.95 ? 0 : 255; color = brightness * count <= (sum * (100.0 - t) / 100.0) && brightness < 0.95 ? 0 : 255;
@ -73,6 +73,6 @@ namespace Image::Thresholding
return out; return out;
} }
} } // namespace Image::Thresholding
#endif #endif

35
Input/XInput.h Normal file
View File

@ -0,0 +1,35 @@
/**
* Karaka
*
* @package Stdlib
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef INPUT_XINPUT_H
#define INPUT_XINPUT_H
#ifdef _WIN32
#include <XInput.h>
#else
#include <linux/joystick.h>
#endif
#include "../Stdlib/Types.h"
uint32 find_joysticks() {}
void destory_joysticks() {}
void handle_controller_input()
{
for (uint32 controller_index = 0; controller_index < XUSER_MAX_COUNT; ++controller_index) {
XINPUT_STATE controller_state;
if (XInputGetState(controller_index, &controller_state) == ERROR_SUCCESS) {
} else {
}
}
}
#endif

View File

@ -1,4 +1,5 @@
// Remarks: sizes for the second matrix/vector are often implied by the first parameter and the rules for matrix/vector multiplication. // Remarks: sizes for the second matrix/vector are often implied by the first parameter and the rules for matrix/vector
// multiplication.
// First element is always a matrix of int64_t // First element is always a matrix of int64_t
///////////////////////////////// /////////////////////////////////

View File

@ -0,0 +1,154 @@
/**
* Karaka
*
* @package Stdlib
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef MATH_MATRIX_VECTORFLOAT32_H
#define MATH_MATRIX_VECTORFLOAT32_H
namespace Math::Matrix::VectorFloat32
{
struct v3_f32_4_simd {
union {
struct {
union {
f32_4_simd x;
f32_4_simd r;
};
union {
f32_4_simd y;
f32_4_simd g;
};
union {
f32_4_simd z;
f32_4_simd b;
};
};
f32_4_simd v[3];
};
};
struct v3_f32_8_simd {
union {
struct {
union {
f32_8_simd x;
f32_8_simd r;
};
union {
f32_8_simd y;
f32_8_simd g;
};
union {
f32_8_simd z;
f32_8_simd b;
};
};
f32_8_simd v[3];
};
};
struct v3_f32_16_simd {
union {
struct {
union {
f32_16_simd x;
f32_16_simd r;
};
union {
f32_16_simd y;
f32_16_simd g;
};
union {
f32_16_simd z;
f32_16_simd b;
};
};
f32_16_simd v[3];
};
};
struct v4_f32_4_simd {
union {
struct {
union {
f32_4_simd x;
f32_4_simd r;
};
union {
f32_4_simd y;
f32_4_simd g;
};
union {
f32_4_simd z;
f32_4_simd b;
};
union {
f32_4_simd w;
f32_4_simd a;
};
};
f32_4_simd v[4];
};
};
struct v4_f32_8_simd {
union {
struct {
union {
f32_8_simd x;
f32_8_simd r;
};
union {
f32_8_simd y;
f32_8_simd g;
};
union {
f32_8_simd z;
f32_8_simd b;
};
union {
f32_8_simd w;
f32_8_simd a;
};
};
f32_8_simd v[4];
};
};
struct v4_f32_16_simd {
union {
struct {
union {
f32_16_simd x;
f32_16_simd r;
};
union {
f32_16_simd y;
f32_16_simd g;
};
union {
f32_16_simd z;
f32_16_simd b;
};
union {
f32_16_simd w;
f32_16_simd a;
};
};
f32_16_simd v[4];
};
};
} // namespace Math::Matrix::VectorFloat32
#endif

View File

@ -0,0 +1,176 @@
/**
* Karaka
*
* @package Stdlib
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef MATH_MATRIX_VECTORFLOAT32_H
#define MATH_MATRIX_VECTORFLOAT32_H
#include "Types.h"
#include <immintrin.h>
#include <xmmintrin.h>
struct simd_int32_4 {
union {
__m128i P;
int32 v[4];
};
};
struct simd_int32_8 {
union {
__m256i P;
int32 v[8];
};
};
struct simd_int32_16 {
union {
__m512i P;
int32 v[16];
};
};
struct v3_simd_int32_4 {
union {
struct {
union {
simd_int32_4 x;
simd_int32_4 r;
};
union {
simd_int32_4 y;
simd_int32_4 g;
};
union {
simd_int32_4 z;
simd_int32_4 b;
};
};
simd_int32_4 v[3];
};
};
struct v3_simd_int32_8 {
union {
struct {
union {
simd_int32_8 x;
simd_int32_8 r;
};
union {
simd_int32_8 y;
simd_int32_8 g;
};
union {
simd_int32_8 z;
simd_int32_8 b;
};
};
simd_int32_8 v[3];
};
};
struct v3_simd_int32_16 {
union {
struct {
union {
simd_int32_16 x;
simd_int32_16 r;
};
union {
simd_int32_16 y;
simd_int32_16 g;
};
union {
simd_int32_16 z;
simd_int32_16 b;
};
};
simd_int32_16 v[3];
};
};
struct v4_simd_int32_4 {
union {
struct {
union {
simd_int32_4 x;
simd_int32_4 r;
};
union {
simd_int32_4 y;
simd_int32_4 g;
};
union {
simd_int32_4 z;
simd_int32_4 b;
};
union {
simd_int32_4 w;
simd_int32_4 a;
};
};
simd_int32_4 v[4];
};
};
struct v4_simd_int32_8 {
union {
struct {
union {
simd_int32_8 x;
simd_int32_8 r;
};
union {
simd_int32_8 y;
simd_int32_8 g;
};
union {
simd_int32_8 z;
simd_int32_8 b;
};
union {
simd_int32_8 w;
simd_int32_8 a;
};
};
simd_int32_8 v[4];
};
};
struct v4_simd_int32_16 {
union {
struct {
union {
simd_int32_16 x;
simd_int32_16 r;
};
union {
simd_int32_16 y;
simd_int32_16 g;
};
union {
simd_int32_16 z;
simd_int32_16 b;
};
union {
simd_int32_16 w;
simd_int32_16 a;
};
};
simd_int32_16 v[4];
};
};
#endif

View File

@ -1,186 +1,176 @@
// Remarks: sizes for the second matrix/vector are often implied by the first parameter and the rules for matrix/vector multiplication. /**
* Karaka
*
* @package Stdlib
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef MATH_MATRIX_VECTORFLOAT32_H
#define MATH_MATRIX_VECTORFLOAT32_H
///////////////////////////////// #include "Types.h"
// Multiplication #include <immintrin.h>
///////////////////////////////// #include <xmmintrin.h>
// Array vector multiplication struct simd_int64_2 {
///////////////////////////////// union {
// mult_vec_int32(int64_t *a, size_t a, int32_t *b) __m128i P;
// mult_vec_int64(int64_t *a, size_t a, int64_t *b) int64 v[2];
// mult_vec_float(int64_t *a, size_t a, float *b) };
};
// mult_scal_int32(int64_t *a, size_t a, int32_t b) struct simd_int64_4 {
// mult_scal_int64(int64_t *a, size_t a, int64_t b) union {
// mult_scal_float(int64_t *a, size_t a, float b) __m256i P;
int64 v[4];
};
};
// Vector 2 vector multiplication struct simd_int64_8 {
///////////////////////////////// union {
// v2_mult_vec_int32(v2 *a, int32_t *b) __m512i P;
// v2_mult_vec_int64(v2 *a, int64_t *b) int64 v[8];
// v2_mult_vec_float(v2 *a, float *b) };
// v2_mult_vec_v2(v2 *a, v2 *b) };
// v2_mult_scal_int32(v2 *a, int32_t b) struct v3_simd_int64_2 {
// v2_mult_scal_int64(v2 *a, int64_t b) union {
// v2_mult_scal_float(v2 *a, float b) struct {
union {
simd_int64_2 x;
simd_int64_2 r;
};
union {
simd_int64_2 y;
simd_int64_2 g;
};
union {
simd_int64_2 z;
simd_int64_2 b;
};
};
// Vector 3 vector multiplication simd_int64_2 v[3];
///////////////////////////////// };
// v3_mult_vec_int32(v3 *a, int32_t *b) };
// v3_mult_vec_int64(v3 *a, int64_t *b)
// v3_mult_vec_float(v3 *a, float *b)
// v3_mult_vec_v3(v3 *a, v3 *b)
// v3_mult_scal_int32(v3 *a, int32_t b) struct v3_simd_int64_4 {
// v3_mult_scal_int64(v3 *a, int64_t b) union {
// v3_mult_scal_float(v3 *a, float b) struct {
union {
simd_int64_4 x;
simd_int64_4 r;
};
union {
simd_int64_4 y;
simd_int64_4 g;
};
union {
simd_int64_4 z;
simd_int64_4 b;
};
};
// Vector 4 vector multiplication simd_int64_4 v[3];
///////////////////////////////// };
// v4_mult_vec_int32(v4 *a, int32_t *b) };
// v4_mult_vec_int64(v4 *a, int64_t *b)
// v4_mult_vec_float(v4 *a, float *b)
// v4_mult_vec_v4(v4 *a, v4 *b)
// v4_mult_scal_int32(v4 *a, int32_t b) struct v3_simd_int64_8 {
// v4_mult_scal_int64(v4 *a, int64_t b) union {
// v4_mult_scal_float(v4 *a, float b) struct {
union {
simd_int64_8 x;
simd_int64_8 r;
};
union {
simd_int64_8 y;
simd_int64_8 g;
};
union {
simd_int64_8 z;
simd_int64_8 b;
};
};
///////////////////////////////// simd_int64_8 v[3];
// Addition };
///////////////////////////////// };
// Array vector addition struct v4_simd_int64_2 {
///////////////////////////////// union {
// add_vec_int32(int64_t *a, size_t a, int32_t *b) struct {
// add_vec_int64(int64_t *a, size_t a, int64_t *b) union {
// add_vec_float(int64_t *a, size_t a, float *b) simd_int64_2 x;
simd_int64_2 r;
};
union {
simd_int64_2 y;
simd_int64_2 g;
};
union {
simd_int64_2 z;
simd_int64_2 b;
};
union {
simd_int64_2 w;
simd_int64_2 a;
};
};
// add_scal_int32(int64_t *a, size_t a, int32_t b) simd_int64_2 v[4];
// add_scal_int64(int64_t *a, size_t a, int64_t b) };
// add_scal_float(int64_t *a, size_t a, float b) };
// Vector 2 vector addition struct v4_simd_int64_4 {
///////////////////////////////// union {
// v2_add_vec_int32(v2 *a, int32_t *b) struct {
// v2_add_vec_int64(v2 *a, int64_t *b) union {
// v2_add_vec_float(v2 *a, float *b) simd_int64_4 x;
// v2_add_vec_v2(v2 *a, v2 *b) simd_int64_4 r;
};
union {
simd_int64_4 y;
simd_int64_4 g;
};
union {
simd_int64_4 z;
simd_int64_4 b;
};
union {
simd_int64_4 w;
simd_int64_4 a;
};
};
// v2_add_scal_int32(v2 *a, int32_t b) simd_int64_4 v[4];
// v2_add_scal_int64(v2 *a, int64_t b) };
// v2_add_scal_float(v2 *a, float b) };
// Vector 3 vector addition struct v4_simd_int64_8 {
///////////////////////////////// union {
// v3_add_vec_int32(v3 *a, int32_t *b) struct {
// v3_add_vec_int64(v3 *a, int64_t *b) union {
// v3_add_vec_float(v3 *a, float *b) simd_int64_8 x;
// v3_add_vec_v3(v3 *a, v3 *b) simd_int64_8 r;
};
union {
simd_int64_8 y;
simd_int64_8 g;
};
union {
simd_int64_8 z;
simd_int64_8 b;
};
union {
simd_int64_8 w;
simd_int64_8 a;
};
};
// v3_add_scal_int32(v3 *a, int32_t b) simd_int64_8 v[4];
// v3_add_scal_int64(v3 *a, int64_t b) };
// v3_add_scal_float(v3 *a, float b) };
// Vector 4 vector addition #endif
/////////////////////////////////
// v4_add_vec_int32(v4 *a, int32_t *b)
// v4_add_vec_int64(v4 *a, int64_t *b)
// v4_add_vec_float(v4 *a, float *b)
// v4_add_vec_v4(v4 *a, v4 *b)
// v4_add_scal_int32(v4 *a, int32_t b)
// v4_add_scal_int64(v4 *a, int64_t b)
// v4_add_scal_float(v4 *a, float b)
/////////////////////////////////
// Subtraction
/////////////////////////////////
// Array vector subtraction
/////////////////////////////////
// sub_vec_int32(int64_t *a, size_t a, int32_t *b)
// sub_vec_int64(int64_t *a, size_t a, int64_t *b)
// sub_vec_float(int64_t *a, size_t a, float *b)
// sub_scal_int32(int64_t *a, size_t a, int32_t b)
// sub_scal_int64(int64_t *a, size_t a, int64_t b)
// sub_scal_float(int64_t *a, size_t a, float b)
// Vector 2 vector subtraction
/////////////////////////////////
// v2_sub_vec_int32(v2 *a, int32_t *b)
// v2_sub_vec_int64(v2 *a, int64_t *b)
// v2_sub_vec_float(v2 *a, float *b)
// v2_sub_vec_v2(v2 *a, v2 *b)
// v2_sub_scal_int32(v2 *a, int32_t b)
// v2_sub_scal_int64(v2 *a, int64_t b)
// v2_sub_scal_float(v2 *a, float b)
// Vector 3 vector subtraction
/////////////////////////////////
// v3_sub_vec_int32(v3 *a, int32_t *b)
// v3_sub_vec_int64(v3 *a, int64_t *b)
// v3_sub_vec_float(v3 *a, float *b)
// v3_sub_vec_v3(v3 *a, v3 *b)
// v3_sub_scal_int32(v3 *a, int32_t b)
// v3_sub_scal_int64(v3 *a, int64_t b)
// v3_sub_scal_float(v3 *a, float b)
// Vector 4 vector subtraction
/////////////////////////////////
// v4_sub_vec_int32(v4 *a, int32_t *b)
// v4_sub_vec_int64(v4 *a, int64_t *b)
// v4_sub_vec_float(v4 *a, float *b)
// v4_sub_vec_v4(v4 *a, v4 *b)
// v4_sub_scal_int32(v4 *a, int32_t b)
// v4_sub_scal_int64(v4 *a, int64_t b)
// v4_sub_scal_float(v4 *a, float b)
/////////////////////////////////
// Other
/////////////////////////////////
// Cross product
/////////////////////////////////
// cross_int32(int64_t *a, size_t a, int32_t *b)
// cross_int64(int64_t *a, size_t a, int64_t *b)
// cross_float(int64_t *a, size_t a, float *b)
// v2_cross_v2(v2 *a, v2 *b)
// v3_cross_v3(v3 *a, v3 *b)
// v4_cross_v4(v4 *a, v4 *b)
// Dot product
/////////////////////////////////
// dot_int32(int64_t *a, size_t a, int32_t *b)
// dot_int64(int64_t *a, size_t a, int64_t *b)
// dot_float(int64_t *a, size_t a, float *b)
// v2_dot_v2(v2 *a, v2 *b)
// v3_dot_v3(v3 *a, v3 *b)
// v4_dot_v4(v4 *a, v4 *b)
// Angle
/////////////////////////////////
// angle_int32(int64_t *a, size_t a, int32_t *b)
// angle_int64(int64_t *a, size_t a, int64_t *b)
// angle_float(int64_t *a, size_t a, float *b)
// v2_angle_v2(v2 *a, v2 *b)
// v3_angle_v3(v3 *a, v3 *b)
// v4_angle_v4(v4 *a, v4 *b)
// Cosine
/////////////////////////////////
// cosine_int32(int64_t *a, size_t a, int32_t *b)
// cosine_int64(int64_t *a, size_t a, int64_t *b)
// cosine_float(int64_t *a, size_t a, float *b)
// v2_cosine_v2(v2 *a, v2 *b)
// v3_cosine_v3(v3 *a, v3 *b)
// v4_cosine_v4(v4 *a, v4 *b)

View File

@ -17,8 +17,8 @@
#include <iostream> #include <iostream>
#include <regex> #include <regex>
#include "../Stdlib/HashTable.h"
#include "../Hash/MeowHash.h" #include "../Hash/MeowHash.h"
#include "../Stdlib/HashTable.h"
namespace Router namespace Router
{ {
@ -36,14 +36,14 @@ namespace Router
return router; return router;
} }
void set(const Router *router, const char* route, void *endpoint) void set(const Router *router, const char *route, void *endpoint)
{ {
Stdlib::HashTable::set_entry(router->routes, route, endpoint); Stdlib::HashTable::set_entry(router->routes, route, endpoint);
} }
RouterFunc match_route(const Router *router, const char *uri) RouterFunc match_route(const Router *router, const char *uri)
{ {
RouterFunc ptr = NULL; RouterFunc ptr = NULL;
Stdlib::HashTable::it itr = Stdlib::HashTable::table_iterator(router->routes); Stdlib::HashTable::it itr = Stdlib::HashTable::table_iterator(router->routes);
std::regex regex; std::regex regex;
@ -66,6 +66,6 @@ namespace Router
Stdlib::HashTable::free_table(router->routes); Stdlib::HashTable::free_table(router->routes);
router->routes = NULL; router->routes = NULL;
} }
} } // namespace Router
#endif #endif

View File

@ -38,15 +38,10 @@ namespace Stdlib::HashTable
size_t index; size_t index;
} it; } it;
inline inline unsigned long long hash_key(const char *key)
unsigned long long hash_key(const char *key)
{ {
return (unsigned long long) MeowU64From( return (unsigned long long) MeowU64From(
Hash::Meow::MeowHash(Hash::Meow::MeowDefaultSeed, Hash::Meow::MeowHash(Hash::Meow::MeowDefaultSeed, strlen(key), (void *) key), 0);
strlen(key),
(void *) key),
0
);
} }
ht *create_table(int max = 0, bool is_fixed = false) ht *create_table(int max = 0, bool is_fixed = false)
@ -56,8 +51,8 @@ namespace Stdlib::HashTable
return NULL; return NULL;
} }
table->size = 0; table->size = 0;
table->max = max == 0 ? 16 : max; table->max = max == 0 ? 16 : max;
table->is_fixed = is_fixed; table->is_fixed = is_fixed;
table->entries = (entry *) calloc(table->max, sizeof(entry)); table->entries = (entry *) calloc(table->max, sizeof(entry));
@ -72,7 +67,7 @@ namespace Stdlib::HashTable
void *get_entry(ht *table, const char *key) void *get_entry(ht *table, const char *key)
{ {
unsigned long long hash = hash_key(key); unsigned long long hash = hash_key(key);
size_t index = (size_t) (hash & (unsigned long long)(table->max - 1)); size_t index = (size_t) (hash & (unsigned long long) (table->max - 1));
while (table->entries[index].key != NULL) { while (table->entries[index].key != NULL) {
if (strcmp(key, table->entries[index].key) == 0) { if (strcmp(key, table->entries[index].key) == 0) {
@ -91,7 +86,7 @@ namespace Stdlib::HashTable
const char *_set_entry(entry *entries, size_t max, const char *key, void *value, size_t *size) const char *_set_entry(entry *entries, size_t max, const char *key, void *value, size_t *size)
{ {
unsigned long long hash = hash_key(key); unsigned long long hash = hash_key(key);
size_t index = (size_t) (hash & (unsigned long long)(max - 1)); size_t index = (size_t) (hash & (unsigned long long) (max - 1));
while (entries[index].key != NULL) { while (entries[index].key != NULL) {
if (strcmp(key, entries[index].key) == 0) { if (strcmp(key, entries[index].key) == 0) {
@ -107,11 +102,11 @@ namespace Stdlib::HashTable
} }
if (size != NULL) { if (size != NULL) {
#ifdef _WIN32 #ifdef _WIN32
key = _strdup(key); key = _strdup(key);
#else #else
key = strdup(key); key = strdup(key);
#endif #endif
if (key == NULL) { if (key == NULL) {
return NULL; return NULL;
@ -120,7 +115,7 @@ namespace Stdlib::HashTable
++(*size); ++(*size);
} }
entries[index].key = (char *) key; entries[index].key = (char *) key;
entries[index].value = value; entries[index].value = value;
return key; return key;
@ -213,6 +208,6 @@ namespace Stdlib::HashTable
free(table->entries); free(table->entries);
} }
} } // namespace Stdlib::HashTable
#endif #endif

50
Stdlib/Intrinsics.h Normal file
View File

@ -0,0 +1,50 @@
/**
* Jingga
*
* @package Stdlib
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef STDLIB_INTRINSICS_H
#define STDLIB_INTRINSICS_H
#include <immintrin.h>
#include <inttypes.h>
#include <x86intrin.h>
#include <xmmintrin.h>
#include "Types.h"
namespace Stdlib::Intrinsics
{
inline f32 sqrt(f32 a) { return _mm_cvtss_f32(_mm_sqrt_ss(_mm_set_ss(a))); }
inline f32 round(f32 a)
{
return _mm_cvtss_f32(
_mm_round_ss(_mm_setzero_ps(), _mm_set_ss(a), (_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC)));
}
inline uint32 round_to_int(f32 a) { return (uint32) _mm_cvtss_si32(_mm_set_ss(a)); }
inline f32 floor(f32 a) { return _mm_cvtss_f32(_mm_floor_ss(_mm_setzero_ps(), _mm_set_ss(a))); }
inline f32 ceil(f32 a) { return _mm_cvtss_f32(_mm_ceil_ss(_mm_setzero_ps(), _mm_set_ss(a))); }
inline uint32 hash(uint64 a, uint64 b = 0)
{
uint8 seed[16] = {
0xaa, 0x9b, 0xbd, 0xb8, 0xa1, 0x98, 0xac, 0x3f, 0x1f, 0x94, 0x07, 0xb3, 0x8c, 0x27, 0x93, 0x69,
};
__m128i hash = _mm_set_epi64x(a, b);
hash = _mm_aesdec_si128(hash, _mm_loadu_si128((__m128i *) seed));
hash = _mm_aesdec_si128(hash, _mm_loadu_si128((__m128i *) seed));
return _mm_extract_epi32(hash, 0);
}
} // namespace Stdlib::Intrinsics
#endif

View File

@ -13,6 +13,8 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
// @todo check Vectors, we can simplify this!!!
// int32_t vectors // int32_t vectors
typedef union { typedef union {
struct { struct {

935
Stdlib/SIMD/SIMD_F32.h Normal file
View File

@ -0,0 +1,935 @@
/**
* Karaka
*
* @package Stdlib
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef STDLIB_SIMD_F32_H
#define STDLIB_SIMD_F32_H
#include <immintrin.h>
#include <xmmintrin.h>
#include "../Types.h"
namespace Stdlib::SIMD
{
struct f32_4_simd {
union {
__m128 s;
f32 v[4];
};
};
struct f32_8_simd {
union {
__m256 s;
f32 v[8];
};
};
struct f32_16_simd {
union {
__m512 s;
f32 v[16];
};
};
inline f32_4_simd load_f32_4_simd(f32 *mem)
{
f32_4_simd simd;
simd.s = _mm_loadu_ps(mem);
return simd;
}
inline f32_4_simd init_f32_4_simd(f32 *mem)
{
f32_4_simd simd;
simd.s = _mm_set_ps(mem[0], mem[1], mem[2], mem[3]);
return simd;
}
inline void unload_f32_4_simd(f32_4_simd a, f32 *array) { _mm_store_ps(array, a.s); }
inline f32_8_simd load_f32_8_simd(f32 *mem)
{
f32_8_simd simd;
simd.s = _mm256_loadu_ps(mem);
return simd;
}
inline f32_8_simd init_f32_8_simd(f32 *mem)
{
f32_8_simd simd;
simd.s = _mm256_set_ps(mem[0], mem[1], mem[2], mem[3], mem[4], mem[5], mem[6], mem[7]);
return simd;
}
inline void unload_f32_8_simd(f32_8_simd a, f32 *array) { _mm256_store_ps(array, a.s); }
inline f32_16_simd load_f32_16_simd(f32 *mem)
{
f32_16_simd simd;
simd.s = _mm512_loadu_ps(mem);
return simd;
}
inline f32_16_simd init_f32_16_simd(f32 *mem)
{
f32_16_simd simd;
simd.s = _mm512_set_ps(mem[0], mem[1], mem[2], mem[3], mem[4], mem[5], mem[6], mem[7], mem[8], mem[9], mem[10],
mem[11], mem[12], mem[13], mem[14], mem[15]);
return simd;
}
inline void unload_f32_16_simd(f32_16_simd a, f32 *array) { _mm512_store_ps(array, a.s); }
inline f32_4_simd init_zero_f32_4_simd()
{
f32_4_simd simd;
simd.s = _mm_setzero_ps();
return simd;
}
inline f32_8_simd init_zero_f32_8_simd()
{
f32_8_simd simd;
simd.s = _mm256_setzero_ps();
return simd;
}
inline f32_16_simd init_zero_f32_16_simd()
{
f32_16_simd simd;
simd.s = _mm512_setzero_ps();
return simd;
}
inline f32_4_simd operator+(f32_4_simd a, f32_4_simd b)
{
f32_4_simd simd;
simd.s = _mm_add_ps(a.s, b.s);
return simd;
}
inline f32_8_simd operator+(f32_8_simd a, f32_8_simd b)
{
f32_8_simd simd;
simd.s = _mm256_add_ps(a.s, b.s);
return simd;
}
inline f32_16_simd operator+(f32_16_simd a, f32_16_simd b)
{
f32_16_simd simd;
simd.s = _mm512_add_ps(a.s, b.s);
return simd;
}
inline f32_4_simd operator-(f32_4_simd a, f32_4_simd b)
{
f32_4_simd simd;
simd.s = _mm_sub_ps(a.s, b.s);
return simd;
}
inline f32_4_simd operator-(f32_4_simd a) { return init_zero_f32_4_simd() - a; }
inline f32_8_simd operator-(f32_8_simd a, f32_8_simd b)
{
f32_8_simd simd;
simd.s = _mm256_sub_ps(a.s, b.s);
return simd;
}
inline f32_8_simd operator-(f32_8_simd a) { return init_zero_f32_8_simd() - a; }
inline f32_16_simd operator-(f32_16_simd a, f32_16_simd b)
{
f32_16_simd simd;
simd.s = _mm512_sub_ps(a.s, b.s);
return simd;
}
inline f32_16_simd operator-(f32_16_simd a) { return init_zero_f32_16_simd() - a; }
inline f32_4_simd operator*(f32_4_simd a, f32_4_simd b)
{
f32_4_simd simd;
simd.s = _mm_mul_ps(a.s, b.s);
return simd;
}
inline f32_8_simd operator*(f32_8_simd a, f32_8_simd b)
{
f32_8_simd simd;
simd.s = _mm256_mul_ps(a.s, b.s);
return simd;
}
inline f32_16_simd operator*(f32_16_simd a, f32_16_simd b)
{
f32_16_simd simd;
simd.s = _mm512_mul_ps(a.s, b.s);
return simd;
}
inline f32_4_simd operator/(f32_4_simd a, f32_4_simd b)
{
f32_4_simd simd;
simd.s = _mm_div_ps(a.s, b.s);
return simd;
}
inline f32_8_simd operator/(f32_8_simd a, f32_8_simd b)
{
f32_8_simd simd;
simd.s = _mm256_div_ps(a.s, b.s);
return simd;
}
inline f32_16_simd operator/(f32_16_simd a, f32_16_simd b)
{
f32_16_simd simd;
simd.s = _mm512_div_ps(a.s, b.s);
return simd;
}
inline f32_4_simd operator^(f32_4_simd a, f32_4_simd b)
{
f32_4_simd simd;
simd.s = _mm_xor_ps(a.s, b.s);
return simd;
}
inline f32_8_simd operator^(f32_8_simd a, f32_8_simd b)
{
f32_8_simd simd;
simd.s = _mm256_xor_ps(a.s, b.s);
return simd;
}
inline f32_16_simd operator^(f32_16_simd a, f32_16_simd b)
{
f32_16_simd simd;
simd.s = _mm512_xor_ps(a.s, b.s);
return simd;
}
inline f32_4_simd &operator-=(f32_4_simd &a, f32_4_simd b)
{
a = a - b;
return a;
}
inline f32_8_simd &operator-=(f32_8_simd &a, f32_8_simd b)
{
a = a - b;
return a;
}
inline f32_16_simd &operator-=(f32_16_simd &a, f32_16_simd b)
{
a = a - b;
return a;
}
inline f32_4_simd &operator+=(f32_4_simd &a, f32_4_simd b)
{
a = a + b;
return a;
}
inline f32_8_simd &operator+=(f32_8_simd &a, f32_8_simd b)
{
a = a + b;
return a;
}
inline f32_16_simd &operator+=(f32_16_simd &a, f32_16_simd b)
{
a = a + b;
return a;
}
inline f32_4_simd &operator*=(f32_4_simd &a, f32_4_simd b)
{
a = a * b;
return a;
}
inline f32_8_simd &operator*=(f32_8_simd &a, f32_8_simd b)
{
a = a * b;
return a;
}
inline f32_16_simd &operator*=(f32_16_simd &a, f32_16_simd b)
{
a = a * b;
return a;
}
inline f32_4_simd &operator/=(f32_4_simd &a, f32_4_simd b)
{
a = a / b;
return a;
}
inline f32_8_simd &operator/=(f32_8_simd &a, f32_8_simd b)
{
a = a / b;
return a;
}
inline f32_16_simd &operator/=(f32_16_simd &a, f32_16_simd b)
{
a = a / b;
return a;
}
inline f32_4_simd &operator^=(f32_4_simd &a, f32_4_simd b)
{
a = a ^ b;
return a;
}
inline f32_8_simd &operator^=(f32_8_simd &a, f32_8_simd b)
{
a = a ^ b;
return a;
}
inline f32_16_simd &operator^=(f32_16_simd &a, f32_16_simd b)
{
a = a ^ b;
return a;
}
inline f32_4_simd operator<(f32_4_simd a, f32_4_simd b)
{
f32_4_simd simd;
simd.s = _mm_cmplt_ps(a.s, b.s);
return simd;
}
inline f32_8_simd operator<(f32_8_simd a, f32_8_simd b)
{
f32_8_simd simd;
simd.s = _mm256_cmp_ps(a.s, b.s, _CMP_LT_OQ);
return simd;
}
inline f32_16_simd operator<(f32_16_simd a, f32_16_simd b)
{
f32_16_simd simd;
simd.s = _mm512_mask_blend_ps(_mm512_cmplt_ps_mask(a.s, b.s), a.s, b.s);
return simd;
}
inline f32_4_simd operator<=(f32_4_simd a, f32_4_simd b)
{
f32_4_simd simd;
simd.s = _mm_cmple_ps(a.s, b.s);
return simd;
}
inline f32_8_simd operator<=(f32_8_simd a, f32_8_simd b)
{
f32_8_simd simd;
simd.s = _mm256_cmp_ps(a.s, b.s, _CMP_LE_OQ);
return simd;
}
inline f32_16_simd operator<=(f32_16_simd a, f32_16_simd b)
{
f32_16_simd simd;
simd.s = _mm512_mask_blend_ps(_mm512_cmp_ps_mask(a.s, b.s, _CMP_LE_OQ), a.s, b.s);
return simd;
}
inline f32_4_simd operator>(f32_4_simd a, f32_4_simd b)
{
f32_4_simd simd;
simd.s = _mm_cmpgt_ps(a.s, b.s);
return simd;
}
inline f32_8_simd operator>(f32_8_simd a, f32_8_simd b)
{
f32_8_simd simd;
simd.s = _mm256_cmp_ps(a.s, b.s, _CMP_GT_OQ);
return simd;
}
inline f32_16_simd operator>(f32_16_simd a, f32_16_simd b)
{
f32_16_simd simd;
simd.s = _mm512_mask_blend_ps(_mm512_cmp_ps_mask(a.s, b.s, _CMP_GT_OQ), a.s, b.s);
return simd;
}
inline f32_4_simd operator>=(f32_4_simd a, f32_4_simd b)
{
f32_4_simd simd;
simd.s = _mm_cmpge_ps(a.s, b.s);
return simd;
}
inline f32_8_simd operator>=(f32_8_simd a, f32_8_simd b)
{
f32_8_simd simd;
simd.s = _mm256_cmp_ps(a.s, b.s, _CMP_GE_OQ);
return simd;
}
inline f32_16_simd operator>=(f32_16_simd a, f32_16_simd b)
{
f32_16_simd simd;
simd.s = _mm512_mask_blend_ps(_mm512_cmp_ps_mask(a.s, b.s, _CMP_GE_OQ), a.s, b.s);
return simd;
}
inline f32_4_simd operator==(f32_4_simd a, f32_4_simd b)
{
f32_4_simd simd;
simd.s = _mm_cmpeq_ps(a.s, b.s);
return simd;
}
inline f32_8_simd operator==(f32_8_simd a, f32_8_simd b)
{
f32_8_simd simd;
simd.s = _mm256_cmp_ps(a.s, b.s, _CMP_EQ_OQ);
return simd;
}
inline f32_16_simd operator==(f32_16_simd a, f32_16_simd b)
{
f32_16_simd simd;
simd.s = _mm512_mask_blend_ps(_mm512_cmp_ps_mask(a.s, b.s, _CMP_EQ_OQ), a.s, b.s);
return simd;
}
inline f32_4_simd operator!=(f32_4_simd a, f32_4_simd b)
{
f32_4_simd simd;
simd.s = _mm_cmpneq_ps(a.s, b.s);
return simd;
}
inline f32_8_simd operator!=(f32_8_simd a, f32_8_simd b)
{
f32_8_simd simd;
simd.s = _mm256_cmp_ps(a.s, b.s, _CMP_NEQ_OQ);
return simd;
}
inline f32_16_simd operator!=(f32_16_simd a, f32_16_simd b)
{
f32_16_simd simd;
simd.s = _mm512_mask_blend_ps(_mm512_cmp_ps_mask(a.s, b.s, _CMP_NEQ_OQ), a.s, b.s);
return simd;
}
inline f32_4_simd operator&(f32_4_simd a, f32_4_simd b)
{
f32_4_simd simd;
simd.s = _mm_and_ps(a.s, b.s);
return simd;
}
inline f32_8_simd operator&(f32_8_simd a, f32_8_simd b)
{
f32_8_simd simd;
simd.s = _mm256_and_ps(a.s, b.s);
return simd;
}
inline f32_16_simd operator&(f32_16_simd a, f32_16_simd b)
{
f32_16_simd simd;
simd.s = _mm512_and_ps(a.s, b.s);
return simd;
}
inline f32_4_simd operator|(f32_4_simd a, f32_4_simd b)
{
f32_4_simd simd;
simd.s = _mm_or_ps(a.s, b.s);
return simd;
}
inline f32_8_simd operator|(f32_8_simd a, f32_8_simd b)
{
f32_8_simd simd;
simd.s = _mm256_or_ps(a.s, b.s);
return simd;
}
inline f32_16_simd operator|(f32_16_simd a, f32_16_simd b)
{
f32_16_simd simd;
simd.s = _mm512_or_ps(a.s, b.s);
return simd;
}
inline f32_4_simd &operator&=(f32_4_simd &a, f32_4_simd b)
{
a = a & b;
return a;
}
inline f32_8_simd &operator&=(f32_8_simd &a, f32_8_simd b)
{
a = a & b;
return a;
}
inline f32_16_simd &operator&=(f32_16_simd &a, f32_16_simd b)
{
a = a & b;
return a;
}
inline f32_4_simd &operator|=(f32_4_simd &a, f32_4_simd b)
{
a = a | b;
return a;
}
inline f32_8_simd &operator|=(f32_8_simd &a, f32_8_simd b)
{
a = a | b;
return a;
}
inline f32_16_simd &operator|=(f32_16_simd &a, f32_16_simd b)
{
a = a | b;
return a;
}
inline f32_4_simd abs(f32_4_simd a)
{
unsigned int unsigned_mask = (unsigned int) (1 << 31);
__m128 mask = _mm_set1_ps(*(float *) &unsigned_mask);
f32_4_simd simd;
simd.s = _mm_and_ps(a.s, mask);
return simd;
}
inline f32_8_simd abs(f32_8_simd a)
{
unsigned int unsigned_mask = (unsigned int) (1 << 31);
__m256 mask = _mm256_set1_ps(*(float *) &unsigned_mask);
f32_8_simd simd;
simd.s = _mm256_and_ps(a.s, mask);
return simd;
}
inline f32_16_simd abs(f32_16_simd a)
{
unsigned int unsigned_mask = (unsigned int) (1 << 31);
__m512 mask = _mm512_set1_ps(*(float *) &unsigned_mask);
f32_16_simd simd;
simd.s = _mm512_and_ps(a.s, mask);
return simd;
}
inline f32_4_simd min(f32_4_simd a, f32_4_simd b)
{
f32_4_simd simd;
simd.s = _mm_min_ps(a.s, b.s);
return simd;
}
inline f32_8_simd min(f32_8_simd a, f32_8_simd b)
{
f32_8_simd simd;
simd.s = _mm256_min_ps(a.s, b.s);
return simd;
}
inline f32_16_simd min(f32_16_simd a, f32_16_simd b)
{
f32_16_simd simd;
simd.s = _mm512_min_ps(a.s, b.s);
return simd;
}
inline f32_4_simd max(f32_4_simd a, f32_4_simd b)
{
f32_4_simd simd;
simd.s = _mm_max_ps(a.s, b.s);
return simd;
}
inline f32_8_simd max(f32_8_simd a, f32_8_simd b)
{
f32_8_simd simd;
simd.s = _mm256_max_ps(a.s, b.s);
return simd;
}
inline f32_16_simd max(f32_16_simd a, f32_16_simd b)
{
f32_16_simd simd;
simd.s = _mm512_max_ps(a.s, b.s);
return simd;
}
inline f32_4_simd sign(f32_4_simd a)
{
unsigned int umask = (unsigned int) (1 << 31);
__m128 mask = _mm_set1_ps(*(float *) &umask);
f32_4_simd signBit;
signBit.s = _mm_and_ps(a.s, mask);
f32_4_simd b;
b.s = _mm_set1_ps(1.0f);
f32_4_simd simd = b | signBit;
return simd;
}
inline f32_8_simd sign(f32_8_simd a)
{
unsigned int umask = (unsigned int) (1 << 31);
__m256 mask = _mm256_set1_ps(*(float *) &umask);
f32_8_simd signBit;
signBit.s = _mm256_and_ps(a.s, mask);
f32_8_simd b;
b.s = _mm256_set1_ps(1.0f);
f32_8_simd simd = b | signBit;
return simd;
}
inline f32_16_simd sign(f32_16_simd a)
{
unsigned int umask = (unsigned int) (1 << 31);
__m512 mask = _mm512_set1_ps(*(float *) &umask);
f32_16_simd signBit;
signBit.s = _mm512_and_ps(a.s, mask);
f32_16_simd b;
b.s = _mm512_set1_ps(1.0f);
f32_16_simd simd = b | signBit;
return simd;
}
inline f32_4_simd floor(f32_4_simd a)
{
f32_4_simd simd;
simd.s = _mm_floor_ps(a.s);
return simd;
}
inline f32_8_simd floor(f32_8_simd a)
{
f32_8_simd simd;
simd.s = _mm256_floor_ps(a.s);
return simd;
}
inline f32_16_simd floor(f32_16_simd a)
{
f32_16_simd simd;
simd.s = _mm512_floor_ps(a.s);
return simd;
}
inline f32_4_simd ceil(f32_4_simd a)
{
f32_4_simd simd;
simd.s = _mm_ceil_ps(a.s);
return simd;
}
inline f32_8_simd ceil(f32_8_simd a)
{
f32_8_simd simd;
simd.s = _mm256_ceil_ps(a.s);
return simd;
}
inline f32_16_simd ceil(f32_16_simd a)
{
f32_16_simd simd;
simd.s = _mm512_ceil_ps(a.s);
return simd;
}
inline f32_4_simd sqrt(f32_4_simd a)
{
f32_4_simd simd;
simd.s = _mm_sqrt_ps(a.s);
return simd;
}
inline f32_8_simd sqrt(f32_8_simd a)
{
f32_8_simd simd;
simd.s = _mm256_sqrt_ps(a.s);
return simd;
}
inline f32_16_simd sqrt(f32_16_simd a)
{
f32_16_simd simd;
simd.s = _mm512_sqrt_ps(a.s);
return simd;
}
inline f32_4_simd sqrt_inv_approx(f32_4_simd a)
{
f32_4_simd simd;
simd.s = _mm_rsqrt_ps(a.s);
return simd;
}
inline f32_8_simd sqrt_inv_approx(f32_8_simd a)
{
f32_8_simd simd;
simd.s = _mm256_rsqrt_ps(a.s);
return simd;
}
inline f32_16_simd sqrt_inv_approx(f32_16_simd a)
{
f32_16_simd simd;
simd.s = _mm512_rsqrt14_ps(a.s);
return simd;
}
inline f32_4_simd one_over_approx(f32_4_simd a)
{
f32_4_simd simd;
simd.s = _mm_rcp_ps(a.s);
return simd;
}
inline f32_8_simd one_over_approx(f32_8_simd a)
{
f32_8_simd simd;
simd.s = _mm256_rcp_ps(a.s);
return simd;
}
inline f32_16_simd one_over_approx(f32_16_simd a)
{
f32_16_simd simd;
simd.s = _mm512_rcp14_ps(a.s);
return simd;
}
inline f32_4_simd clamp(f32_4_simd min_value, f32_4_simd a, f32_4_simd max_value)
{
return min(max(a, min_value), max_value);
}
inline f32_8_simd clamp(f32_8_simd min_value, f32_8_simd a, f32_8_simd max_value)
{
return min(max(a, min_value), max_value);
}
inline f32_16_simd clamp(f32_16_simd min_value, f32_16_simd a, f32_16_simd max_value)
{
return min(max(a, min_value), max_value);
}
inline int32 which_true(f32_4_simd a)
{
int32 which_true = _mm_movemask_ps(a.s);
return which_true;
}
inline int32 which_true(f32_8_simd a)
{
int32 which_true = _mm256_movemask_ps(a.s);
return which_true;
}
inline int32 which_true(f32_16_simd a)
{
int32 which_true = _mm512_movepi32_mask(_mm512_castps_si512(a.s));
return which_true;
}
inline bool any_true(f32_4_simd a)
{
bool is_any_true = _mm_movemask_ps(a.s) > 0;
return is_any_true;
}
inline bool any_true(f32_8_simd a)
{
bool is_any_true = _mm256_movemask_ps(a.s) > 0;
return is_any_true;
}
inline bool any_true(f32_16_simd a)
{
bool is_any_true = _mm512_movepi32_mask(_mm512_castps_si512(a.s)) > 0;
return is_any_true;
}
inline bool all_true(f32_4_simd a)
{
bool is_true = (_mm_movemask_ps(a.s) == 15);
return is_true;
}
inline bool all_true(f32_8_simd a)
{
bool is_true = (_mm256_movemask_ps(a.s) == 255);
return is_true;
}
inline bool all_true(f32_16_simd a)
{
bool is_true = (_mm512_movepi32_mask(_mm512_castps_si512(a.s)) == 65535);
return is_true;
}
inline bool all_false(f32_4_simd a)
{
bool is_false = (_mm_movemask_ps(a.s) == 0);
return is_false;
}
inline bool all_false(f32_8_simd a)
{
bool is_false = (_mm256_movemask_ps(a.s) == 0);
return is_false;
}
inline bool all_false(f32_16_simd a)
{
// @todo This can be optimized (requires also changes in the comparison functions return)
bool is_false = (_mm512_movepi32_mask(_mm512_castps_si512(a.s)) == 0);
return is_false;
}
} // namespace Stdlib::SIMD
#endif

58
Stdlib/SIMD/SIMD_Helper.h Normal file
View File

@ -0,0 +1,58 @@
/**
* Karaka
*
* @package Stdlib
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef STDLIB_SIMD_HELPER_H
#define STDLIB_SIMD_HELPER_H
#include <immintrin.h>
#include <stdint.h>
#include <xmmintrin.h>
namespace Stdlib::SIMD
{
bool is_avx_supported()
{
uint32_t eax, ebx, ecx, edx;
eax = 1; // CPUID function 1
__asm__ __volatile__("cpuid;" : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) : "a"(eax));
// Check the AVX feature bit in ECX
return (ecx >> 28) & 1;
}
bool is_avx256_supported()
{
uint32_t eax, ebx, ecx, edx;
eax = 7; // CPUID function 7
ecx = 0; // Sub-function 0
__asm__ __volatile__("cpuid;" : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) : "a"(eax), "c"(ecx));
// Check the AVX-256 (AVX2) feature bit in EBX
return (ebx >> 5) & 1;
}
bool is_avx512_supported()
{
uint32_t eax, ebx, ecx, edx;
eax = 7; // CPUID function 7
ecx = 0; // Sub-function 0
__asm__ __volatile__("cpuid;" : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) : "a"(eax), "c"(ecx));
// Check the AVX-512 feature bit in EBX
return (ebx >> 16) & 1;
}
} // namespace Stdlib::SIMD
#endif

937
Stdlib/SIMD/SIMD_I32.h Normal file
View File

@ -0,0 +1,937 @@
/**
* Karaka
*
* @package Stdlib
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef STDLIB_SIMD_I32_H
#define STDLIB_SIMD_I32_H
#include <immintrin.h>
#include <xmmintrin.h>
#include "../Types.h"
#include "SIMD_F32.h"
namespace Stdlib::SIMD
{
struct int32_4_simd {
union {
__m128i s;
int32 v[4];
};
};
struct int32_8_simd {
union {
__m256i s;
int32 v[8];
};
};
struct int32_16_simd {
union {
__m512i s;
int32 v[16];
};
};
inline int32_4_simd load_int32_4_simd(int32 *mem)
{
int32_4_simd simd;
simd.s = _mm_loadu_epi32(mem);
return simd;
}
inline int32_4_simd init_int32_4_simd(int32 *mem)
{
int32_4_simd simd;
simd.s = _mm_set_epi32(mem[0], mem[1], mem[2], mem[3]);
return simd;
}
inline void unload_int32_4_simd(int32_4_simd a, int32 *array) { _mm_store_epi32(array, a.s); }
inline int32_8_simd load_int32_8_simd(int32 *mem)
{
int32_8_simd simd;
simd.s = _mm256_loadu_epi32(mem);
return simd;
}
inline int32_8_simd init_int32_8_simd(int32 *mem)
{
int32_8_simd simd;
simd.s = _mm256_set_epi32(mem[0], mem[1], mem[2], mem[3], mem[4], mem[5], mem[6], mem[7]);
return simd;
}
inline void unload_int32_8_simd(int32_8_simd a, int32 *array) { _mm256_store_epi32(array, a.s); }
inline int32_16_simd load_int32_16_simd(int32 *mem)
{
int32_16_simd simd;
simd.s = _mm512_loadu_epi32(mem);
return simd;
}
inline int32_16_simd init_int32_16_simd(int32 *mem)
{
int32_16_simd simd;
simd.s = _mm512_set_epi32(mem[0], mem[1], mem[2], mem[3], mem[4], mem[5], mem[6], mem[7], mem[8], mem[9],
mem[10], mem[11], mem[12], mem[13], mem[14], mem[15]);
return simd;
}
inline void unload_int32_16_simd(int32_16_simd a, int32 *array) { _mm512_store_epi32(array, a.s); }
inline int32_4_simd init_zero_int32_4_simd()
{
int32_4_simd simd;
simd.s = _mm_setzero_si128();
return simd;
}
inline int32_8_simd init_zero_int32_8_simd()
{
int32_8_simd simd;
simd.s = _mm256_setzero_si256();
return simd;
}
inline int32_16_simd init_zero_int32_16_simd()
{
int32_16_simd simd;
simd.s = _mm512_setzero_epi32();
return simd;
}
inline int32_4_simd operator+(int32_4_simd a, int32_4_simd b)
{
int32_4_simd simd;
simd.s = _mm_add_epi32(a.s, b.s);
return simd;
}
inline int32_8_simd operator+(int32_8_simd a, int32_8_simd b)
{
int32_8_simd simd;
simd.s = _mm256_add_epi32(a.s, b.s);
return simd;
}
inline int32_16_simd operator+(int32_16_simd a, int32_16_simd b)
{
int32_16_simd simd;
simd.s = _mm512_add_epi32(a.s, b.s);
return simd;
}
inline int32_4_simd operator-(int32_4_simd a, int32_4_simd b)
{
int32_4_simd simd;
simd.s = _mm_sub_epi32(a.s, b.s);
return simd;
}
inline int32_4_simd operator-(int32_4_simd a) { return init_zero_int32_4_simd() - a; }
inline int32_8_simd operator-(int32_8_simd a, int32_8_simd b)
{
int32_8_simd simd;
simd.s = _mm256_sub_epi32(a.s, b.s);
return simd;
}
inline int32_8_simd operator-(int32_8_simd a) { return init_zero_int32_8_simd() - a; }
inline int32_16_simd operator-(int32_16_simd a, int32_16_simd b)
{
int32_16_simd simd;
simd.s = _mm512_sub_epi32(a.s, b.s);
return simd;
}
inline int32_16_simd operator-(int32_16_simd a) { return init_zero_int32_16_simd() - a; }
inline int32_4_simd operator*(int32_4_simd a, int32_4_simd b)
{
int32_4_simd simd;
simd.s = _mm_mul_epi32(a.s, b.s);
return simd;
}
inline int32_8_simd operator*(int32_8_simd a, int32_8_simd b)
{
int32_8_simd simd;
simd.s = _mm256_mul_epi32(a.s, b.s);
return simd;
}
inline int32_16_simd operator*(int32_16_simd a, int32_16_simd b)
{
int32_16_simd simd;
simd.s = _mm512_mul_epi32(a.s, b.s);
return simd;
}
inline Stdlib::SIMD::f32_4_simd operator/(int32_4_simd a, int32_4_simd b)
{
Stdlib::SIMD::f32_4_simd simd;
simd.s = _mm_div_ps(a.s, b.s);
return simd;
}
inline Stdlib::SIMD::f32_8_simd operator/(int32_8_simd a, int32_8_simd b)
{
Stdlib::SIMD::f32_8_simd simd;
simd.s = _mm256_div_ps(a.s, b.s);
return simd;
}
inline Stdlib::SIMD::f32_16_simd operator/(int32_16_simd a, int32_16_simd b)
{
Stdlib::SIMD::f32_16_simd simd;
simd.s = _mm512_div_ps(a.s, b.s);
return simd;
}
inline int32_4_simd operator^(int32_4_simd a, int32_4_simd b)
{
int32_4_simd simd;
simd.s = _mm_xor_epi32(a.s, b.s);
return simd;
}
inline int32_8_simd operator^(int32_8_simd a, int32_8_simd b)
{
int32_8_simd simd;
simd.s = _mm256_xor_epi32(a.s, b.s);
return simd;
}
inline int32_16_simd operator^(int32_16_simd a, int32_16_simd b)
{
int32_16_simd simd;
simd.s = _mm512_xor_epi32(a.s, b.s);
return simd;
}
inline int32_4_simd &operator-=(int32_4_simd &a, int32_4_simd b)
{
a = a - b;
return a;
}
inline int32_8_simd &operator-=(int32_8_simd &a, int32_8_simd b)
{
a = a - b;
return a;
}
inline int32_16_simd &operator-=(int32_16_simd &a, int32_16_simd b)
{
a = a - b;
return a;
}
inline int32_4_simd &operator+=(int32_4_simd &a, int32_4_simd b)
{
a = a + b;
return a;
}
inline int32_8_simd &operator+=(int32_8_simd &a, int32_8_simd b)
{
a = a + b;
return a;
}
inline int32_16_simd &operator+=(int32_16_simd &a, int32_16_simd b)
{
a = a + b;
return a;
}
inline int32_4_simd &operator*=(int32_4_simd &a, int32_4_simd b)
{
a = a * b;
return a;
}
inline int32_8_simd &operator*=(int32_8_simd &a, int32_8_simd b)
{
a = a * b;
return a;
}
inline int32_16_simd &operator*=(int32_16_simd &a, int32_16_simd b)
{
a = a * b;
return a;
}
inline int32_4_simd &operator/=(int32_4_simd &a, int32_4_simd b)
{
a.s = _mm_cvtps_epi32((a / b).s);
return a;
}
inline int32_8_simd &operator/=(int32_8_simd &a, int32_8_simd b)
{
a.s = _mm256_cvtps_epi32((a / b).s);
return a;
}
inline int32_16_simd &operator/=(int32_16_simd &a, int32_16_simd b)
{
a.s = _mm512_cvtps_epi32((a / b).s);
return a;
}
inline int32_4_simd &operator^=(int32_4_simd &a, int32_4_simd b)
{
a = a ^ b;
return a;
}
inline int32_8_simd &operator^=(int32_8_simd &a, int32_8_simd b)
{
a = a ^ b;
return a;
}
inline int32_16_simd &operator^=(int32_16_simd &a, int32_16_simd b)
{
a = a ^ b;
return a;
}
inline int32_4_simd operator<(int32_4_simd a, int32_4_simd b)
{
int32_4_simd simd;
simd.s = _mm_cmplt_epi32(a.s, b.s);
return simd;
}
inline int32_8_simd operator<(int32_8_simd a, int32_8_simd b)
{
int32_8_simd simd;
simd.s = _mm256_xor_si256(_mm256_cmpgt_epi32(a.s, b.s), _mm256_set1_epi32(-1));
return simd;
}
inline int32_16_simd operator<(int32_16_simd a, int32_16_simd b)
{
int32_16_simd simd;
simd.s = _mm512_mask_blend_epi32(_mm512_cmplt_epi32_mask(a.s, b.s), a.s, b.s);
return simd;
}
inline int32_4_simd operator<=(int32_4_simd a, int32_4_simd b)
{
int32_4_simd simd;
simd.s = _mm_andnot_si128(_mm_cmplt_epi32(b.s, a.s), _mm_set1_epi32(-1));
return simd;
}
inline int32_8_simd operator<=(int32_8_simd a, int32_8_simd b)
{
int32_8_simd simd;
simd.s = _mm256_andnot_si256(_mm256_cmpgt_epi32(a.s, b.s), _mm256_set1_epi32(-1));
return simd;
}
inline int32_16_simd operator<=(int32_16_simd a, int32_16_simd b)
{
int32_16_simd simd;
simd.s = _mm512_mask_blend_epi32(_mm512_knot(_mm512_cmpgt_epi32_mask(b.s, a.s)), b.s, a.s);
return simd;
}
inline int32_4_simd operator>(int32_4_simd a, int32_4_simd b)
{
int32_4_simd simd;
simd.s = _mm_cmpgt_epi32(a.s, b.s);
return simd;
}
inline int32_8_simd operator>(int32_8_simd a, int32_8_simd b)
{
int32_8_simd simd;
simd.s = _mm256_cmpgt_epi32(a.s, b.s);
return simd;
}
inline int32_16_simd operator>(int32_16_simd a, int32_16_simd b)
{
int32_16_simd simd;
simd.s = _mm512_mask_blend_ps(_mm512_cmpgt_epi32_mask(a.s, b.s), a.s, b.s);
return simd;
}
inline int32_4_simd operator>=(int32_4_simd a, int32_4_simd b)
{
int32_4_simd simd;
simd.s = _mm_andnot_si128(_mm_cmplt_epi32(a.s, b.s), _mm_set1_epi32(-1));
return simd;
}
inline int32_8_simd operator>=(int32_8_simd a, int32_8_simd b)
{
int32_8_simd simd;
simd.s = _mm256_andnot_si256(_mm256_cmpgt_epi32(b.s, a.s), _mm256_set1_epi32(-1));
return simd;
}
inline int32_16_simd operator>=(int32_16_simd a, int32_16_simd b)
{
int32_16_simd simd;
simd.s = _mm512_mask_blend_ps(_mm512_cmpge_epi32_mask(a.s, b.s), a.s, b.s);
return simd;
}
inline int32_4_simd operator==(int32_4_simd a, int32_4_simd b)
{
int32_4_simd simd;
simd.s = _mm_cmpeq_epi32(a.s, b.s);
return simd;
}
inline int32_8_simd operator==(int32_8_simd a, int32_8_simd b)
{
int32_8_simd simd;
simd.s = _mm256_cmpeq_epi32(a.s, b.s);
return simd;
}
inline int32_16_simd operator==(int32_16_simd a, int32_16_simd b)
{
int32_16_simd simd;
simd.s = _mm512_mask_blend_ps(_mm512_cmpeq_epi32_mask(a.s, b.s), a.s, b.s);
return simd;
}
inline int32_4_simd operator!=(int32_4_simd a, int32_4_simd b)
{
int32_4_simd simd;
simd.s = _mm_cmpneq_epi32(a.s, b.s);
return simd;
}
inline int32_8_simd operator!=(int32_8_simd a, int32_8_simd b)
{
int32_8_simd simd;
simd.s = _mm256_cmp_epi32(a.s, b.s, _CMP_NEQ_OQ);
return simd;
}
inline int32_16_simd operator!=(int32_16_simd a, int32_16_simd b)
{
int32_16_simd simd;
simd.s = _mm512_mask_mov_epi32(_mm512_setzero_epi32(), _mm512_cmp_ps_mask(a.s, b.s, _CMP_NEQ_OQ),
_mm512_set1_epi32(1.0f));
return simd;
}
inline int32_4_simd operator&(int32_4_simd a, int32_4_simd b)
{
int32_4_simd simd;
simd.s = _mm_and_epi32(a.s, b.s);
return simd;
}
inline int32_8_simd operator&(int32_8_simd a, int32_8_simd b)
{
int32_8_simd simd;
simd.s = _mm256_and_epi32(a.s, b.s);
return simd;
}
inline int32_16_simd operator&(int32_16_simd a, int32_16_simd b)
{
int32_16_simd simd;
simd.s = _mm512_and_epi32(a.s, b.s);
return simd;
}
inline int32_4_simd operator|(int32_4_simd a, int32_4_simd b)
{
int32_4_simd simd;
simd.s = _mm_or_epi32(a.s, b.s);
return simd;
}
inline int32_8_simd operator|(int32_8_simd a, int32_8_simd b)
{
int32_8_simd simd;
simd.s = _mm256_or_epi32(a.s, b.s);
return simd;
}
inline int32_16_simd operator|(int32_16_simd a, int32_16_simd b)
{
int32_16_simd simd;
simd.s = _mm512_or_epi32(a.s, b.s);
return simd;
}
inline int32_4_simd &operator&=(int32_4_simd &a, int32_4_simd b)
{
a = a & b;
return a;
}
inline int32_8_simd &operator&=(int32_8_simd &a, int32_8_simd b)
{
a = a & b;
return a;
}
inline int32_16_simd &operator&=(int32_16_simd &a, int32_16_simd b)
{
a = a & b;
return a;
}
inline int32_4_simd &operator|=(int32_4_simd &a, int32_4_simd b)
{
a = a | b;
return a;
}
inline int32_8_simd &operator|=(int32_8_simd &a, int32_8_simd b)
{
a = a | b;
return a;
}
inline int32_16_simd &operator|=(int32_16_simd &a, int32_16_simd b)
{
a = a | b;
return a;
}
inline int32_4_simd abs(int32_4_simd a)
{
unsigned int unsigned_mask = (unsigned int) (1 << 31);
__m128 mask = _mm_set1_epi32(*(float *) &unsigned_mask);
int32_4_simd simd;
simd.s = _mm_and_epi32(a.s, mask);
return simd;
}
inline int32_8_simd abs(int32_8_simd a)
{
unsigned int unsigned_mask = (unsigned int) (1 << 31);
__m256 mask = _mm256_set1_epi32(*(float *) &unsigned_mask);
int32_8_simd simd;
simd.s = _mm256_and_epi32(a.s, mask);
return simd;
}
inline int32_16_simd abs(int32_16_simd a)
{
unsigned int unsigned_mask = (unsigned int) (1 << 31);
__m512 mask = _mm512_set1_epi32(*(float *) &unsigned_mask);
int32_16_simd simd;
simd.s = _mm512_and_epi32(a.s, mask);
return simd;
}
inline int32_4_simd min(int32_4_simd a, int32_4_simd b)
{
int32_4_simd simd;
simd.s = _mm_min_epi32(a.s, b.s);
return simd;
}
inline int32_8_simd min(int32_8_simd a, int32_8_simd b)
{
int32_8_simd simd;
simd.s = _mm256_min_epi32(a.s, b.s);
return simd;
}
inline int32_16_simd min(int32_16_simd a, int32_16_simd b)
{
int32_16_simd simd;
simd.s = _mm512_min_epi32(a.s, b.s);
return simd;
}
inline int32_4_simd max(int32_4_simd a, int32_4_simd b)
{
int32_4_simd simd;
simd.s = _mm_max_epi32(a.s, b.s);
return simd;
}
inline int32_8_simd max(int32_8_simd a, int32_8_simd b)
{
int32_8_simd simd;
simd.s = _mm256_max_epi32(a.s, b.s);
return simd;
}
inline int32_16_simd max(int32_16_simd a, int32_16_simd b)
{
int32_16_simd simd;
simd.s = _mm512_max_epi32(a.s, b.s);
return simd;
}
inline int32_4_simd sign(int32_4_simd a)
{
unsigned int umask = (unsigned int) (1 << 31);
__m128 mask = _mm_set1_epi32(*(float *) &umask);
int32_4_simd signBit;
signBit.s = _mm_and_epi32(a.s, mask);
int32_4_simd b;
b.s = _mm_set1_epi32(1.0f);
int32_4_simd simd = b | signBit;
return simd;
}
inline int32_8_simd sign(int32_8_simd a)
{
unsigned int umask = (unsigned int) (1 << 31);
__m256 mask = _mm256_set1_epi32(*(float *) &umask);
int32_8_simd signBit;
signBit.s = _mm256_and_epi32(a.s, mask);
int32_8_simd b;
b.s = _mm256_set1_epi32(1.0f);
int32_8_simd simd = b | signBit;
return simd;
}
inline int32_16_simd sign(int32_16_simd a)
{
unsigned int umask = (unsigned int) (1 << 31);
__m512 mask = _mm512_set1_epi32(*(float *) &umask);
int32_16_simd signBit;
signBit.s = _mm512_and_epi32(a.s, mask);
int32_16_simd b;
b.s = _mm512_set1_epi32(1.0f);
int32_16_simd simd = b | signBit;
return simd;
}
inline int32_4_simd floor(int32_4_simd a)
{
int32_4_simd simd;
simd.s = _mm_floor_epi32(a.s);
return simd;
}
inline int32_8_simd floor(int32_8_simd a)
{
int32_8_simd simd;
simd.s = _mm256_floor_epi32(a.s);
return simd;
}
inline int32_16_simd floor(int32_16_simd a)
{
int32_16_simd simd;
simd.s = _mm512_floor_epi32(a.s);
return simd;
}
inline int32_4_simd ceil(int32_4_simd a)
{
int32_4_simd simd;
simd.s = _mm_ceil_epi32(a.s);
return simd;
}
inline int32_8_simd ceil(int32_8_simd a)
{
int32_8_simd simd;
simd.s = _mm256_ceil_epi32(a.s);
return simd;
}
inline int32_16_simd ceil(int32_16_simd a)
{
int32_16_simd simd;
simd.s = _mm512_ceil_epi32(a.s);
return simd;
}
inline int32_4_simd sqrt(int32_4_simd a)
{
int32_4_simd simd;
simd.s = _mm_sqrt_epi32(a.s);
return simd;
}
inline int32_8_simd sqrt(int32_8_simd a)
{
int32_8_simd simd;
simd.s = _mm256_sqrt_epi32(a.s);
return simd;
}
inline int32_16_simd sqrt(int32_16_simd a)
{
int32_16_simd simd;
simd.s = _mm512_sqrt_epi32(a.s);
return simd;
}
inline int32_4_simd sqrt_inv_approx(int32_4_simd a)
{
int32_4_simd simd;
simd.s = _mm_rsqrt_epi32(a.s);
return simd;
}
inline int32_8_simd sqrt_inv_approx(int32_8_simd a)
{
int32_8_simd simd;
simd.s = _mm256_rsqrt_epi32(a.s);
return simd;
}
inline int32_16_simd sqrt_inv_approx(int32_16_simd a)
{
int32_16_simd simd;
simd.s = _mm512_rsqrt14_epi32(a.s);
return simd;
}
inline int32_4_simd one_over_approx(int32_4_simd a)
{
int32_4_simd simd;
simd.s = _mm_rcp_epi32(a.s);
return simd;
}
inline int32_8_simd one_over_approx(int32_8_simd a)
{
int32_8_simd simd;
simd.s = _mm256_rcp_epi32(a.s);
return simd;
}
inline int32_16_simd one_over_approx(int32_16_simd a)
{
int32_16_simd simd;
simd.s = _mm512_rcp14_epi32(a.s);
return simd;
}
inline int32_4_simd clamp(int32_4_simd min_value, int32_4_simd a, int32_4_simd max_value)
{
return min(max(a, min_value), max_value);
}
inline int32_8_simd clamp(int32_8_simd min_value, int32_8_simd a, int32_8_simd max_value)
{
return min(max(a, min_value), max_value);
}
inline int32_16_simd clamp(int32_16_simd min_value, int32_16_simd a, int32_16_simd max_value)
{
return min(max(a, min_value), max_value);
}
inline int32 which_true(int32_4_simd a)
{
int32 which_true = _mm_movemask_epi32(a.s);
return which_true;
}
inline int32 which_true(int32_8_simd a)
{
int32 which_true = _mm256_movemask_epi32(a.s);
return which_true;
}
inline int32 which_true(int32_16_simd a)
{
int32 which_true = _mm512_movepi32_mask(_mm512_castps_si512(a.s));
return which_true;
}
inline bool any_true(int32_4_simd a)
{
bool is_any_true = _mm_movemask_epi32(a.s) > 0;
return is_any_true;
}
inline bool any_true(int32_8_simd a)
{
bool is_any_true = _mm256_movemask_epi32(a.s) > 0;
return is_any_true;
}
inline bool any_true(int32_16_simd a)
{
bool is_any_true = _mm512_movepi32_mask(_mm512_castps_si512(a.s)) > 0;
return is_any_true;
}
inline bool all_true(int32_4_simd a)
{
bool is_true = (_mm_movemask_epi32(a.s) == 15);
return is_true;
}
inline bool all_true(int32_8_simd a)
{
bool is_true = (_mm256_movemask_epi32(a.s) == 255);
return is_true;
}
inline bool all_true(int32_16_simd a)
{
bool is_true = (_mm512_movepi32_mask(_mm512_castps_si512(a.s)) == 65535);
return is_true;
}
inline bool all_false(int32_4_simd a)
{
bool is_false = (_mm_movemask_epi32(a.s) == 0);
return is_false;
}
inline bool all_false(int32_8_simd a)
{
bool is_false = (_mm256_movemask_epi32(a.s) == 0);
return is_false;
}
inline bool all_false(int32_16_simd a)
{
// @todo This can be optimized (requires also changes in the comparison functions return)
bool is_false = (_mm512_movepi32_mask(_mm512_castps_si512(a.s)) == 0);
return is_false;
}
} // namespace Stdlib::SIMD
#endif

29
Stdlib/Types.h Normal file
View File

@ -0,0 +1,29 @@
/**
* Karaka
*
* @package Stdlib
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef STDLIB_TYPES_H
#define STDLIB_TYPES_H
#include <float.h>
#include <stdint.h>
typedef int8_t int8;
typedef int16_t int16;
typedef int32_t int32;
typedef int64_t int64;
typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;
typedef float f32;
typedef double f64;
#endif

View File

@ -19,6 +19,7 @@ namespace Threads
struct job_t { struct job_t {
JobFunc func; JobFunc func;
void *arg; void *arg;
int state;
job_t *next; job_t *next;
}; };

View File

@ -19,38 +19,26 @@ namespace Threads
{ {
Job *pool_work_create(JobFunc func, void *arg) Job *pool_work_create(JobFunc func, void *arg)
{ {
Job *work;
if (func == NULL) { if (func == NULL) {
return NULL; return NULL;
} }
work = (Job *) malloc(sizeof(*work)); Job *work = (Job *) malloc(sizeof(*work));
work->func = func; work->func = func;
work->arg = arg; work->arg = arg;
work->state = 0;
work->next = NULL; work->next = NULL;
return work; return work;
} }
void pool_work_destroy(Job *work) Job *pool_work_poll(Threads::ThreadPool *pool)
{ {
if (work == NULL) {
return;
}
free(work);
}
Job *pool_work_get(Threads::ThreadPool *pool)
{
Job *work;
if (pool == NULL) { if (pool == NULL) {
return NULL; return NULL;
} }
work = pool->work_first; Job *work = pool->work_first;
if (work == NULL) { if (work == NULL) {
return NULL; return NULL;
} }
@ -70,7 +58,7 @@ namespace Threads
Threads::ThreadPool *pool = (Threads::ThreadPool *) arg; Threads::ThreadPool *pool = (Threads::ThreadPool *) arg;
Threads::Job *work; Threads::Job *work;
while (1) { while (true) {
pthread_mutex_lock(&(pool->work_mutex)); pthread_mutex_lock(&(pool->work_mutex));
while (pool->work_first == NULL && !pool->stop) { while (pool->work_first == NULL && !pool->stop) {
@ -81,13 +69,12 @@ namespace Threads
break; break;
} }
work = Threads::pool_work_get(pool); work = Threads::pool_work_poll(pool);
++(pool->working_cnt); ++(pool->working_cnt);
pthread_mutex_unlock(&(pool->work_mutex)); pthread_mutex_unlock(&(pool->work_mutex));
if (work != NULL) { if (work != NULL) {
work->func(work->arg); work->func(work);
pool_work_destroy(work);
} }
pthread_mutex_lock(&(pool->work_mutex)); pthread_mutex_lock(&(pool->work_mutex));
@ -155,20 +142,15 @@ namespace Threads
void pool_destroy(Threads::ThreadPool *pool) void pool_destroy(Threads::ThreadPool *pool)
{ {
Threads::Job *work;
Threads::Job *work2;
if (pool == NULL) { if (pool == NULL) {
return; return;
} }
pthread_mutex_lock(&(pool->work_mutex)); pthread_mutex_lock(&(pool->work_mutex));
work = pool->work_first; Threads::Job *work = pool->work_first;
while (work != NULL) { while (work != NULL) {
work2 = work->next; work = work->next;
pool_work_destroy(work);
work = work2;
} }
pool->stop = true; pool->stop = true;
@ -184,17 +166,15 @@ namespace Threads
free(pool); free(pool);
} }
bool pool_add_work(Threads::ThreadPool *pool, JobFunc func, void *arg) Threads::Job* pool_add_work(Threads::ThreadPool *pool, JobFunc func, void *arg)
{ {
Threads::Job *work;
if (pool == NULL) { if (pool == NULL) {
return false; return NULL;
} }
work = Threads::pool_work_create(func, arg); Threads::Job *work = Threads::pool_work_create(func, arg);
if (work == NULL) { if (work == NULL) {
return false; return NULL;
} }
pthread_mutex_lock(&(pool->work_mutex)); pthread_mutex_lock(&(pool->work_mutex));
@ -209,7 +189,7 @@ namespace Threads
pthread_cond_broadcast(&(pool->work_cond)); pthread_cond_broadcast(&(pool->work_cond));
pthread_mutex_unlock(&(pool->work_mutex)); pthread_mutex_unlock(&(pool->work_mutex));
return true; return work;
} }
} }

71
UI/window.h Normal file
View File

@ -0,0 +1,71 @@
#ifndef UI_WINDOW_H
#define UI_WINDOW_H
#ifdef _WIN32
#include <windows.h>
#include <windowsx.h>
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
#endif
namespace UI
{
typedef struct {
unsigned int width = 0;
unsigned int height = 0;
#ifdef _WIN32
HWND hwnd;
#endif
} window;
void window_open(window* w)
{
#ifdef _WIN32
ShowWindow(w->hwnd, SW_SHOW);
#endif
}
#ifdef _WIN32
void window_create_directx(window* w)
{
HINSTANCE hinstance = GetModuleHandle(nullptr);
WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hinstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = "WindowClass1";
RegisterClassEx(&wc);
RECT wr = {0, 0, 800, 600};
AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE);
w->hwnd = CreateWindowEx((DWORD) NULL,
wc.lpszClassName, NULL,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
wr.right - wr.left,
wr.bottom - wr.top,
NULL, NULL, hinstance, w
);
}
#endif
window* window_create(window* w)
{
#ifdef _WIN32
window_create_directx(w);
#endif
return w;
}
}
#endif

View File

@ -20,28 +20,26 @@ namespace Utils
{ {
namespace ApplicationUtils namespace ApplicationUtils
{ {
inline inline char *cwd()
char *cwd()
{ {
char *cwd = (char *) malloc(4096 * sizeof(char)); char *cwd = (char *) malloc(4096 * sizeof(char));
if (cwd == NULL) { if (cwd == NULL) {
return NULL; return NULL;
} }
getcwd(cwd, 4096 * sizeof(char)); getcwd(cwd, 4096 * sizeof(char));
return cwd; return cwd;
} }
inline inline void chdir_application(const char *cwd, const char *arg)
void chdir_application(const char *cwd, const char *arg)
{ {
char *pos = strrchr((char *) arg, '/'); char *pos = strrchr((char *) arg, '/');
if (pos == NULL) { if (pos == NULL) {
pos = strrchr((char *) arg, '\\'); pos = strrchr((char *) arg, '\\');
} }
char* dir = (char *) calloc((pos - arg + 1), sizeof(char)); char *dir = (char *) calloc((pos - arg + 1), sizeof(char));
if (!dir) { if (!dir) {
return; return;
} }
@ -53,8 +51,7 @@ namespace Utils
} }
} }
inline inline const char *compile_arg_line(int argc, const char **argv)
const char *compile_arg_line(int argc, const char **argv)
{ {
size_t max = 512; size_t max = 512;
size_t length = 0; size_t length = 0;
@ -79,17 +76,17 @@ namespace Utils
max += 128; max += 128;
} }
#ifdef _WIN32 #ifdef _WIN32
strcat_s(arg, max * sizeof(char), argv[i]); strcat_s(arg, max * sizeof(char), argv[i]);
#else #else
strcat(arg, argv[i]); strcat(arg, argv[i]);
#endif #endif
length += argv_length; length += argv_length;
} }
return arg; return arg;
} }
} } // namespace ApplicationUtils
} } // namespace Utils
#endif #endif

View File

@ -18,8 +18,7 @@
namespace Utils::ArrayUtils namespace Utils::ArrayUtils
{ {
inline inline const char *get_arg(const char *id, const char **argv, size_t size)
const char* get_arg(const char *id, const char **argv, size_t size)
{ {
if (Utils::StringUtils::is_number(id)) { if (Utils::StringUtils::is_number(id)) {
return argv[atoi(id)]; return argv[atoi(id)];
@ -34,8 +33,7 @@ namespace Utils::ArrayUtils
return NULL; return NULL;
} }
inline inline bool has_arg(const char *id, const char **argv, size_t size)
bool has_arg(const char *id, const char **argv, size_t size)
{ {
for (size_t i = 0; i < size; ++i) { for (size_t i = 0; i < size; ++i) {
if (strcmp(id, argv[i]) == 0) { if (strcmp(id, argv[i]) == 0) {
@ -46,8 +44,7 @@ namespace Utils::ArrayUtils
return false; return false;
} }
inline inline double array_sum_double(const double *array, size_t size)
double array_sum_double(const double *array, size_t size)
{ {
double sum = 0.0; double sum = 0.0;
for (size_t i = 0; i < size; ++i) { for (size_t i = 0; i < size; ++i) {
@ -57,8 +54,7 @@ namespace Utils::ArrayUtils
return sum; return sum;
} }
inline inline float array_sum_float(const float *array, size_t size)
float array_sum_float(const float *array, size_t size)
{ {
float sum = 0.0; float sum = 0.0;
for (size_t i = 0; i < size; ++i) { for (size_t i = 0; i < size; ++i) {
@ -68,8 +64,7 @@ namespace Utils::ArrayUtils
return sum; return sum;
} }
inline inline int64_t array_sum_int(const int64_t *array, size_t size)
int64_t array_sum_int(const int64_t *array, size_t size)
{ {
int64_t sum = 0; int64_t sum = 0;
for (size_t i = 0; i < size; ++i) { for (size_t i = 0; i < size; ++i) {
@ -79,8 +74,7 @@ namespace Utils::ArrayUtils
return sum; return sum;
} }
inline inline size_t find_in_array_string(const char *element, const char **array, size_t size)
size_t find_in_array_string(const char *element, const char **array, size_t size)
{ {
for (size_t i = 0; i < size; ++i) { for (size_t i = 0; i < size; ++i) {
if (strcmp(element, array[i]) == 0) { if (strcmp(element, array[i]) == 0) {
@ -91,8 +85,7 @@ namespace Utils::ArrayUtils
return -1; return -1;
} }
inline inline size_t find_in_array_double(double element, const double *array, size_t size)
size_t find_in_array_double(double element, const double *array, size_t size)
{ {
for (size_t i = 0; i < size; ++i) { for (size_t i = 0; i < size; ++i) {
if (array[i] == element) { if (array[i] == element) {
@ -103,8 +96,7 @@ namespace Utils::ArrayUtils
return -1; return -1;
} }
inline inline size_t find_in_array_float(float element, const float *array, size_t size)
size_t find_in_array_float(float element, const float *array, size_t size)
{ {
for (size_t i = 0; i < size; ++i) { for (size_t i = 0; i < size; ++i) {
if (array[i] == element) { if (array[i] == element) {
@ -115,8 +107,7 @@ namespace Utils::ArrayUtils
return -1; return -1;
} }
inline inline size_t find_in_array_int(int64_t element, const int64_t *array, size_t size)
size_t find_in_array_int(int64_t element, const int64_t *array, size_t size)
{ {
for (size_t i = 0; i < size; ++i) { for (size_t i = 0; i < size; ++i) {
if (array[i] == element) { if (array[i] == element) {
@ -127,10 +118,9 @@ namespace Utils::ArrayUtils
return -1; return -1;
} }
inline inline double *merge_arrays_double(const double *array1, size_t size1, const double *array2, size_t size2)
double* merge_arrays_double(const double* array1, size_t size1, const double* array2, size_t size2)
{ {
double* merged = (double*) malloc((size1 + size2) * sizeof(double)); double *merged = (double *) malloc((size1 + size2) * sizeof(double));
if (merged == NULL) { if (merged == NULL) {
return NULL; return NULL;
} }
@ -146,10 +136,9 @@ namespace Utils::ArrayUtils
return merged; return merged;
} }
inline inline float *merge_arrays_float(const float *array1, size_t size1, const float *array2, size_t size2)
float* merge_arrays_float(const float* array1, size_t size1, const float* array2, size_t size2)
{ {
float* merged = (float*) malloc((size1 + size2) * sizeof(float)); float *merged = (float *) malloc((size1 + size2) * sizeof(float));
if (merged == NULL) { if (merged == NULL) {
return NULL; return NULL;
} }
@ -165,10 +154,9 @@ namespace Utils::ArrayUtils
return merged; return merged;
} }
inline inline int64_t *merge_arrays_int(const int64_t *array1, size_t size1, const int64_t *array2, size_t size2)
int64_t* merge_arrays_int(const int64_t* array1, size_t size1, const int64_t* array2, size_t size2)
{ {
int64_t* merged = (int64_t*) malloc((size1 + size2) * sizeof(int64_t)); int64_t *merged = (int64_t *) malloc((size1 + size2) * sizeof(int64_t));
if (merged == NULL) { if (merged == NULL) {
return NULL; return NULL;
} }
@ -184,26 +172,25 @@ namespace Utils::ArrayUtils
return merged; return merged;
} }
inline inline char **merge_arrays_char(const char **array1, size_t size1, const char **array2, size_t size2)
char** merge_arrays_char(const char** array1, size_t size1, const char** array2, size_t size2)
{ {
char** merged = (char**) malloc((size1 + size2) * sizeof(char*)); char **merged = (char **) malloc((size1 + size2) * sizeof(char *));
if (merged == NULL) { if (merged == NULL) {
return NULL; return NULL;
} }
for (size_t i = 0; i < size1; ++i) { for (size_t i = 0; i < size1; ++i) {
merged[i] = (char*) malloc((strlen(array1[i]) + 1) * sizeof(char)); merged[i] = (char *) malloc((strlen(array1[i]) + 1) * sizeof(char));
strcpy(merged[i], array1[i]); strcpy(merged[i], array1[i]);
} }
for (size_t i = 0; i < size2; ++i) { for (size_t i = 0; i < size2; ++i) {
merged[i] = (char*) malloc((strlen(array2[i]) + 1) * sizeof(char)); merged[i] = (char *) malloc((strlen(array2[i]) + 1) * sizeof(char));
strcpy(merged[i], array2[i]); strcpy(merged[i], array2[i]);
} }
return merged; return merged;
} }
} } // namespace Utils::ArrayUtils
#endif #endif

View File

@ -21,10 +21,9 @@ namespace Utils::ColorUtils
unsigned char b = 0; unsigned char b = 0;
} RGB; } RGB;
inline inline RGB *int_to_rgb(int rgb)
RGB* int_to_rgb(int rgb)
{ {
RGB* result = (RGB*) malloc(1 * sizeof(RGB)); RGB *result = (RGB *) malloc(1 * sizeof(RGB));
result->r = rgb & 255; result->r = rgb & 255;
result->g = (rgb >> 8) & 255; result->g = (rgb >> 8) & 255;
@ -33,25 +32,23 @@ namespace Utils::ColorUtils
return result; return result;
} }
inline inline int rgb_to_int(const RGB *rgb)
int rgb_to_int(const RGB* rgb)
{ {
int i = (255 & rgb->r) << 16; int i = (255 & rgb->r) << 16;
i += (255 & rgb->g) << 8; i += (255 & rgb->g) << 8;
i += (255 & rgb->b); i += (255 & rgb->b);
return i; return i;
} }
inline inline int rgb_to_int(char r, char g, char b)
int rgb_to_int(char r, char g, char b)
{ {
int i = (255 & r) << 16; int i = (255 & r) << 16;
i += (255 & g) << 8; i += (255 & g) << 8;
i += (255 & b); i += (255 & b);
return i; return i;
} }
} } // namespace Utils::ColorUtils
#endif #endif

View File

@ -15,8 +15,8 @@
#include <string.h> #include <string.h>
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h>
#include <wchar.h> #include <wchar.h>
#include <windows.h>
#else #else
#include <sys/stat.h> #include <sys/stat.h>
#endif #endif
@ -25,65 +25,62 @@
namespace Utils::FileUtils namespace Utils::FileUtils
{ {
inline inline bool file_exists(const char *filename)
bool file_exists (const char *filename)
{ {
#ifdef _WIN32 #ifdef _WIN32
return access(filename, 0) == 0; return access(filename, 0) == 0;
#else #else
struct stat buffer; struct stat buffer;
return stat(filename, &buffer) == 0; return stat(filename, &buffer) == 0;
#endif #endif
} }
inline inline time_t last_modification(const char *filename)
time_t last_modification (const char *filename)
{ {
#ifdef _WIN32 #ifdef _WIN32
FILETIME modtime; FILETIME modtime;
HANDLE h; HANDLE h;
size_t nameLength = strlen(filename); size_t nameLength = strlen(filename);
wchar_t *wtext = (wchar_t *) calloc(nameLength, sizeof(char)); wchar_t *wtext = (wchar_t *) calloc(nameLength, sizeof(char));
mbstowcs_s(NULL, wtext, nameLength, filename, nameLength); mbstowcs_s(NULL, wtext, nameLength, filename, nameLength);
LPWSTR pFilename = wtext; LPWSTR pFilename = wtext;
if (!pFilename) {
free(wtext);
return 0;
}
h = CreateFileW(pFilename, GENERIC_READ | FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING, 0, NULL);
if (!pFilename) {
free(wtext); free(wtext);
free(pFilename);
if (h == INVALID_HANDLE_VALUE) { return 0;
return (time_t) 0; }
}
if (GetFileTime(h, NULL, NULL, &modtime) == 0) { h = CreateFileW(pFilename, GENERIC_READ | FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING, 0, NULL);
return (time_t) 0;
}
unsigned long long seconds = ((unsigned long long) (modtime.dwHighDateTime)) << 32; free(wtext);
seconds |= modtime.dwLowDateTime; free(pFilename);
return (seconds - 116444736000000000) / 10000000; if (h == INVALID_HANDLE_VALUE) {
#else return (time_t) 0;
struct stat buffer; }
stat(filename, &buffer);
return (time_t) buffer.st_mtim.tv_sec; if (GetFileTime(h, NULL, NULL, &modtime) == 0) {
#endif return (time_t) 0;
}
unsigned long long seconds = ((unsigned long long) (modtime.dwHighDateTime)) << 32;
seconds |= modtime.dwLowDateTime;
return (seconds - 116444736000000000) / 10000000;
#else
struct stat buffer;
stat(filename, &buffer);
return (time_t) buffer.st_mtim.tv_sec;
#endif
return (time_t) 0; return (time_t) 0;
} }
inline inline const char *file_extension(const char *filename)
const char* file_extension (const char *filename)
{ {
char *dot = strrchr((char *) filename, '.'); char *dot = strrchr((char *) filename, '.');
@ -99,7 +96,7 @@ namespace Utils::FileUtils
int size = 0; // doesn't include null termination (same as strlen) int size = 0; // doesn't include null termination (same as strlen)
} file_body; } file_body;
file_body read_file (const char *filename) file_body read_file(const char *filename)
{ {
file_body file = {0}; file_body file = {0};
@ -126,6 +123,6 @@ namespace Utils::FileUtils
return file; return file;
} }
} } // namespace Utils::FileUtils
#endif #endif

View File

@ -15,25 +15,37 @@
/* /*
MMX MMX
Introduce eight 64 bit registers (MM0-MM7) and instructions to work with eight signed/unsigned bytes, four signed/unsigned words, two signed/unsigned dwords. Introduce eight 64 bit registers (MM0-MM7) and instructions to work with eight signed/unsigned bytes, four
signed/unsigned words, two signed/unsigned dwords.
3DNow! 3DNow!
Add support for single precision floating point operand to MMX. Few operation supported, for example addition, subtraction, multiplication. Add support for single precision floating point operand to MMX. Few operation supported, for example addition,
subtraction, multiplication.
SSE SSE
Introduce eight/sixteen 128 bit registers (XMM0-XMM7/15) and instruction to work with four single precision floating point operands. Add integer operations on MMX registers too. (The MMX-integer part of SSE is sometimes called MMXEXT, and was implemented on a few non-Intel CPUs without xmm registers and the floating point part of SSE.) Introduce eight/sixteen 128 bit registers (XMM0-XMM7/15) and instruction to work with four single precision floating
point operands. Add integer operations on MMX registers too. (The MMX-integer part of SSE is sometimes called MMXEXT,
and was implemented on a few non-Intel CPUs without xmm registers and the floating point part of SSE.)
SSE2 SSE2
Introduces instruction to work with 2 double precision floating point operands, and with packed byte/word/dword/qword integers in 128-bit xmm registers. Introduces instruction to work with 2 double precision floating point operands, and with packed byte/word/dword/qword
integers in 128-bit xmm registers.
SSE3 SSE3
Add a few varied instructions (mostly floating point), including a special kind of unaligned load (lddqu) that was better on Pentium 4, synchronization instruction, horizontal add/sub. Add a few varied instructions (mostly floating point), including a special kind of unaligned load (lddqu) that was
better on Pentium 4, synchronization instruction, horizontal add/sub.
SSSE3 SSSE3
Again a varied set of instructions, mostly integer. The first shuffle that takes its control operand from a register instead of hard-coded (pshufb). More horizontal processing, shuffle, packing/unpacking, mul+add on bytes, and some specialized integer add/mul stuff. Again a varied set of instructions, mostly integer. The first shuffle that takes its control operand from a register
instead of hard-coded (pshufb). More horizontal processing, shuffle, packing/unpacking, mul+add on bytes, and some
specialized integer add/mul stuff.
SSE4 (SSE4.1, SSE4.2) SSE4 (SSE4.1, SSE4.2)
Add a lot of instructions: Filling in a lot of the gaps by providing min and max and other operations for all integer data types (especially 32-bit integer had been lacking), where previously integer min was only available for unsigned bytes and signed 16-bit. Also scaling, FP rounding, blending, linear algebra operation, text processing, comparisons. Also a non temporal load for reading video memory, or copying it back to main memory. (Previously only NT stores were available.) Add a lot of instructions: Filling in a lot of the gaps by providing min and max and other operations for all integer
data types (especially 32-bit integer had been lacking), where previously integer min was only available for unsigned
bytes and signed 16-bit. Also scaling, FP rounding, blending, linear algebra operation, text processing, comparisons.
Also a non temporal load for reading video memory, or copying it back to main memory. (Previously only NT stores were
available.)
AESNI AESNI
Add support for accelerating AES symmetric encryption/decryption. Add support for accelerating AES symmetric encryption/decryption.
@ -48,7 +60,9 @@ AVX2
Add support for integer data types. Add support for integer data types.
AVX512F AVX512F
Add eight/thirty-two 512 bit registers (ZMM0-ZMM7/31) and eight 64-bit mask register (k0-k7). Promote most previous instruction to 512 bit wide. Optional parts of AVX512 add instruction for exponentials & reciprocals (AVX512ER), scatter/gather prefetching (AVX512PF), scatter conflict detection (AVX512CD), compress, expand. Add eight/thirty-two 512 bit registers (ZMM0-ZMM7/31) and eight 64-bit mask register (k0-k7). Promote most previous
instruction to 512 bit wide. Optional parts of AVX512 add instruction for exponentials & reciprocals (AVX512ER),
scatter/gather prefetching (AVX512PF), scatter conflict detection (AVX512CD), compress, expand.
IMCI (Intel Xeon Phi) IMCI (Intel Xeon Phi)
Early development of AVX512 for the first-gen Intel Xeon Phi (Knight's Corner) coprocessor. Early development of AVX512 for the first-gen Intel Xeon Phi (Knight's Corner) coprocessor.

View File

@ -16,14 +16,13 @@
namespace Utils::Rng::StringUtils namespace Utils::Rng::StringUtils
{ {
inline inline char *generate_string(size_t min = 10, size_t max = 10,
char* generate_string( const char *charset = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
size_t min = 10, size_t max = 10, int charsetLength = 62)
const char *charset = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", int charsetLength = 62 {
) {
srand(time(0)); srand(time(0));
size_t length = (rand() % (max - min + 1)) + min; size_t length = (rand() % (max - min + 1)) + min;
char *randomString = (char *) malloc(length + 1); char *randomString = (char *) malloc(length + 1);
for (size_t i = 0; i < length; ++i) { for (size_t i = 0; i < length; ++i) {
@ -34,6 +33,6 @@ namespace Utils::Rng::StringUtils
return randomString; return randomString;
} }
} } // namespace Utils::Rng::StringUtils
#endif #endif

View File

@ -10,12 +10,12 @@
#ifndef UTILS_STRING_UTILS_H #ifndef UTILS_STRING_UTILS_H
#define UTILS_STRING_UTILS_H #define UTILS_STRING_UTILS_H
#include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <ctype.h>
#include "MathUtils.h"
#include "ArraySort.h" #include "ArraySort.h"
#include "MathUtils.h"
namespace Utils::StringUtils namespace Utils::StringUtils
{ {
@ -62,8 +62,7 @@ namespace Utils::StringUtils
return result; return result;
} }
inline inline bool is_number(const char *s)
bool is_number(const char *s)
{ {
while (*s != '\0') { while (*s != '\0') {
if (!isdigit(*s)) { if (!isdigit(*s)) {
@ -76,8 +75,7 @@ namespace Utils::StringUtils
return true; return true;
} }
inline inline size_t str_count(const char *str, const char *substr)
size_t str_count(const char *str, const char *substr)
{ {
size_t l1 = strlen(str); size_t l1 = strlen(str);
size_t l2 = strlen(substr); size_t l2 = strlen(substr);
@ -94,13 +92,12 @@ namespace Utils::StringUtils
return count; return count;
} }
inline inline char *strsep(const char **sp, const char *sep)
char *strsep(const char **sp, const char *sep)
{ {
char *p, *s; char *p, *s;
if (sp == NULL || *sp == NULL || **sp == '\0') { if (sp == NULL || *sp == NULL || **sp == '\0') {
return(NULL); return (NULL);
} }
s = (char *) *sp; s = (char *) *sp;
@ -116,8 +113,7 @@ namespace Utils::StringUtils
} }
// @todo Implement delim as const char* (also allow \0 length) // @todo Implement delim as const char* (also allow \0 length)
inline inline int str_split(char **list, const char *str, const char delim)
int str_split(char **list, const char *str, const char delim)
{ {
size_t splits = str_count(str, (char *) &delim) + 1; size_t splits = str_count(str, (char *) &delim) + 1;
list = (char **) malloc(splits * sizeof(char *)); list = (char **) malloc(splits * sizeof(char *));
@ -136,8 +132,7 @@ namespace Utils::StringUtils
} }
// @todo Implement delim as const char* (also allow \0 length) // @todo Implement delim as const char* (also allow \0 length)
inline inline char *str_combine(const char **str, size_t size, const char delim)
char* str_combine(const char **str, size_t size, const char delim)
{ {
if (size < 1) { if (size < 1) {
return NULL; return NULL;
@ -199,8 +194,8 @@ namespace Utils::StringUtils
for (i = 1; i <= fromSize; ++i) { for (i = 1; i <= fromSize; ++i) {
for (j = 1; j <= toSize; ++j) { for (j = 1; j <= toSize; ++j) {
dm[i * fromSize + j] = strcmp(from[i - 1], to[j - 1]) == 0 dm[i * fromSize + j] = strcmp(from[i - 1], to[j - 1]) == 0
? dm[(i - 1) * fromSize + (j - 1)] + 1 ? dm[(i - 1) * fromSize + (j - 1)] + 1
: oms_max(dm[(i - 1) * fromSize + j], dm[i * fromSize + (j - 1)]); : oms_max(dm[(i - 1) * fromSize + j], dm[i * fromSize + (j - 1)]);
} }
} }
@ -218,11 +213,11 @@ namespace Utils::StringUtils
continue; continue;
} }
#ifdef _WIN32 #ifdef _WIN32
strcpy_s(diffValues[diffIndex], (strlen(to[j - 1]) + 1) * sizeof(char), to[j - 1]); strcpy_s(diffValues[diffIndex], (strlen(to[j - 1]) + 1) * sizeof(char), to[j - 1]);
#else #else
strcpy(diffValues[diffIndex], to[j - 1]); strcpy(diffValues[diffIndex], to[j - 1]);
#endif #endif
diffMasks[diffIndex] = 1; diffMasks[diffIndex] = 1;
@ -240,11 +235,11 @@ namespace Utils::StringUtils
continue; continue;
} }
#ifdef _WIN32 #ifdef _WIN32
strcpy_s(diffValues[diffIndex], (strlen(from[i - 1]) + 1) * sizeof(char), from[i - 1]); strcpy_s(diffValues[diffIndex], (strlen(from[i - 1]) + 1) * sizeof(char), from[i - 1]);
#else #else
strcpy(diffValues[diffIndex], from[i - 1]); strcpy(diffValues[diffIndex], from[i - 1]);
#endif #endif
diffMasks[diffIndex] = -1; diffMasks[diffIndex] = -1;
@ -261,11 +256,11 @@ namespace Utils::StringUtils
continue; continue;
} }
#ifdef _WIN32 #ifdef _WIN32
strcpy_s(diffValues[diffIndex], (strlen(from[i - 1]) + 1) * sizeof(char), from[i - 1]); strcpy_s(diffValues[diffIndex], (strlen(from[i - 1]) + 1) * sizeof(char), from[i - 1]);
#else #else
strcpy(diffValues[diffIndex], from[i - 1]); strcpy(diffValues[diffIndex], from[i - 1]);
#endif #endif
/* Handled with calloc /* Handled with calloc
diffMasks[diffIndex] = 0; diffMasks[diffIndex] = 0;
@ -303,7 +298,8 @@ namespace Utils::StringUtils
return text_diff{diffValues, diffMasks, diffIndex}; return text_diff{diffValues, diffMasks, diffIndex};
} }
char *strtok(char *str, const char *delim, char **saveptr) { char *strtok(char *str, const char *delim, char **saveptr)
{
if (str == NULL) { if (str == NULL) {
str = *saveptr; str = *saveptr;
} }
@ -313,17 +309,17 @@ namespace Utils::StringUtils
} }
char *token_start = str; char *token_start = str;
char *token_end = strpbrk(token_start, delim); char *token_end = strpbrk(token_start, delim);
if (token_end == NULL) { if (token_end == NULL) {
*saveptr = NULL; *saveptr = NULL;
} else { } else {
*token_end = '\0'; *token_end = '\0';
*saveptr = token_end + 1; *saveptr = token_end + 1;
} }
return token_start; return token_start;
} }
} } // namespace Utils::StringUtils
#endif #endif

View File

@ -10,57 +10,97 @@
#ifndef UTILS_TEST_UTILS_H #ifndef UTILS_TEST_UTILS_H
#define UTILS_TEST_UTILS_H #define UTILS_TEST_UTILS_H
#include <stdio.h>
#include "MathUtils.h" #include "MathUtils.h"
#include <stdio.h>
#define ASSERT_EQUALS(a, b, t1, t2) ({\ #define ASSERT_EQUALS(a, b, t1, t2) \
if ((a) == (b)) { \ ({ \
printf("."); \ if ((a) == (b)) { \
} else { \ printf("."); \
printf("[F]"); \ } else { \
printf("\033[31m[F]\033[0m"); \
printf("\n\n%s - %i: ", __FILE__, __LINE__); \ printf("\n\n%s - %i: ", __FILE__, __LINE__); \
printf((t1), (a)); printf(" != "); printf((t2), (b)); printf("\n"); \ printf((t1), (a)); \
return 0; } \ printf(" != "); \
printf((t2), (b)); \
printf("\n"); \
return 0; \
} \
}) })
#define ASSERT_EQUALS_WITH_DELTA(a, b, delta, t1, t2) ({\ #define ASSERT_NOT_EQUALS(a, b, t1, t2) \
if (oms_abs((a) - (b)) <= (delta)) { \ ({ \
printf("."); \ if ((a) != (b)) { \
} else { \ printf("."); \
printf("[F]"); \ } else { \
printf("\033[31m[F]\033[0m"); \
printf("\n\n%s - %i: ", __FILE__, __LINE__); \ printf("\n\n%s - %i: ", __FILE__, __LINE__); \
printf((t1), (a)); printf(" != "); printf((t2), (b)); printf("\n"); \ printf((t1), (a)); \
return 0; } \ printf(" == "); \
printf((t2), (b)); \
printf("\n"); \
return 0; \
} \
}) })
#define ASSERT_CONTAINS(a, b) ({\ #define ASSERT_EQUALS_WITH_DELTA(a, b, delta, t1, t2) \
if (strstr((a), (b)) != NULL) { \ ({ \
printf("."); \ if (oms_abs((a) - (b)) <= (delta)) { \
} else { \ printf("."); \
printf("[F]"); \ } else { \
printf("\033[31m[F]\033[0m"); \
printf("\n\n%s - %i: ", __FILE__, __LINE__); \ printf("\n\n%s - %i: ", __FILE__, __LINE__); \
printf("%s", (a)); printf(" !contains "); printf("%s", (b)); printf("\n"); \ printf((t1), (a)); \
return 0; } \ printf(" != "); \
printf((t2), (b)); \
printf("\n"); \
return 0; \
} \
}) })
#define ASSERT_TRUE(a) ({\ #define ASSERT_CONTAINS(a, b) \
if ((a) == true) { \ ({ \
printf("."); \ if (strstr((a), (b)) != NULL) { \
} else { \ printf("."); \
printf("[F]"); \ } else { \
printf("\033[31m[F]\033[0m"); \
printf("\n\n%s - %i: ", __FILE__, __LINE__); \ printf("\n\n%s - %i: ", __FILE__, __LINE__); \
printf("%d", (a)); printf(" != "); printf("1"); printf("\n"); \ printf("%s", (a)); \
return 0; } \ printf(" !contains "); \
printf("%s", (b)); \
printf("\n"); \
return 0; \
} \
}) })
#define ASSERT_FALSE(a) ({\ #define ASSERT_TRUE(a) \
if ((a) == false) { \ ({ \
printf("."); \ if ((a) == true) { \
} else { \ printf("."); \
printf("[F]"); \ } else { \
printf("\033[31m[F]\033[0m"); \
printf("\n\n%s - %i: ", __FILE__, __LINE__); \ printf("\n\n%s - %i: ", __FILE__, __LINE__); \
printf("%d", (a)); printf(" != "); printf("1"); printf("\n"); \ printf("%d", (a)); \
return 0; } \ printf(" != "); \
printf("1"); \
printf("\n"); \
return 0; \
} \
})
#define ASSERT_FALSE(a) \
({ \
if ((a) == false) { \
printf("."); \
} else { \
printf("\033[31m[F]\033[0m"); \
printf("\n\n%s - %i: ", __FILE__, __LINE__); \
printf("%d", (a)); \
printf(" != "); \
printf("1"); \
printf("\n"); \
return 0; \
} \
}) })
#endif #endif

View File

@ -9,10 +9,10 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include "../../Utils/TestUtils.h"
#include "../../Image/ImageUtils.h" #include "../../Image/ImageUtils.h"
#include "../../Utils/TestUtils.h"
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
printf("ImageUtils:\n\n"); printf("ImageUtils:\n\n");

View File

@ -0,0 +1,32 @@
/**
* Jingga
*
* @package Test
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "../../Stdlib/Intrinsics.h"
#include "../../Utils/TestUtils.h"
int main(int argc, char **argv)
{
printf("Intrinsics:\n\n");
ASSERT_EQUALS_WITH_DELTA(Stdlib::Intrinsics::sqrt(1.234f), sqrt(1.234f), 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA((int) Stdlib::Intrinsics::round_to_int(1.234f), (int) roundf(1.234f), 0.01, "%d", "%d");
// ASSERT_EQUALS_WITH_DELTA(Stdlib::Intrinsics::floor(1.234f), 1.0f, 0.01, "%f", "%f");
// ASSERT_EQUALS_WITH_DELTA(Stdlib::Intrinsics::round(1.234f), roundf(1.234f), 0.01, "%f", "%f");
ASSERT_NOT_EQUALS(Stdlib::Intrinsics::hash(123456), Stdlib::Intrinsics::hash(654321), "%d", "%d");
printf("\n\n");
return 0;
}

View File

@ -0,0 +1,575 @@
/**
* Jingga
*
* @package Test
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
#include <stdio.h>
#include <stdlib.h>
#include "../../../Stdlib/SIMD/SIMD_F32.h"
#include "../../../Stdlib/SIMD/SIMD_Helper.h"
#include "../../../Utils/TestUtils.h"
float *a_array_4 = (float *) aligned_alloc(32, 4 * sizeof(float));
float *b_array_4 = (float *) aligned_alloc(32, 4 * sizeof(float));
float *expected_array_4 = (float *) aligned_alloc(32, 4 * sizeof(float));
float *result_array_4 = (float *) aligned_alloc(32, 4 * sizeof(float));
float *a_array_8 = (float *) aligned_alloc(32, 8 * sizeof(float));
float *b_array_8 = (float *) aligned_alloc(32, 8 * sizeof(float));
float *expected_array_8 = (float *) aligned_alloc(32, 8 * sizeof(float));
float *result_array_8 = (float *) aligned_alloc(32, 8 * sizeof(float));
float *a_array_16 = (float *) aligned_alloc(32, 16 * sizeof(float));
float *b_array_16 = (float *) aligned_alloc(32, 16 * sizeof(float));
float *expected_array_16 = (float *) aligned_alloc(32, 16 * sizeof(float));
float *result_array_16 = (float *) aligned_alloc(32, 16 * sizeof(float));
int test_operator_plus();
int test_operator_minus();
int test_operator_mul();
int main(int argc, char **argv)
{
printf("SIMD_F32:\n");
test_operator_plus();
test_operator_minus();
test_operator_mul();
printf("\n\n");
return 0;
}
int test_operator_plus()
{
printf("\noperator+:\n");
printf("[4]: ");
if (!Stdlib::SIMD::is_avx_supported()) {
printf("[\033[33mNot supported\033[0m]");
return 0;
}
a_array_4[0] = 0.0f;
a_array_4[1] = 1.0f;
a_array_4[2] = 2.0f;
a_array_4[3] = 3.0f;
b_array_4[0] = 0.0f;
b_array_4[1] = 1.0f;
b_array_4[2] = 2.0f;
b_array_4[3] = 3.0f;
expected_array_4[0] = 0.0f;
expected_array_4[1] = 2.0f;
expected_array_4[2] = 4.0f;
expected_array_4[3] = 6.0f;
Stdlib::SIMD::f32_4_simd expected_simd_4 = Stdlib::SIMD::load_f32_4_simd(expected_array_4);
Stdlib::SIMD::f32_4_simd a_simd_4 = Stdlib::SIMD::load_f32_4_simd(a_array_4);
Stdlib::SIMD::f32_4_simd b_simd_4 = Stdlib::SIMD::load_f32_4_simd(b_array_4);
Stdlib::SIMD::f32_4_simd result_simd_4 = a_simd_4 + b_simd_4;
Stdlib::SIMD::unload_f32_4_simd(result_simd_4, result_array_4);
ASSERT_EQUALS_WITH_DELTA(result_array_4[0], expected_array_4[0], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_4[1], expected_array_4[1], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_4[2], expected_array_4[2], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_4[3], expected_array_4[3], 0.01, "%f", "%f");
ASSERT_TRUE(Stdlib::SIMD::all_true(result_simd_4 == expected_simd_4));
printf("\n[8]: ");
if (!Stdlib::SIMD::is_avx256_supported()) {
printf("[\033[33mNot supported\033[0m]");
return 0;
}
a_array_8[0] = 0.0f;
a_array_8[1] = 1.0f;
a_array_8[2] = 2.0f;
a_array_8[3] = 3.0f;
a_array_8[4] = 0.0f;
a_array_8[5] = 1.0f;
a_array_8[6] = 2.0f;
a_array_8[7] = 3.0f;
b_array_8[0] = 0.0f;
b_array_8[1] = 1.0f;
b_array_8[2] = 2.0f;
b_array_8[3] = 3.0f;
b_array_8[4] = 0.0f;
b_array_8[5] = 1.0f;
b_array_8[6] = 2.0f;
b_array_8[7] = 3.0f;
expected_array_8[0] = 0.0f;
expected_array_8[1] = 2.0f;
expected_array_8[2] = 4.0f;
expected_array_8[3] = 6.0f;
expected_array_8[4] = 0.0f;
expected_array_8[5] = 2.0f;
expected_array_8[6] = 4.0f;
expected_array_8[7] = 6.0f;
Stdlib::SIMD::f32_8_simd expected_simd_8 = Stdlib::SIMD::load_f32_8_simd(expected_array_8);
Stdlib::SIMD::f32_8_simd a_simd_8 = Stdlib::SIMD::load_f32_8_simd(a_array_8);
Stdlib::SIMD::f32_8_simd b_simd_8 = Stdlib::SIMD::load_f32_8_simd(b_array_8);
Stdlib::SIMD::f32_8_simd result_simd_8 = a_simd_8 + b_simd_8;
Stdlib::SIMD::unload_f32_8_simd(result_simd_8, result_array_8);
ASSERT_EQUALS_WITH_DELTA(result_array_8[0], expected_array_8[0], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_8[1], expected_array_8[1], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_8[2], expected_array_8[2], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_8[3], expected_array_8[3], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_8[4], expected_array_8[4], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_8[5], expected_array_8[5], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_8[6], expected_array_8[6], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_8[7], expected_array_8[7], 0.01, "%f", "%f");
ASSERT_TRUE(Stdlib::SIMD::all_true(result_simd_8 == expected_simd_8));
printf("\n[16]: ");
if (!Stdlib::SIMD::is_avx512_supported()) {
printf("[\033[33mNot supported\033[0m]");
return 0;
}
a_array_16[0] = 0.0f;
a_array_16[1] = 1.0f;
a_array_16[2] = 2.0f;
a_array_16[3] = 3.0f;
a_array_16[4] = 0.0f;
a_array_16[5] = 1.0f;
a_array_16[6] = 2.0f;
a_array_16[7] = 3.0f;
a_array_16[8] = 0.0f;
a_array_16[9] = 1.0f;
a_array_16[10] = 2.0f;
a_array_16[11] = 3.0f;
a_array_16[12] = 0.0f;
a_array_16[13] = 1.0f;
a_array_16[14] = 2.0f;
a_array_16[15] = 3.0f;
b_array_16[0] = 0.0f;
b_array_16[1] = 1.0f;
b_array_16[2] = 2.0f;
b_array_16[3] = 3.0f;
b_array_16[4] = 0.0f;
b_array_16[5] = 1.0f;
b_array_16[6] = 2.0f;
b_array_16[7] = 3.0f;
b_array_16[8] = 0.0f;
b_array_16[9] = 1.0f;
b_array_16[10] = 2.0f;
b_array_16[11] = 3.0f;
b_array_16[12] = 0.0f;
b_array_16[13] = 1.0f;
b_array_16[14] = 2.0f;
b_array_16[15] = 3.0f;
expected_array_16[0] = 0.0f;
expected_array_16[1] = 2.0f;
expected_array_16[2] = 4.0f;
expected_array_16[3] = 6.0f;
expected_array_16[4] = 0.0f;
expected_array_16[5] = 2.0f;
expected_array_16[6] = 4.0f;
expected_array_16[7] = 6.0f;
expected_array_16[8] = 0.0f;
expected_array_16[9] = 2.0f;
expected_array_16[10] = 4.0f;
expected_array_16[11] = 6.0f;
expected_array_16[12] = 0.0f;
expected_array_16[13] = 2.0f;
expected_array_16[14] = 4.0f;
expected_array_16[15] = 6.0f;
Stdlib::SIMD::f32_16_simd expected_simd_16 = Stdlib::SIMD::load_f32_16_simd(expected_array_16);
Stdlib::SIMD::f32_16_simd a_simd_16 = Stdlib::SIMD::load_f32_16_simd(a_array_16);
Stdlib::SIMD::f32_16_simd b_simd_16 = Stdlib::SIMD::load_f32_16_simd(b_array_16);
Stdlib::SIMD::f32_16_simd result_simd_16 = a_simd_16 + b_simd_16;
Stdlib::SIMD::unload_f32_16_simd(result_simd_16, result_array_16);
ASSERT_EQUALS_WITH_DELTA(result_array_16[0], expected_array_16[0], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[1], expected_array_16[1], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[2], expected_array_16[2], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[3], expected_array_16[3], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[4], expected_array_16[4], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[5], expected_array_16[5], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[6], expected_array_16[6], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[7], expected_array_16[7], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[8], expected_array_16[8], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[9], expected_array_16[9], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[10], expected_array_16[10], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[11], expected_array_16[11], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[12], expected_array_16[12], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[13], expected_array_16[13], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[14], expected_array_16[14], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[15], expected_array_16[15], 0.01, "%f", "%f");
ASSERT_TRUE(Stdlib::SIMD::all_true(result_simd_16 == expected_simd_16));
return 0;
}
int test_operator_minus()
{
printf("\noperator-:\n");
printf("[4]: ");
if (!Stdlib::SIMD::is_avx_supported()) {
printf("[\033[33mNot supported\033[0m]");
return 0;
}
a_array_4[0] = 0.0f;
a_array_4[1] = 1.0f;
a_array_4[2] = 2.0f;
a_array_4[3] = 3.0f;
b_array_4[0] = 1.0f;
b_array_4[1] = 1.0f;
b_array_4[2] = 1.0f;
b_array_4[3] = 1.0f;
expected_array_4[0] = -1.0f;
expected_array_4[1] = 0.0f;
expected_array_4[2] = 1.0f;
expected_array_4[3] = 2.0f;
Stdlib::SIMD::f32_4_simd expected_simd_4 = Stdlib::SIMD::load_f32_4_simd(expected_array_4);
Stdlib::SIMD::f32_4_simd a_simd_4 = Stdlib::SIMD::load_f32_4_simd(a_array_4);
Stdlib::SIMD::f32_4_simd b_simd_4 = Stdlib::SIMD::load_f32_4_simd(b_array_4);
Stdlib::SIMD::f32_4_simd result_simd_4 = a_simd_4 - b_simd_4;
Stdlib::SIMD::unload_f32_4_simd(result_simd_4, result_array_4);
ASSERT_EQUALS_WITH_DELTA(result_array_4[0], expected_array_4[0], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_4[1], expected_array_4[1], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_4[2], expected_array_4[2], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_4[3], expected_array_4[3], 0.01, "%f", "%f");
ASSERT_TRUE(Stdlib::SIMD::all_true(result_simd_4 == expected_simd_4));
printf("\n[8]: ");
if (!Stdlib::SIMD::is_avx256_supported()) {
printf("[\033[33mNot supported\033[0m]");
return 0;
}
a_array_8[0] = 0.0f;
a_array_8[1] = 1.0f;
a_array_8[2] = 2.0f;
a_array_8[3] = 3.0f;
a_array_8[4] = 0.0f;
a_array_8[5] = 1.0f;
a_array_8[6] = 2.0f;
a_array_8[7] = 3.0f;
b_array_8[0] = 1.0f;
b_array_8[1] = 1.0f;
b_array_8[2] = 1.0f;
b_array_8[3] = 1.0f;
b_array_8[4] = 1.0f;
b_array_8[5] = 1.0f;
b_array_8[6] = 1.0f;
b_array_8[7] = 1.0f;
expected_array_8[0] = -1.0f;
expected_array_8[1] = 0.0f;
expected_array_8[2] = 1.0f;
expected_array_8[3] = 2.0f;
expected_array_8[4] = -1.0f;
expected_array_8[5] = 0.0f;
expected_array_8[6] = 1.0f;
expected_array_8[7] = 2.0f;
Stdlib::SIMD::f32_8_simd expected_simd_8 = Stdlib::SIMD::load_f32_8_simd(expected_array_8);
Stdlib::SIMD::f32_8_simd a_simd_8 = Stdlib::SIMD::load_f32_8_simd(a_array_8);
Stdlib::SIMD::f32_8_simd b_simd_8 = Stdlib::SIMD::load_f32_8_simd(b_array_8);
Stdlib::SIMD::f32_8_simd result_simd_8 = a_simd_8 - b_simd_8;
Stdlib::SIMD::unload_f32_8_simd(result_simd_8, result_array_8);
ASSERT_EQUALS_WITH_DELTA(result_array_8[0], expected_array_8[0], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_8[1], expected_array_8[1], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_8[2], expected_array_8[2], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_8[3], expected_array_8[3], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_8[4], expected_array_8[4], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_8[5], expected_array_8[5], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_8[6], expected_array_8[6], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_8[7], expected_array_8[7], 0.01, "%f", "%f");
ASSERT_TRUE(Stdlib::SIMD::all_true(result_simd_8 == expected_simd_8));
printf("\n[16]: ");
if (!Stdlib::SIMD::is_avx512_supported()) {
printf("[\033[33mNot supported\033[0m]");
return 0;
}
a_array_16[0] = 0.0f;
a_array_16[1] = 1.0f;
a_array_16[2] = 2.0f;
a_array_16[3] = 3.0f;
a_array_16[4] = 0.0f;
a_array_16[5] = 1.0f;
a_array_16[6] = 2.0f;
a_array_16[7] = 3.0f;
a_array_16[8] = 0.0f;
a_array_16[9] = 1.0f;
a_array_16[10] = 2.0f;
a_array_16[11] = 3.0f;
a_array_16[12] = 0.0f;
a_array_16[13] = 1.0f;
a_array_16[14] = 2.0f;
a_array_16[15] = 3.0f;
b_array_16[0] = 1.0f;
b_array_16[1] = 1.0f;
b_array_16[2] = 1.0f;
b_array_16[3] = 1.0f;
b_array_16[4] = 1.0f;
b_array_16[5] = 1.0f;
b_array_16[6] = 1.0f;
b_array_16[7] = 1.0f;
b_array_16[8] = 1.0f;
b_array_16[9] = 1.0f;
b_array_16[10] = 1.0f;
b_array_16[11] = 1.0f;
b_array_16[12] = 1.0f;
b_array_16[13] = 1.0f;
b_array_16[14] = 1.0f;
b_array_16[15] = 1.0f;
expected_array_16[0] = -1.0f;
expected_array_16[1] = 0.0f;
expected_array_16[2] = 1.0f;
expected_array_16[3] = 2.0f;
expected_array_16[4] = -1.0f;
expected_array_16[5] = 0.0f;
expected_array_16[6] = 1.0f;
expected_array_16[7] = 2.0f;
expected_array_16[8] = -1.0f;
expected_array_16[9] = 0.0f;
expected_array_16[10] = 1.0f;
expected_array_16[11] = 2.0f;
expected_array_16[12] = -1.0f;
expected_array_16[13] = 0.0f;
expected_array_16[14] = 1.0f;
expected_array_16[15] = 2.0f;
Stdlib::SIMD::f32_16_simd expected_simd_16 = Stdlib::SIMD::load_f32_16_simd(expected_array_16);
Stdlib::SIMD::f32_16_simd a_simd_16 = Stdlib::SIMD::load_f32_16_simd(a_array_16);
Stdlib::SIMD::f32_16_simd b_simd_16 = Stdlib::SIMD::load_f32_16_simd(b_array_16);
Stdlib::SIMD::f32_16_simd result_simd_16 = a_simd_16 - b_simd_16;
Stdlib::SIMD::unload_f32_16_simd(result_simd_16, result_array_16);
ASSERT_EQUALS_WITH_DELTA(result_array_16[0], expected_array_16[0], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[1], expected_array_16[1], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[2], expected_array_16[2], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[3], expected_array_16[3], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[4], expected_array_16[4], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[5], expected_array_16[5], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[6], expected_array_16[6], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[7], expected_array_16[7], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[8], expected_array_16[8], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[9], expected_array_16[9], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[10], expected_array_16[10], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[11], expected_array_16[11], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[12], expected_array_16[12], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[13], expected_array_16[13], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[14], expected_array_16[14], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[15], expected_array_16[15], 0.01, "%f", "%f");
ASSERT_TRUE(Stdlib::SIMD::all_true(result_simd_16 == expected_simd_16));
return 0;
}
int test_operator_mul()
{
printf("\noperator*:\n");
printf("[4]: ");
if (!Stdlib::SIMD::is_avx_supported()) {
printf("[\033[33mNot supported\033[0m]");
return 0;
}
a_array_4[0] = 0.0f;
a_array_4[1] = 1.0f;
a_array_4[2] = 2.0f;
a_array_4[3] = 3.0f;
b_array_4[0] = 0.0f;
b_array_4[1] = 1.0f;
b_array_4[2] = 2.0f;
b_array_4[3] = 3.0f;
expected_array_4[0] = 0.0f;
expected_array_4[1] = 1.0f;
expected_array_4[2] = 4.0f;
expected_array_4[3] = 9.0f;
Stdlib::SIMD::f32_4_simd expected_simd_4 = Stdlib::SIMD::load_f32_4_simd(expected_array_4);
Stdlib::SIMD::f32_4_simd a_simd_4 = Stdlib::SIMD::load_f32_4_simd(a_array_4);
Stdlib::SIMD::f32_4_simd b_simd_4 = Stdlib::SIMD::load_f32_4_simd(b_array_4);
Stdlib::SIMD::f32_4_simd result_simd_4 = a_simd_4 * b_simd_4;
Stdlib::SIMD::unload_f32_4_simd(result_simd_4, result_array_4);
ASSERT_EQUALS_WITH_DELTA(result_array_4[0], expected_array_4[0], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_4[1], expected_array_4[1], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_4[2], expected_array_4[2], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_4[3], expected_array_4[3], 0.01, "%f", "%f");
ASSERT_TRUE(Stdlib::SIMD::all_true(result_simd_4 == expected_simd_4));
printf("\n[8]: ");
if (!Stdlib::SIMD::is_avx256_supported()) {
printf("[\033[33mNot supported\033[0m]");
return 0;
}
a_array_8[0] = 0.0f;
a_array_8[1] = 1.0f;
a_array_8[2] = 2.0f;
a_array_8[3] = 3.0f;
a_array_8[4] = 0.0f;
a_array_8[5] = 1.0f;
a_array_8[6] = 2.0f;
a_array_8[7] = 3.0f;
b_array_8[0] = 0.0f;
b_array_8[1] = 1.0f;
b_array_8[2] = 2.0f;
b_array_8[3] = 3.0f;
b_array_8[4] = 0.0f;
b_array_8[5] = 1.0f;
b_array_8[6] = 2.0f;
b_array_8[7] = 3.0f;
expected_array_8[0] = 0.0f;
expected_array_8[1] = 1.0f;
expected_array_8[2] = 4.0f;
expected_array_8[3] = 9.0f;
expected_array_8[4] = 0.0f;
expected_array_8[5] = 1.0f;
expected_array_8[6] = 4.0f;
expected_array_8[7] = 9.0f;
Stdlib::SIMD::f32_8_simd expected_simd_8 = Stdlib::SIMD::load_f32_8_simd(expected_array_8);
Stdlib::SIMD::f32_8_simd a_simd_8 = Stdlib::SIMD::load_f32_8_simd(a_array_8);
Stdlib::SIMD::f32_8_simd b_simd_8 = Stdlib::SIMD::load_f32_8_simd(b_array_8);
Stdlib::SIMD::f32_8_simd result_simd_8 = a_simd_8 * b_simd_8;
Stdlib::SIMD::unload_f32_8_simd(result_simd_8, result_array_8);
ASSERT_EQUALS_WITH_DELTA(result_array_8[0], expected_array_8[0], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_8[1], expected_array_8[1], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_8[2], expected_array_8[2], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_8[3], expected_array_8[3], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_8[4], expected_array_8[4], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_8[5], expected_array_8[5], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_8[6], expected_array_8[6], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_8[7], expected_array_8[7], 0.01, "%f", "%f");
ASSERT_TRUE(Stdlib::SIMD::all_true(result_simd_8 == expected_simd_8));
printf("\n[16]: ");
if (!Stdlib::SIMD::is_avx512_supported()) {
printf("[\033[33mNot supported\033[0m]");
return 0;
}
a_array_16[0] = 0.0f;
a_array_16[1] = 1.0f;
a_array_16[2] = 2.0f;
a_array_16[3] = 3.0f;
a_array_16[4] = 0.0f;
a_array_16[5] = 1.0f;
a_array_16[6] = 2.0f;
a_array_16[7] = 3.0f;
a_array_16[8] = 0.0f;
a_array_16[9] = 1.0f;
a_array_16[10] = 2.0f;
a_array_16[11] = 3.0f;
a_array_16[12] = 0.0f;
a_array_16[13] = 1.0f;
a_array_16[14] = 2.0f;
a_array_16[15] = 3.0f;
b_array_16[0] = 0.0f;
b_array_16[1] = 1.0f;
b_array_16[2] = 2.0f;
b_array_16[3] = 3.0f;
b_array_16[4] = 0.0f;
b_array_16[5] = 1.0f;
b_array_16[6] = 2.0f;
b_array_16[7] = 3.0f;
b_array_16[8] = 0.0f;
b_array_16[9] = 1.0f;
b_array_16[10] = 2.0f;
b_array_16[11] = 3.0f;
b_array_16[12] = 0.0f;
b_array_16[13] = 1.0f;
b_array_16[14] = 2.0f;
b_array_16[15] = 3.0f;
expected_array_16[0] = 0.0f;
expected_array_16[1] = 1.0f;
expected_array_16[2] = 4.0f;
expected_array_16[3] = 9.0f;
expected_array_16[4] = 0.0f;
expected_array_16[5] = 1.0f;
expected_array_16[6] = 4.0f;
expected_array_16[7] = 9.0f;
expected_array_16[8] = 0.0f;
expected_array_16[9] = 1.0f;
expected_array_16[10] = 4.0f;
expected_array_16[11] = 9.0f;
expected_array_16[12] = 0.0f;
expected_array_16[13] = 1.0f;
expected_array_16[14] = 4.0f;
expected_array_16[15] = 9.0f;
Stdlib::SIMD::f32_16_simd expected_simd_16 = Stdlib::SIMD::load_f32_16_simd(expected_array_16);
Stdlib::SIMD::f32_16_simd a_simd_16 = Stdlib::SIMD::load_f32_16_simd(a_array_16);
Stdlib::SIMD::f32_16_simd b_simd_16 = Stdlib::SIMD::load_f32_16_simd(b_array_16);
Stdlib::SIMD::f32_16_simd result_simd_16 = a_simd_16 * b_simd_16;
Stdlib::SIMD::unload_f32_16_simd(result_simd_16, result_array_16);
ASSERT_EQUALS_WITH_DELTA(result_array_16[0], expected_array_16[0], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[1], expected_array_16[1], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[2], expected_array_16[2], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[3], expected_array_16[3], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[4], expected_array_16[4], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[5], expected_array_16[5], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[6], expected_array_16[6], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[7], expected_array_16[7], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[8], expected_array_16[8], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[9], expected_array_16[9], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[10], expected_array_16[10], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[11], expected_array_16[11], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[12], expected_array_16[12], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[13], expected_array_16[13], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[14], expected_array_16[14], 0.01, "%f", "%f");
ASSERT_EQUALS_WITH_DELTA(result_array_16[15], expected_array_16[15], 0.01, "%f", "%f");
ASSERT_TRUE(Stdlib::SIMD::all_true(result_simd_16 == expected_simd_16));
return 0;
}

View File

@ -0,0 +1,41 @@
/**
* Jingga
*
* @package Test
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
#include <stdio.h>
#include <stdlib.h>
#include "../../../Stdlib/SIMD/SIMD_Helper.h"
#include "../../../Utils/TestUtils.h"
int main(int argc, char **argv)
{
printf("SIMD_Helper:\n");
if (Stdlib::SIMD::is_avx_supported()) {
printf("\nAVX is supported");
} else {
printf("\033[33m\nAVX is NOT supported\033[0m");
}
if (Stdlib::SIMD::is_avx256_supported()) {
printf("\nAVX 256 is supported");
} else {
printf("\033[33m\nAVX 256 is NOT supported\033[0m");
}
if (Stdlib::SIMD::is_avx512_supported()) {
printf("\nAVX 512 is supported");
} else {
printf("\033[33m\nAVX 512 is NOT supported\033[0m");
}
printf("\n\n");
return 0;
}

View File

@ -7,6 +7,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://jingga.app * @link https://jingga.app
*/ */
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include "../../Threads/Thread.h" #include "../../Threads/Thread.h"
@ -15,46 +16,56 @@
static const size_t num_threads = 4; static const size_t num_threads = 4;
static const size_t num_items = 10; static const size_t num_items = 10;
// increase value by 100
void worker(void *arg) void worker(void *arg)
{ {
int *val = (int *) arg; Threads::Job *job = (Threads::Job *) arg;
int old = *val;
*val += 100; int *val = (int *) job->arg;
// printf("tid=%p, old=%d, val=%d\n", (void *) pthread_self(), old, *val); *val += 100;
if (*val % 2) { if (*val % 2) {
sleep(1); sleep(1);
} }
job->state = 1;
} }
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
printf("Threads:\n\n"); printf("Threads:\n\n");
printf("ThreadPool:\n"); printf("ThreadPool:\n");
int i; int i;
Threads::ThreadPool *pool = Threads::pool_create(num_threads); Threads::ThreadPool *pool = Threads::pool_create(num_threads);
int *vals = (int *) calloc(num_items, sizeof(int)); int *vals = (int *) calloc(num_items, sizeof(int));
Threads::Job **works = (Threads::Job **) calloc(num_items, sizeof(Threads::Job));
for (i = 0; i < num_items; ++i) { for (i = 0; i < num_items; ++i) {
vals[i] = i; vals[i] = i;
Threads::pool_add_work(pool, worker, vals + i); works[i] = Threads::pool_add_work(pool, worker, vals + i);
} }
Threads::pool_wait(pool); // @bug wait is not working as expected
sleep(1); // I thought wait works similarly to what the do/while construct below does
// Threads::pool_wait(pool);
bool finished = false;
do {
finished = true;
for (i = 0; i < num_items; ++i) {
finished = finished && (works[i]->state == 1);
}
} while (!finished);
bool test = true; bool test = true;
for (i = 0; i < num_items; ++i) { for (i = 0; i < num_items; ++i) {
// printf("%d\n", vals[i]); ASSERT_EQUALS(vals[i], 100 + i, "%d", "%d");
test = test && 100 + i == vals[i];
} }
ASSERT_EQUALS(test, true, "%d", "%d");
free(vals); free(vals);
free(works);
Threads::pool_destroy(pool); Threads::pool_destroy(pool);
printf("\n\n"); printf("\n\n");

View File

@ -9,10 +9,10 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include "../../Utils/WebUtils.h"
#include "../../Utils/TestUtils.h" #include "../../Utils/TestUtils.h"
#include "../../Utils/WebUtils.h"
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
printf("Utils:\n\n"); printf("Utils:\n\n");
printf("WebUtils:\n"); printf("WebUtils:\n");

View File

@ -9,3 +9,9 @@ g++ $BASEDIR/Image/ImageUtilsTest.cpp -o $BASEDIR/Image/ImageUtilsTest && $BASED
g++ $BASEDIR/Threads/ThreadPoolTest.cpp -o $BASEDIR/Threads/ThreadPoolTest && $BASEDIR/Threads/ThreadPoolTest && rm $BASEDIR/Threads/ThreadPoolTest g++ $BASEDIR/Threads/ThreadPoolTest.cpp -o $BASEDIR/Threads/ThreadPoolTest && $BASEDIR/Threads/ThreadPoolTest && rm $BASEDIR/Threads/ThreadPoolTest
# g++ $BASEDIR/Utils/WebUtilsTest.cpp -o $BASEDIR/Utils/WebUtilsTest -l curl -l xml2 -l libxml2 -I /usr/include/libxml2 -f permissive && $BASEDIR/Utils/WebUtilsTest && rm $BASEDIR/Utils/WebUtilsTest # g++ $BASEDIR/Utils/WebUtilsTest.cpp -o $BASEDIR/Utils/WebUtilsTest -l curl -l xml2 -l libxml2 -I /usr/include/libxml2 -f permissive && $BASEDIR/Utils/WebUtilsTest && rm $BASEDIR/Utils/WebUtilsTest
g++ $BASEDIR/Stdlib/SIMD/SIMD_HelperTest.cpp -o $BASEDIR/Stdlib/SIMD/SIMD_HelperTest && $BASEDIR/Stdlib/SIMD/SIMD_HelperTest && rm $BASEDIR/Stdlib/SIMD/SIMD_HelperTest
g++ -maes -msse4.2 -mavx512f -mpclmul -mavx512dq -march=native $BASEDIR/Stdlib/IntrinsicsTest.cpp -o $BASEDIR/Stdlib/IntrinsicsTest && $BASEDIR/Stdlib/IntrinsicsTest && rm $BASEDIR/Stdlib/IntrinsicsTest
g++ -maes -msse4.2 -mavx512f -mpclmul -mavx512dq -march=native $BASEDIR/Stdlib/SIMD/SIMD_F32Test.cpp -o $BASEDIR/Stdlib/SIMD/SIMD_F32Test && $BASEDIR/Stdlib/SIMD/SIMD_F32Test && rm $BASEDIR/Stdlib/SIMD/SIMD_F32Test