[Tarantool-patches] [PATCH luajit v2] x64: Fix 64 bit shift code generation.

Sergey Kaplun skaplun at tarantool.org
Wed Jun 28 13:57:48 MSK 2023


Hi, Maxim!
Thanks for the fixes!
LGTM, with an ignorable nit below.

Also, I suppose it is better to rebase on the newest master (since
merged C tests may conflict with your changes).

On 13.06.23, Maxim Kokryashkin wrote:
> From: Mike Pall <mike>
> 
> Reported by Philipp Kutin.
> Fix contributed by Peter Cawley.
> 
> (cherry-picked from commit 03a7ebca4f6819658cdaa12ba3af54a17b8035e9)

<snipped>

> 
> Branch: https://github.com/tarantool/luajit/tree/fckxorg/fix-bit-shift-generation
> PR: https://github.com/tarantool/tarantool/pull/8727
> 
>  src/lj_asm_x86.h                              |  2 +-
>  test/tarantool-tests/CMakeLists.txt           |  1 +
>  .../fix-bit-shift-generation.test.lua         | 48 +++++++++++++++++++
>  .../fix-bit-shift-generation/CMakeLists.txt   |  1 +
>  .../libtestbitshift.c                         |  8 ++++
>  5 files changed, 59 insertions(+), 1 deletion(-)
>  create mode 100644 test/tarantool-tests/fix-bit-shift-generation.test.lua
>  create mode 100644 test/tarantool-tests/fix-bit-shift-generation/CMakeLists.txt
>  create mode 100644 test/tarantool-tests/fix-bit-shift-generation/libtestbitshift.c
> 
> diff --git a/src/lj_asm_x86.h b/src/lj_asm_x86.h
> index e6c42c6d..63d332ca 100644
> --- a/src/lj_asm_x86.h
> +++ b/src/lj_asm_x86.h

<snipped>

> diff --git a/test/tarantool-tests/CMakeLists.txt b/test/tarantool-tests/CMakeLists.txt
> index a428d009..d36271f1 100644
> --- a/test/tarantool-tests/CMakeLists.txt
> +++ b/test/tarantool-tests/CMakeLists.txt

<snipped>

> diff --git a/test/tarantool-tests/fix-bit-shift-generation.test.lua b/test/tarantool-tests/fix-bit-shift-generation.test.lua
> new file mode 100644
> index 00000000..e3f30eae
> --- /dev/null
> +++ b/test/tarantool-tests/fix-bit-shift-generation.test.lua

<snipped>

> +local testbitshift = ffi.load('testbitshift')
> +ffi.cdef[[
> +uint64_t
> +testbitshift
> +(const int arg1, const int arg2, const int arg3, const uint64_t arg4)

Side note: See the ignorable comment for the testbitshift lib below.

> +]]
> +
> +local result = {}
> +jit.opt.start('hotloop=1')
> +
> +for i = 1, NTESTS do
> +  -- The rotation is performed beyond the 32-bit size, for
> +  -- truncation to become noticeable. `testbitshift` is used to
> +  -- ensure that the result of rotation goes into the `rcx`,
> +  -- corresponding to the x86_64 ABI. Although it is possible to
> +  -- use a function from the C standard library for that, all of
> +  -- the suitable ones are variadic, and variadics are recorded
> +  -- incorrectly on Apple Silicon.

Side note: still think that we also should fix the M1 behaviour (but in
the different patch set, obviously). And we shouldn't forget to update
this test after, I believe.

> +  result[i] = testbitshift.testbitshift(1, 1, 1, rol(1ULL, i + 32))

<snipped>

> diff --git a/test/tarantool-tests/fix-bit-shift-generation/CMakeLists.txt b/test/tarantool-tests/fix-bit-shift-generation/CMakeLists.txt
> new file mode 100644
> index 00000000..f85f875b
> --- /dev/null
> +++ b/test/tarantool-tests/fix-bit-shift-generation/CMakeLists.txt

<snipped>

> diff --git a/test/tarantool-tests/fix-bit-shift-generation/libtestbitshift.c b/test/tarantool-tests/fix-bit-shift-generation/libtestbitshift.c
> new file mode 100644
> index 00000000..0785ebba
> --- /dev/null
> +++ b/test/tarantool-tests/fix-bit-shift-generation/libtestbitshift.c
> @@ -0,0 +1,8 @@
> +#include <stdint.h>
> +
> +uint64_t
> +testbitshift
> +(const int arg1, const int arg2, const int arg3, const uint64_t arg4)
> +{
> +	return arg4;
> +}

I suggest to use more meaningful naming (like we need to get only 4th
argument of the function). Also, it helps with linewidth.

| uint64_t
| pick4(const int arg1, const int arg2, const int arg3, const uint64_t res)
| {
| 	return res;
| }

Feel free to ignore.
But if you prefer the new naming -- don't forget to change it in the Lua
test too.

Also, it is strange that the compiler doesn't warn about unused
arguments, but OK.

> -- 
> 2.40.1
> 

-- 
Best regards,
Sergey Kaplun


More information about the Tarantool-patches mailing list