File size: 1,186 Bytes
f25167e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{
  "name": "loop_034",
  "op_type": "loop_034",
  "description": "Compare many short null-terminated strings for equality",
  "tags": [
    "simd-loop"
  ],
  "axes": {
    "N": {
      "type": "var",
      "description": "Buffer length (bytes)"
    }
  },
  "inputs": {
    "a": {
      "shape": [
        "N"
      ],
      "dtype": "uint8"
    },
    "b": {
      "shape": [
        "N"
      ],
      "dtype": "uint8"
    }
  },
  "outputs": {
    "checksum": {
      "shape": null,
      "dtype": "uint32",
      "description": "Scalar checksum"
    }
  },
  "reference": "import numpy as np\n\ndef run(a, b):\n    n = len(a); res = 0; cnt = 0; length = 13; off = 0\n    while off < n:\n        k = off\n        while k < n and a[k] == b[k] and int(a[k]) != 0: k += 1\n        av = int(a[k]) if k < n else 0\n        bv = int(b[k]) if k < n else 0\n        r = av - bv\n        cmp = 2 if r > 0 else (3 if r < 0 else 1)\n        res = (res + cnt * cmp) & 0xffffffff\n        off += length; cnt += 1; length = 3 + (length + 11) % 43\n    return np.uint32(res)\n",
  "simd_loop_meta": {
    "output_inplace": false,
    "array_pad": 0,
    "scratch": [],
    "axes_order": []
  }
}