Show HN: LuaJIT with Native SIMD

frityet1 pts0 comments

Release 1.0.0-simd · TheLuaOSProject/LuaJITMT · GitHub

//releases/show" data-turbo-transient="true" />

Skip to content

Search or jump to...

Search code, repositories, users, issues, pull requests...

-->

Search

Clear

Search syntax tips

Provide feedback

--><br>We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Cancel

Submit feedback

Saved searches

Use saved searches to filter your results more quickly

-->

Name

Query

To see all available qualifiers, see our documentation.

Cancel

Create saved search

Sign in

//releases/show;ref_cta:Sign up;ref_loc:header logged out"}"<br>Sign up

Appearance settings

Resetting focus

You signed in with another tab or window. Reload to refresh your session.<br>You signed out in another tab or window. Reload to refresh your session.<br>You switched accounts on another tab or window. Reload to refresh your session.

Dismiss alert

{{ message }}

Uh oh!

There was an error while loading. Please reload this page.

TheLuaOSProject

LuaJITMT

Public

forked from LuaJIT/LuaJIT

Notifications<br>You must be signed in to change notification settings

Fork

Star

1.0.0-simd

Latest

Latest

Compare

Choose a tag to compare

Sorry, something went wrong.

Filter

Loading

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

No results found

View all tags

Frityet

released this

26 Jul 21:35

1.0.0-simd

f64de27

LuaJIT SIMD 1.0.0

Important<br>This is the single-threaded SIMD release. It does not include or enable LuaJITMT multithreading support!

This adds native JIT support for FFI vector values with SSE for x86-64-v2 and AVX/AVX2 for x86-64-v3 (ARM support will come soon...).

Benchmarks!

Measured on P-cores (taskset -c 8) of an Intel Core i9-13900F, Linux x86-64, GCC 14.2.0. These are the best of 9 runs from the normal release build. The C reference was compiled with exactly -O2 as the optimisation

level:

taskset -c 8 ./src/luajit test/simd/bench.lua 9<br>cc -O2 -std=c11 -Wall -Wextra -Wpedantic test/simd/bench.c -lm -o simd-bench-c<br>taskset -c 8 ./simd-bench-c 9

All time columns are msec. Lua code for the benchmark here and C code here.

Workload<br>Lua scalar<br>Lua XMM<br>Lua AVX2<br>AVX2 speedup<br>C XMM -O2<br>C AVX2 -O2<br>Lua AVX2 vs C

SAXPY (float)<br>7.4<br>1.4<br>1.1<br>6.87x<br>1.1<br>0.7<br>~64%

Dot product (float)<br>4.8<br>1.2<br>0.6<br>8.09x<br>1.2<br>0.6<br>~100%

Horizontal max (int32)<br>3.6<br>3.7<br>1.9<br>1.91x<br>0.6<br>0.4<br>~21%

Clamp (float)<br>28.1<br>1.5<br>1.2<br>23.44x<br>0.8<br>0.7<br>~58%

Delta encode (int32)<br>5.1<br>2.0<br>2.1<br>2.39x<br>1.6<br>1.5<br>~71%

8-tap FIR (float)<br>3.4<br>0.9<br>0.6<br>5.62x<br>0.5<br>0.5<br>~83%

Degree-11 polynomial (double)<br>4.2<br>2.1<br>1.4<br>3.07x<br>2.1<br>1.1<br>~79%

Mandelbrot, 64 iterations (double)<br>6.7<br>7.4<br>4.1<br>1.63x<br>3.7<br>1.9<br>~46%

RGBA channel merge, 1080p<br>13.4<br>13.0<br>12.4<br>1.08x<br>12.5<br>12.4<br>~100%

32-byte block checksum, 16 MiB<br>7.5<br>1.5<br>1.2<br>6.33x<br>1.2<br>1.2<br>~100%

32-byte block SAD, 16 MiB<br>20.8<br>2.8<br>2.5<br>8.20x<br>2.3<br>2.3<br>~92%

4K 16-pixel luma sum<br>4.1<br>2.3<br>1.6<br>2.55x<br>2.2<br>1.6<br>~100%

4K depth tile extrema<br>6.3<br>1.4<br>1.5<br>4.13x<br>1.0<br>1.2<br>~80%

PCM16 peak envelope<br>9.1<br>2.1<br>2.3<br>4.05x<br>2.5<br>2.8<br>~122%

Float PCM noise gate<br>47.1<br>4.5<br>3.2<br>14.87x<br>2.9<br>2.8<br>~88%

PCM16 16-tap decimator<br>13.1<br>2.4<br>1.6<br>7.98x<br>2.3<br>1.5<br>~94%

4K residual codebook<br>151.7<br>7.6<br>6.2<br>24.64x<br>6.4<br>5.9<br>~95%

4K four-rate quantize<br>127.0<br>9.2<br>5.5<br>23.10x<br>6.7<br>4.3<br>~78%

INT8 activation range, 16 MiB<br>13.1<br>1.9<br>2.1<br>6.19x<br>2.2<br>2.5<br>~119%

INT8 32-tap ternary filter<br>28.0<br>2.8<br>2.0<br>14.24x<br>3.6<br>3.8<br>~190%

5x5 Gaussian, 1080p<br>10.4<br>2.3<br>1.9<br>5.37x<br>1.5<br>1.2<br>~63%

3x3 dilation, 4K<br>452.9<br>7.4<br>6.5<br>69.56x<br>7.2<br>7.2<br>~111%

Weighted 4x4 point transform<br>22.6<br>8.7<br>4.4<br>5.09x<br>5.0<br>4.6<br>~105%

3D voxel index checksum<br>9.6<br>11.6<br>8.2<br>1.18x<br>10.1<br>10.3<br>~126%

64-tap audio FIR<br>8.7<br>2.2<br>1.5<br>5.86x<br>1.6<br>1.2<br>~80%

Gravity particles x32<br>58.0<br>19.6<br>10.7<br>5.44x<br>13.3<br>7.1<br>~66%

ChaCha20 block core<br>28.8<br>3.5<br>2.0<br>14.06x<br>3.6<br>1.9<br>~95%

API

Also available in the docs

Alongside regular FFI vector operators, the ffi.simd module provides

operations that ordinary Lua syntax cannot express:

local ffi = require("ffi")<br>local simd = require("ffi.simd")

ffi must be loaded first. Vector types are declared by the program, the module does not install names such as float4 or i32x4 globally. The examples below use these declarations:

ffi.cdef [[<br>typedef float float4 __attribute__((vector_size(16)));<br>typedef double double2 __attribute__((vector_size(16)));<br>typedef int8_t i8x16 __attribute__((vector_size(16)));<br>typedef uint8_t u8x16 __attribute__((vector_size(16)));<br>typedef int16_t i16x8 __attribute__((vector_size(16)));<br>typedef uint16_t u16x8 __attribute__((vector_size(16)));<br>typedef int32_t i32x4 __attribute__((vector_size(16)));<br>typedef uint32_t u32x4 __attribute__((vector_size(16)));<br>typedef int64_t i64x2 __attribute__((vector_size(16)));<br>typedef uint64_t u64x2 __attribute__((vector_size(16)));

typedef float float8 __attribute__((vector_size(32)));<br>typedef int32_t i32x8 __attribute__((vector_size(32)));<br>]]

local float4 = ffi.typeof("float4")<br>local double2 = ffi.typeof("double2")<br>local i8x16 =...

simd typedef __attribute__ vector_size float luajit

Related Articles