Skip to content

Commit

Permalink
changed hebi_packet size to 128-bits on 64-bit platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
suiginsoft committed Oct 24, 2016
1 parent 9826e46 commit 1e6b485
Show file tree
Hide file tree
Showing 53 changed files with 1,225 additions and 985 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ BENCH_DEPS := $(DEPS) bench/bench.h
CHECK_P := \
pcmp \
pcopy \
pmove \
pnorm \
pzero

Expand Down
6 changes: 3 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ Hebimath has the following design features:
- Can use fixed-size buffers instead of an allocator when initializing
a number primitive, useful for memory allocations on the stack.
- Can specify separate memory allocators for result and temporary buffers.
- Smallest unit size for natural numbers and integers is 16 bytes on 32-bit
platforms and 32-bytes on 64-bit platforms. This larger unit or packet size
aids in shrinking the amount of code bloat for unrolled kernel functions.
- Smallest unit size for natural numbers and integers is 16 bytes. This
larger unit or packet size aids in shrinking the amount of code bloat for
unrolled kernel functions.
- Memory buffers are correctly aligned for use with SIMD instructions.

Hebimath adheres to these principles in its implementation:
Expand Down
2 changes: 1 addition & 1 deletion bench/p/padd.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static volatile uint64_t result_sink;
int
main(int argc, char *argv[])
{
bench_args p = { .iter = 5000, .an = 32768, .bn = 16384 };
bench_args p = { .iter = 5000, .an = 65536, .bn = 32768 };
hebi_packet *a, *b, *r;
int i;

Expand Down
2 changes: 1 addition & 1 deletion bench/p/paddu.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static const uint64_t b = 42571;
int
main(int argc, char *argv[])
{
bench_args p = { .iter = 5000, .an = 32768 };
bench_args p = { .iter = 5000, .an = 65536 };
hebi_packet *a, *r;
int i;

Expand Down
2 changes: 1 addition & 1 deletion bench/p/pclz.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static volatile size_t result_sink;
int
main(int argc, char *argv[])
{
bench_args p = { .iter = 5000, .an = 32768 };
bench_args p = { .iter = 5000, .an = 65536 };
hebi_packet *a;
int i;

Expand Down
2 changes: 1 addition & 1 deletion bench/p/pcopy.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static volatile uint32_t result_sink;
int
main(int argc, char *argv[])
{
bench_args p = { .iter = 5000, .an = 32768, .bn = 32768 };
bench_args p = { .iter = 5000, .an = 65536, .bn = 65536 };
hebi_packet *a, *b;
int i;

Expand Down
2 changes: 1 addition & 1 deletion bench/p/pdivrem.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static volatile size_t result_sink;
int
main(int argc, char *argv[])
{
bench_args p = { .iter = 5000, .an = 512, .bn = 256 };
bench_args p = { .iter = 5000, .an = 1024, .bn = 512 };
hebi_packet *a, *b, *q, *r, *w;
size_t rn;
int i;
Expand Down
2 changes: 1 addition & 1 deletion bench/p/pdivremu.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static const uint64_t b = 42571;
int
main(int argc, char *argv[])
{
bench_args p = { .iter = 5000, .an = 32768 };
bench_args p = { .iter = 5000, .an = 65536 };
hebi_packet *a, *r;
int i;

Expand Down
2 changes: 1 addition & 1 deletion bench/p/pmove.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static volatile uint32_t result_sink;
int
main(int argc, char *argv[])
{
bench_args p = { .iter = 5000, .an = 32768, .bn = 32768 };
bench_args p = { .iter = 5000, .an = 65536, .bn = 65536 };
hebi_packet *a, *b;
int i;

Expand Down
2 changes: 1 addition & 1 deletion bench/p/pmul.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static volatile uint64_t result_sink;
int
main(int argc, char *argv[])
{
bench_args p = { .iter = 5000, .an = 256, .bn = 256 };
bench_args p = { .iter = 5000, .an = 512, .bn = 512 };
hebi_packet *a, *b, *r;
int i;

Expand Down
2 changes: 1 addition & 1 deletion bench/p/pmul_karatsuba.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static volatile uint64_t result_sink;
int
main(int argc, char *argv[])
{
bench_args p = { .iter = 5000, .an = 256, .bn = 256 };
bench_args p = { .iter = 5000, .an = 512, .bn = 512 };
hebi_packet *a, *b, *r, *w;
size_t rn, wn;
int i;
Expand Down
2 changes: 1 addition & 1 deletion bench/p/pmulu.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static const uint64_t b = 42571;
int
main(int argc, char *argv[])
{
bench_args p = { .iter = 5000, .an = 32768 };
bench_args p = { .iter = 5000, .an = 65536 };
hebi_packet *a, *r;
int i;

Expand Down
2 changes: 1 addition & 1 deletion bench/p/pnorm.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static volatile size_t result_sink;
int
main(int argc, char *argv[])
{
bench_args p = { .iter = 5000, .an = 32768 };
bench_args p = { .iter = 5000, .an = 65536 };
hebi_packet *a;
int i;

Expand Down
4 changes: 2 additions & 2 deletions bench/p/pshl.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#include "../bench.h"

static volatile size_t result_sink;
static const size_t b = 433;
static const size_t b = 443;

int
main(int argc, char *argv[])
{
bench_args p = { .iter = 5000, .an = 32768 };
bench_args p = { .iter = 5000, .an = 65536 };
hebi_packet *a, *r;
size_t rn;
int i;
Expand Down
2 changes: 1 addition & 1 deletion bench/p/pshr.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static const size_t b = 433;
int
main(int argc, char *argv[])
{
bench_args p = { .iter = 5000, .an = 32768 };
bench_args p = { .iter = 5000, .an = 65536 };
hebi_packet *a, *r;
size_t rn;
int i;
Expand Down
2 changes: 1 addition & 1 deletion bench/p/psqr.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static volatile uint64_t result_sink;
int
main(int argc, char *argv[])
{
bench_args p = { .iter = 5000, .an = 256 };
bench_args p = { .iter = 5000, .an = 512 };
hebi_packet *a, *r;
int i;

Expand Down
2 changes: 1 addition & 1 deletion bench/p/psqr_karatsuba.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static volatile uint64_t result_sink;
int
main(int argc, char *argv[])
{
bench_args p = { .iter = 5000, .an = 256 };
bench_args p = { .iter = 5000, .an = 512 };
hebi_packet *a, *r, *w;
size_t rn, wn;
int i;
Expand Down
2 changes: 1 addition & 1 deletion bench/p/psub.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static volatile uint64_t result_sink;
int
main(int argc, char *argv[])
{
bench_args p = { .iter = 5000, .an = 32768, .bn = 16384 };
bench_args p = { .iter = 5000, .an = 65536, .bn = 32768 };
hebi_packet *a, *b, *r;
int i;

Expand Down
2 changes: 1 addition & 1 deletion bench/p/psubu.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static const uint64_t b = 42571;
int
main(int argc, char *argv[])
{
bench_args p = { .iter = 5000, .an = 32768 };
bench_args p = { .iter = 5000, .an = 65536 };
hebi_packet *a, *r;
int i;

Expand Down
2 changes: 1 addition & 1 deletion bench/p/pzero.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static volatile uint32_t result_sink;
int
main(int argc, char *argv[])
{
bench_args p = { .iter = 5000, .an = 32768 };
bench_args p = { .iter = 5000, .an = 65536 };
hebi_packet *a;
int i;

Expand Down
46 changes: 30 additions & 16 deletions check/p/pcopy.c
Original file line number Diff line number Diff line change
@@ -1,31 +1,45 @@
#include "../check.h"
#include <string.h>

#define NUM_PACKETS 501
#define NUM_DIGITS (NUM_PACKETS * HEBI_PACKET_LIMBS64)
#define NUM_BYTES (NUM_PACKETS * sizeof(hebi_packet))
#define COUNT 1024
#define GUARD 8
#define TOTAL (COUNT+GUARD*2)

static const uint32_t a[4] = { 0xECECECEC, 0x38383838, 0x92929292, 0xA7A7A7A7 };
static const uint32_t b[4] = { 0x3D3D3D3D, 0x6B6B6B6B, 0x71717171, 0xFEFEFEFE };

int main(int argc, char *argv[])
{
hebi_packet *x, *y;
size_t i, j;
size_t i, j, k;

x = hebi_palloc(HEBI_ALLOC_DEFAULT, NUM_PACKETS);
y = hebi_palloc(HEBI_ALLOC_DEFAULT, NUM_PACKETS);
x = hebi_palloc(HEBI_ALLOC_DEFAULT, TOTAL);
y = hebi_palloc(HEBI_ALLOC_DEFAULT, TOTAL);
assert(x && y);

for (i = 0; i < NUM_PACKETS; ++i) {
for (j = 0; j < HEBI_PACKET_LIMBS64; ++j) {
x[i].hp_limbs64[j] = (uint64_t)i;
y[i].hp_limbs64[j] = (uint64_t)i + 55;
for (k = 1; k <= COUNT; k++) {
for (i = 0; i < k+GUARD*2; i++) {
for (j = 0; j < HEBI_PACKET_LIMBS32; j++) {
x[i].hp_limbs32[j] = a[(k+j)&7];
y[i].hp_limbs32[j] = b[(k+j)&7];
}
}
}

assert(memcmp(x, y, NUM_BYTES) != 0);
hebi_pcopy(y, x, NUM_PACKETS);
assert(memcmp(x, y, NUM_BYTES) == 0);
assert(memcmp(y+GUARD, x+GUARD, k*sizeof(hebi_packet)) != 0);

hebi_pcopy(y+GUARD, x+GUARD, k);

assert(memcmp(y+GUARD, x+GUARD, k*sizeof(hebi_packet)) == 0);

for (i = 0; i < GUARD; i++) {
for (j = 0; j < HEBI_PACKET_LIMBS32; j++) {
assert(y[i].hp_limbs32[j] == b[(k+j)&7]);
assert(y[i+k+GUARD].hp_limbs32[j] == b[(k+j)&7]);
}
}
}

hebi_pfree(HEBI_ALLOC_DEFAULT, x, NUM_PACKETS);
hebi_pfree(HEBI_ALLOC_DEFAULT, y, NUM_PACKETS);
hebi_pfree(HEBI_ALLOC_DEFAULT, x, TOTAL);
hebi_pfree(HEBI_ALLOC_DEFAULT, y, TOTAL);
return 0;
}
45 changes: 45 additions & 0 deletions check/p/pmove.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "../check.h"
#include <string.h>

#define COUNT 1024
#define GUARD 8
#define TOTAL (COUNT+GUARD*2)

static const uint32_t a[4] = { 0xECECECEC, 0x38383838, 0x92929292, 0xA7A7A7A7 };
static const uint32_t b[4] = { 0x3D3D3D3D, 0x6B6B6B6B, 0x71717171, 0xFEFEFEFE };

int main(int argc, char *argv[])
{
hebi_packet *x, *y;
size_t i, j, k;

x = hebi_palloc(HEBI_ALLOC_DEFAULT, TOTAL);
y = hebi_palloc(HEBI_ALLOC_DEFAULT, TOTAL);
assert(x && y);

for (k = 1; k <= COUNT; k++) {
for (i = 0; i < k+GUARD*2; i++) {
for (j = 0; j < HEBI_PACKET_LIMBS32; j++) {
x[i].hp_limbs32[j] = a[(k+j)&7];
y[i].hp_limbs32[j] = b[(k+j)&7];
}
}

assert(memcmp(y+GUARD, x+GUARD, k*sizeof(hebi_packet)) != 0);

hebi_pmove(y+GUARD, x+GUARD, k);

assert(memcmp(y+GUARD, x+GUARD, k*sizeof(hebi_packet)) == 0);

for (i = 0; i < GUARD; i++) {
for (j = 0; j < HEBI_PACKET_LIMBS32; j++) {
assert(y[i].hp_limbs32[j] == b[(k+j)&7]);
assert(y[i+k+GUARD].hp_limbs32[j] == b[(k+j)&7]);
}
}
}

hebi_pfree(HEBI_ALLOC_DEFAULT, x, TOTAL);
hebi_pfree(HEBI_ALLOC_DEFAULT, y, TOTAL);
return 0;
}
30 changes: 19 additions & 11 deletions check/p/pzero.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,35 @@
#include <limits.h>
#include <string.h>

#define NUM_PACKETS 501
#define NUM_DIGITS (NUM_PACKETS * HEBI_PACKET_LIMBS64)
#define NUM_BYTES (NUM_PACKETS * sizeof(hebi_packet))
#define COUNT 1024
#define GUARD 8
#define TOTAL (COUNT+GUARD*2)

int main(int argc, char *argv[])
{
hebi_packet *x;
size_t i, j;
size_t i, j, k;

x = hebi_palloc(HEBI_ALLOC_DEFAULT, NUM_PACKETS);
x = hebi_palloc(HEBI_ALLOC_DEFAULT, TOTAL);
assert(x);

memset(x, UCHAR_MAX, NUM_BYTES);
for (k = 1; k <= COUNT; k++) {
memset(x, UCHAR_MAX, (k+GUARD*2)*sizeof(hebi_packet));

hebi_pzero(x, NUM_PACKETS);
hebi_pzero(x+GUARD, k);

for (i = 0; i < NUM_PACKETS; ++i)
for (j = 0; j < HEBI_PACKET_LIMBS64; ++j)
assert(x[i].hp_limbs64[j] == 0);
for (i = 0; i < k; i++)
for (j = 0; j < HEBI_PACKET_LIMBS32; j++)
assert(x[i+GUARD].hp_limbs32[j] == 0);

hebi_pfree(HEBI_ALLOC_DEFAULT, x, NUM_PACKETS);
for (i = 0; i < GUARD; i++) {
for (j = 0; j < HEBI_PACKET_LIMBS32; j++) {
assert(x[i].hp_limbs32[j] == UINT32_MAX);
assert(x[i+k+GUARD].hp_limbs32[j] == UINT32_MAX);
}
}
}

hebi_pfree(HEBI_ALLOC_DEFAULT, x, TOTAL);
return 0;
}
4 changes: 2 additions & 2 deletions check/z/zgetset.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ int main(int argc, char *argv[])

assert(hebi_zsetstr(a, s1, NULL, 10) > 0);
assert(hebi_zsign(a) > 0);
assert(hebi_zused(a) == 1);
assert(hebi_zused(a) == 2);
assert(hebi_zeven(a));
assert(!hebi_zodd(a));
assert(!hebi_zzero(a));
Expand All @@ -101,7 +101,7 @@ int main(int argc, char *argv[])

assert(hebi_zsetstr(a, s2, NULL, 0) > 0);
assert(hebi_zsign(a) < 0);
assert(hebi_zused(a) == 3);
assert(hebi_zused(a) == 6);
assert(!hebi_zeven(a));
assert(hebi_zodd(a));
assert(!hebi_zzero(a));
Expand Down
1 change: 1 addition & 0 deletions check/z/zshl.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "../check.h"
#include <stdio.h>

int
main(int argc, char *argv[])
Expand Down
Loading

0 comments on commit 1e6b485

Please sign in to comment.