From f034efca545cd215e878f525310910b27db24f36 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Thu, 2 Nov 2023 18:09:13 +0100 Subject: Added writecube AVX --- README.md | 1 - src/cube.c | 30 ++++++++++++++++++++++++++++++ src/cube.h | 4 ++-- test/012_io_AVX_write/01_solved.in | 1 + test/012_io_AVX_write/01_solved.out | 4 ++++ test/012_io_AVX_write/02_scrambled.in | 1 + test/012_io_AVX_write/02_scrambled.out | 4 ++++ test/012_io_AVX_write/io_AVX_tests.c | 28 ++++++++++++++++++++++++++++ 8 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 test/012_io_AVX_write/01_solved.in create mode 100644 test/012_io_AVX_write/01_solved.out create mode 100644 test/012_io_AVX_write/02_scrambled.in create mode 100644 test/012_io_AVX_write/02_scrambled.out create mode 100644 test/012_io_AVX_write/io_AVX_tests.c diff --git a/README.md b/README.md index b2e9424..db0edb6 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,6 @@ $ make test ### Make AVX2 work -* writecube to AVX2-src format (+ tests) * generate moves and transformations with scripts in utils/ * fix base get_ and set_ macros (constant arguments?) * optimize things that use get_ and set_ diff --git a/src/cube.c b/src/cube.c index bb36447..62ac6e3 100644 --- a/src/cube.c +++ b/src/cube.c @@ -276,6 +276,7 @@ static uint8_t readep(char *); static uint8_t readmove(char); static uint8_t readmodifier(char); static cube_t readcube_H48(char *); +static void writecube_AVX(cube_t, char *); static void writecube_H48(cube_t, char *); static int writepiece_SRC(uint8_t, char *); static void writecube_SRC(cube_t, char *); @@ -419,6 +420,32 @@ readcube(format_t format, char *buf) return ret; } +static void +writecube_AVX(cube_t cube, char *buf) +{ + int i, ptr; + uint8_t piece; + + memcpy(buf, "_mm256_set_epi8(\n\t0, 0, 0, 0, ", 30); + ptr = 30; + + for (i = 11; i >= 0; i--) { + piece = get_edge(cube, i); + ptr += writepiece_SRC(piece, buf + ptr); + } + + memcpy(buf+ptr-2, ",\n\t0, 0, 0, 0, 0, 0, 0, 0, ", 27); + ptr += 25; + + for (i = 7; i >= 0; i--) { + piece = get_corner(cube, i); + ptr += writepiece_SRC(piece, buf + ptr); + } + + memcpy(buf+ptr-2, "\n)\0", 3); +} + + static void writecube_H48(cube_t cube, char *buf) { @@ -508,6 +535,9 @@ writecube(format_t format, cube_t cube, char *buf) } switch (format) { + case AVX: + writecube_AVX(cube, buf); + break; case H48: writecube_H48(cube, buf); break; diff --git a/src/cube.h b/src/cube.h index 9ddeefa..a40b8a0 100644 --- a/src/cube.h +++ b/src/cube.h @@ -16,9 +16,9 @@ void writemoves(move_t *, int, char *); trans_t readtrans(char *); void writetrans(trans_t, char *); -typedef enum {H48, SRC} format_t; +typedef enum {AVX, H48, SRC} format_t; cube_t readcube(format_t, char *); /* Supports: H48 */ -void writecube(format_t, cube_t, char *); /* Supports: H48, SRC */ +void writecube(format_t, cube_t, char *); /* Supports: AVX, H48, SRC */ cube_t solvedcube(void); cube_t zerocube(void); diff --git a/test/012_io_AVX_write/01_solved.in b/test/012_io_AVX_write/01_solved.in new file mode 100644 index 0000000..dff224d --- /dev/null +++ b/test/012_io_AVX_write/01_solved.in @@ -0,0 +1 @@ +UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 diff --git a/test/012_io_AVX_write/01_solved.out b/test/012_io_AVX_write/01_solved.out new file mode 100644 index 0000000..9bc7c29 --- /dev/null +++ b/test/012_io_AVX_write/01_solved.out @@ -0,0 +1,4 @@ +_mm256_set_epi8( + 0, 0, 0, 0, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 7, 6, 5, 4, 3, 2, 1, 0 +) diff --git a/test/012_io_AVX_write/02_scrambled.in b/test/012_io_AVX_write/02_scrambled.in new file mode 100644 index 0000000..6a05bbc --- /dev/null +++ b/test/012_io_AVX_write/02_scrambled.in @@ -0,0 +1 @@ +FL0 DB0 UB1 FR0 UR0 DF0 UF0 BR1 UL1 BL1 DL0 DR0 DFR1 UFR1 UBR1 UFL2 DBR2 DFL0 DBL2 UBL0 diff --git a/test/012_io_AVX_write/02_scrambled.out b/test/012_io_AVX_write/02_scrambled.out new file mode 100644 index 0000000..7d406a2 --- /dev/null +++ b/test/012_io_AVX_write/02_scrambled.out @@ -0,0 +1,4 @@ +_mm256_set_epi8( + 0, 0, 0, 0, 7, 6, 26, 21, 27, 0, 3, 4, 8, 17, 2, 9, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 71, 2, 67, 68, 37, 32, 38 +) diff --git a/test/012_io_AVX_write/io_AVX_tests.c b/test/012_io_AVX_write/io_AVX_tests.c new file mode 100644 index 0000000..2815cab --- /dev/null +++ b/test/012_io_AVX_write/io_AVX_tests.c @@ -0,0 +1,28 @@ +#include +#include +#include + +#include "../../src/cube.h" + +#define STRLENMAX 10000 + +int main() { + char *c, str[STRLENMAX]; + cube_t cube; + + for (c = str; (*c = getchar()) != EOF; c++) ; + *c = '\0'; + + cube = readcube(H48, str); + + if (iserror(cube)) { + printf("Error reading cube\n"); + } else if (!issolvable(cube)) { + printf("Cube is not solvable\n"); + } else { + writecube(AVX, cube, str); + printf("%s\n", str); + } + + return 0; +} -- cgit v1.3