diff options
author | MITSUNARI Shigeo <[email protected]> | 2020-07-20 18:24:34 +0900 |
---|---|---|
committer | MITSUNARI Shigeo <[email protected]> | 2020-07-20 18:24:34 +0900 |
commit | 0fdffc6b905d19a72140d228ab2a6e813f9be332 (patch) | |
tree | c7b7a4be7277724fa472e2f6718d39bae75e87d9 /test | |
parent | eda6e2a36439fade84b70ac4195413361a6f0d4f (diff) | |
download | xbyak-0fdffc6b905d19a72140d228ab2a6e813f9be332.tar.gz xbyak-0fdffc6b905d19a72140d228ab2a6e813f9be332.zip |
XBYAK_NOEXCEPTION for -fno-exceptions
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile | 6 | ||||
-rw-r--r-- | test/nm_frame.cpp | 2 | ||||
-rw-r--r-- | test/noexception.cpp | 111 | ||||
-rwxr-xr-x | test/test_nm.sh | 7 |
4 files changed, 124 insertions, 2 deletions
diff --git a/test/Makefile b/test/Makefile index edce942..ac69b3e 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,4 +1,4 @@ -TARGET = make_nm normalize_prefix bad_address misc cvt_test cvt_test32 +TARGET = make_nm normalize_prefix bad_address misc cvt_test cvt_test32 noexception XBYAK_INC=../xbyak/xbyak.h UNAME_S=$(shell uname -s) BIT=32 @@ -45,11 +45,15 @@ cvt_test: cvt_test.cpp ../xbyak/xbyak.h $(CXX) $(CFLAGS) $< -o $@ cvt_test32: cvt_test.cpp ../xbyak/xbyak.h $(CXX) $(CFLAGS) $< -o $@ -DXBYAK32 +noexception: noexception.cpp ../xbyak/xbyak.h + $(CXX) $(CFLAGS) $< -o $@ -fno-exceptions test_nm: normalize_prefix $(TARGET) $(MAKE) -C ../gen ifneq ($(ONLY_64BIT),1) ./test_nm.sh + ./test_nm.sh noexcept + ./noexception ./test_nm.sh Y ./test_nm.sh avx512 ./test_address.sh diff --git a/test/nm_frame.cpp b/test/nm_frame.cpp index 41cff42..161fa7a 100644 --- a/test/nm_frame.cpp +++ b/test/nm_frame.cpp @@ -22,10 +22,12 @@ class ErrorSample : public CodeGenerator { public: void gen() { +#ifndef XBYAK_NOEXCEPTION CYBOZU_TEST_EXCEPTION(mov(ptr[eax],1), std::exception); CYBOZU_TEST_EXCEPTION(test(ptr[eax],1), std::exception); CYBOZU_TEST_EXCEPTION(adc(ptr[eax],1), std::exception); CYBOZU_TEST_EXCEPTION(setz(eax), std::exception); +#endif } }; diff --git a/test/noexception.cpp b/test/noexception.cpp new file mode 100644 index 0000000..db7f99e --- /dev/null +++ b/test/noexception.cpp @@ -0,0 +1,111 @@ +#define XBYAK_NOEXCEPTION +#include <xbyak/xbyak.h> + +using namespace Xbyak; + +int g_err = 0; +int g_test = 0; + +void assertEq(int x, int y) +{ + if (x != y) { + printf("ERR x=%d y=%d\n", x, y); + g_err++; + } + g_test++; +} + +void assertBool(bool b) +{ + if (!b) { + printf("ERR assertBool\n"); + g_err++; + } + g_test++; +} + +void test1() +{ + const int v = 123; + struct Code : CodeGenerator { + Code() + { + mov(eax, v); + ret(); + } + } c; + int (*f)() = c.getCode<int (*)()>(); + assertEq(f(), v); + assertEq(Xbyak::GetError(), ERR_NONE); +} + +void test2() +{ + struct Code : CodeGenerator { + Code() + { + Label lp; + L(lp); + L(lp); + } + } c; + assertEq(Xbyak::GetError(), ERR_LABEL_IS_REDEFINED); + Xbyak::ClearError(); +} + +void test3() +{ + static struct EmptyAllocator : Xbyak::Allocator { + uint8 *alloc() { return 0; } + } emptyAllocator; + struct Code : CodeGenerator { + Code() : CodeGenerator(8, 0, &emptyAllocator) + { + mov(eax, 3); + assertBool(Xbyak::GetError() == 0); + mov(eax, 3); + mov(eax, 3); + assertBool(Xbyak::GetError() != 0); + Xbyak::ClearError(); + assertBool(Xbyak::GetError() == 0); + } + } c; +} + +void test4() +{ + struct Code : CodeGenerator { + Code() + { + mov(ptr[eax], 1); + assertBool(Xbyak::GetError() != 0); + Xbyak::ClearError(); + + test(ptr[eax], 1); + assertBool(Xbyak::GetError() != 0); + Xbyak::ClearError(); + + adc(ptr[eax], 1); + assertBool(Xbyak::GetError() != 0); + Xbyak::ClearError(); + + setz(eax); + assertBool(Xbyak::GetError() != 0); + Xbyak::ClearError(); + } + }; +} + +int main() +{ + test1(); + test2(); + test3(); + test4(); + if (g_err) { + printf("err %d/%d\n", g_err, g_test); + } else { + printf("all ok %d\n", g_test); + } + return g_err != 0; +} diff --git a/test/test_nm.sh b/test/test_nm.sh index d3f5b7f..8ed81df 100755 --- a/test/test_nm.sh +++ b/test/test_nm.sh @@ -25,6 +25,11 @@ else if ($1 == "avx512") then set OPT2="-DXBYAK64 -DUSE_AVX512" set OPT3=win64 set FILTER=./normalize_prefix +else if ($1 == "noexcept") then + echo "nasm(32bit) without exception" + set EXE=nasm + set OPT2="-DXBYAK32 -DXBYAK_NOEXCEPTION" + set OPT3=win32 else echo "nasm(32bit)" set EXE=nasm @@ -33,7 +38,7 @@ else endif set CFLAGS="-Wall -fno-operator-names -I../ $OPT2" -echo "compile make_nm.cpp" +echo "compile make_nm.cpp with $CFLAGS" g++ $CFLAGS make_nm.cpp -o make_nm ./make_nm > a.asm |