Skip to content

Non-SIMD example #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
@@ -17,11 +17,13 @@ jobs:
strategy:
fail-fast: false
matrix:
ghc: ["9.8.1", "9.6.3", "9.4.8", "9.2.8", "9.0.2", "8.10.7"]
os: [ubuntu-latest, macOS-latest, windows-latest]
ghc: ["9.8.2", "9.6.6"]
os: [ubuntu-latest]
exclude:
- os: macos-latest
ghc: "9.8.2"
- os: windows-latest
ghc: "9.4.2"
ghc: "9.8.2"

env:
# Modify this value to "invalidate" the cabal cache.
52 changes: 51 additions & 1 deletion cbits/main.c
Original file line number Diff line number Diff line change
@@ -4,11 +4,16 @@
#include <stdio.h>
#include <string.h>


int hw_simd_json_sm_main(
int argc,
char **argv);

int hw_simd_json_sm_match_slow_main(
int argc,
char **argv);

extern uint32_t hw_json_transition_table[][4];

int main(
int argc,
char **argv) {
@@ -21,6 +26,8 @@ int main(
hw_json_simd_main_spliced(argc - 1, argv + 1);
} else if (strcmp(argv[1], "sm") == 0) {
hw_simd_json_sm_main(argc - 1, argv + 1);
} else if (strcmp(argv[1], "sm-match-slow") == 0) {
hw_simd_json_sm_match_slow_main(argc - 1, argv + 1);
} else {
fprintf(stderr, "Unrecognised command: %s\n", argv[1]);
exit(1);
@@ -164,3 +171,46 @@ int hw_simd_json_sm_main(

return 0;
}

int hw_simd_json_sm_match_slow_main(
int argc,
char **argv) {
if (argc != 2) {
fprintf(stderr, "./a.out <input-file>\n");
exit(1);
}

char *in_filename = argv[1];

FILE *in = fopen(in_filename, "r");

if (!in) {
fprintf(stderr, "Failed to open input file %s\n", in_filename);
exit(1);
}

uint8_t buffer[W8_BUFFER_SIZE];

uint32_t state = 0;

while (1) {
size_t bytes_read = fread(buffer, 1, W8_BUFFER_SIZE, in);

for (size_t i = 0; i < bytes_read; ++i) {
uint8_t b = buffer[i];
state = hw_json_transition_table[b][state];
}

if (bytes_read == 0) {
if (feof(in)) {
break;
}
}
}

fprintf(stderr, "Final state %u\n", state);

fclose(in);

return 0;
}
262 changes: 262 additions & 0 deletions cbits/transition-table.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
#include "intrinsics.h"

#include <stdint.h>

uint32_t hw_json_transition_table[][4] =
{ { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x01, 0x00, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x02, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x03, 0x01, 0x01, 0x03 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
, { 0x00, 0x01, 0x01, 0x00 }
};
2 changes: 1 addition & 1 deletion hw-json-simd.cabal
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ copyright: 2018-2021 John Ky
license: BSD-3-Clause
license-file: LICENSE
build-type: Simple
tested-with: GHC == 9.4.2, GHC == 9.2.4, GHC == 9.0.2, GHC == 8.10.7, GHC == 8.8.4, GHC == 8.6.5
tested-with: GHC == 9.8.2, GHC == 9.6.6
extra-source-files: cbits/debug.h
cbits/simd.h
cbits/intrinsics.h