Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/lib_ffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ LJLIB_CF(ffi_abi) LJLIB_REC(.)
{
GCstr *s = lj_lib_checkstr(L, 1);
int b = 0;
switch (s->hash) {
switch (lj_str_indep_hash(s)) {
#if LJ_64
case H_(849858eb,ad35fd06): b = 1; break; /* 64bit */
#else
Expand Down
14 changes: 7 additions & 7 deletions src/lj_cparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ static void cp_decl_gccattribute(CPState *cp, CPDecl *decl)
if (cp->tok == CTOK_IDENT) {
GCstr *attrstr = cp->str;
cp_next(cp);
switch (attrstr->hash) {
switch (lj_str_indep_hash(attrstr)) {
case H_(64a9208e,8ce14319): case H_(8e6331b2,95a282af): /* aligned */
cp_decl_align(cp, decl);
break;
Expand Down Expand Up @@ -1128,7 +1128,7 @@ static void cp_decl_msvcattribute(CPState *cp, CPDecl *decl)
while (cp->tok == CTOK_IDENT) {
GCstr *attrstr = cp->str;
cp_next(cp);
switch (attrstr->hash) {
switch (lj_str_indep_hash(attrstr)) {
case H_(bc2395fa,98f267f8): /* align */
cp_decl_align(cp, decl);
break;
Expand Down Expand Up @@ -1718,16 +1718,16 @@ static void cp_pragma(CPState *cp, BCLine pragmaline)
{
cp_next(cp);
if (cp->tok == CTOK_IDENT &&
cp->str->hash == H_(e79b999f,42ca3e85)) { /* pack */
(lj_str_indep_hash(cp->str)) == H_(e79b999f,42ca3e85)) { /* pack */
cp_next(cp);
cp_check(cp, '(');
if (cp->tok == CTOK_IDENT) {
if (cp->str->hash == H_(738e923c,a1b65954)) { /* push */
if (lj_str_indep_hash(cp->str) == H_(738e923c,a1b65954)) { /* push */
if (cp->curpack < CPARSE_MAX_PACKSTACK) {
cp->packstack[cp->curpack+1] = cp->packstack[cp->curpack];
cp->curpack++;
}
} else if (cp->str->hash == H_(6c71cf27,6c71cf27)) { /* pop */
} else if (lj_str_indep_hash(cp->str) == H_(6c71cf27,6c71cf27)) { /* pop */
if (cp->curpack > 0) cp->curpack--;
} else {
cp_errmsg(cp, cp->tok, LJ_ERR_XSYMBOL);
Expand Down Expand Up @@ -1777,12 +1777,12 @@ static void cp_decl_multi(CPState *cp)
cp_line(cp, hashline);
continue;
} else if (tok == CTOK_IDENT &&
cp->str->hash == H_(187aab88,fcb60b42)) { /* line */
lj_str_indep_hash(cp->str) == H_(187aab88,fcb60b42)) { /* line */
if (cp_next(cp) != CTOK_INTEGER) cp_err_token(cp, tok);
cp_line(cp, hashline);
continue;
} else if (tok == CTOK_IDENT &&
cp->str->hash == H_(f5e6b4f8,1d509107)) { /* pragma */
lj_str_indep_hash(cp->str) == H_(f5e6b4f8,1d509107)) { /* pragma */
cp_pragma(cp, hashline);
continue;
} else {
Expand Down
16 changes: 11 additions & 5 deletions src/lj_str.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,6 @@ void lj_str_resize(lua_State *L, MSize newmask)
g->strhash = newhash;
}

#include "x64/src/lj_str_hash_x64.h"

#if defined(LJ_ARCH_STR_HASH)
#define LJ_STR_HASH LJ_ARCH_STR_HASH
#else
static MSize
lj_str_original_hash(const char *str, size_t lenx) {
MSize len = (MSize)lenx;
Expand Down Expand Up @@ -160,6 +155,17 @@ lj_str_original_hash(const char *str, size_t lenx) {

return h;
}

MSize
lj_str_indep_hash(GCstr *str) {
return lj_str_original_hash(strdata(str), str->len);
}

#include "x64/src/lj_str_hash_x64.h"

#if defined(LJ_ARCH_STR_HASH)
#define LJ_STR_HASH LJ_ARCH_STR_HASH
#else
#define LJ_STR_HASH lj_str_original_hash
#endif

Expand Down
2 changes: 2 additions & 0 deletions src/lj_str.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ LJ_FUNC void LJ_FASTCALL lj_str_free(global_State *g, GCstr *s);
#define lj_str_newz(L, s) (lj_str_new(L, s, strlen(s)))
#define lj_str_newlit(L, s) (lj_str_new(L, "" s, sizeof(s)-1))

MSize lj_str_indep_hash(GCstr *str);

#endif
1 change: 1 addition & 0 deletions src/x64/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ CXXFLAGS := -O3 -MD -g -msse4.2 -Wall -I../src -I../../../src
test: $(TEST_PROGRAM)
@echo "some unit test"
$(VALGRIND) ./$(TEST_PROGRAM)
./unit_test.sh

@echo "smoke test"
../../luajit test_str_comp.lua
Expand Down
10 changes: 10 additions & 0 deletions src/x64/test/unit/ffi/test_abi.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
local ffi = require "ffi"

-- TODO: test "gc64" and "win" parameters
assert((ffi.abi("32bit") or ffi.abi("64bit"))
and ffi.abi("le")
and not ffi.abi("be")
and ffi.abi("fpu")
and not ffi.abi("softfp")
and ffi.abi("hardfp")
and not ffi.abi("eabi"))
15 changes: 15 additions & 0 deletions src/x64/test/unit/ffi/test_line_directive.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
local x = [=[
local ffi = require "ffi"
ffi.cdef [[
#line 100
typedef Int xxx
]]
]=]

local function foo()
loadstring(x)()
end

local r, e = pcall(foo)
assert(string.find(e, "declaration specifier expected near 'Int' at line 100") ~= nil)
12 changes: 12 additions & 0 deletions src/x64/test/unit/ffi/test_pragma_pack_pushpop.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
local ffi = require "ffi"

ffi.cdef[[
#pragma pack(push, 1)
typedef struct {
char x;
double y;
} foo;
#pragma pack(pop)
]]

assert(ffi.sizeof("foo") == 9)
22 changes: 22 additions & 0 deletions src/x64/test/unit/ffi/test_var_attribute.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
local ffi = require "ffi"

ffi.cdef[[
typedef struct { int a; char b; } __attribute__((packed)) myty1;
typedef struct { int a; char b; } __attribute__((__packed__)) myty1_a;

typedef struct { int a; char b; } __attribute__((aligned(16))) myty2_a;
typedef struct { int a; char b; } __attribute__((__aligned__(16))) myty2;

typedef int __attribute__ ((vector_size (32))) myty3;
typedef int __attribute__ ((__vector_size__ (32))) myty3_a;

typedef int __attribute__ ((mode(DI))) myty4;
]]

assert(ffi.sizeof("myty1") == 5 and
ffi.sizeof("myty1_a") == 5 and
ffi.alignof("myty2") == 16 and
ffi.alignof("myty2_a") == 16 and
ffi.sizeof("myty3") == 32 and
ffi.sizeof("myty3_a") == 32 and
ffi.sizeof("myty4") == 8)
22 changes: 22 additions & 0 deletions src/x64/test/unit_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
DIR=$(cd $(dirname $0); pwd)
cd $DIR

LUAJIT=$DIR/../../luajit
HASERR=0

find $DIR/unit -name "*.lua" -print | while read x; do
$LUAJIT $x >/dev/null 2>/dev/null
if [ $? -eq 0 ]; then
echo "$x ok"
else
HASERR=1
echo "$x failed"
fi
done

if [ $HASERR -eq 0 ]; then
exit 0
fi

exit 1