Skip to content

Commit

Permalink
support AVX
Browse files Browse the repository at this point in the history
  • Loading branch information
herumi committed Feb 4, 2011
1 parent 9fa05da commit 3510943
Show file tree
Hide file tree
Showing 19 changed files with 3,351 additions and 6,425 deletions.
2 changes: 1 addition & 1 deletion COPYRIGHT
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Copyright (c) 2007-2010 MITSUNARI Shigeo
Copyright (c) 2007-2011 MITSUNARI Shigeo
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
572 changes: 568 additions & 4 deletions gen/gen_code.cpp

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

C++用x86(IA-32), x64(AMD64, x86-64) JITアセンブラ Xbyak version 2.29
C++用x86(IA-32), x64(AMD64, x86-64) JITアセンブラ Xbyak version 2.99

-----------------------------------------------------------------------------
◎概要
Expand All @@ -14,12 +14,12 @@
xbyak.hをインクルードするだけですぐ利用することができます.
C++の枠組み内で閉じているため,外部アセンブラは不要です.
32bit/64bit両対応です.
対応ニーモニック:特権命令除くx86, MMX/MMX2/SSE/SSE2/SSE3/SSSE3/SSE4/FPU(一部)
対応ニーモニック:特権命令除くx86, MMX/MMX2/SSE/SSE2/SSE3/SSSE3/SSE4/FPU(一部)/AVX

・Windows Xp(32bit, 64bit), Vista/Linux(32bit, 64bit)/Intel Mac対応
Windows Xp上ではVC2005 Express Ed., VC2008
Windows Xp上ではVC2005 Express Ed., VC2008, VC2010,
Windows Vista
Linux (kernel 2.4.32)上ではgcc 4.3.0, CentOS 5.1上ではgcc 4.1.2
Linux (kernel 2.4.32)上ではgcc 4.5.0, CentOS 5.1上ではgcc 4.1.2
Intel Mac
などで動作確認をしています.

Expand Down Expand Up @@ -199,6 +199,9 @@ sample/{echo,hello}.bfは http://www.kmonos.net/alang/etc/brainfuck.php から
-----------------------------------------------------------------------------
◎履歴

2011/02/04 ver 2.99 beta support AVX
2010/12/08 ver 2.31 fix ptr [rip + 32bit offset], support rtdscp
2010/10/19 ver 2.30 support pclmulqdq, aesdec, aesdeclast, aesenc, aesenclast, aesimc, aeskeygenassist
2010/07/07 ver 2.29 fix call(<label>)
2010/06/17 ver 2.28 move some member functions to public
2010/06/01 ver 2.27 support encoding of mov(reg64, imm) like yasm(not nasm)
Expand Down
15 changes: 9 additions & 6 deletions readme_e.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Xbyak 2.29 ; JIT assembler for x86(IA32), x64(AMD64, x86-64) by C++
Xbyak 2.99 ; JIT assembler for x86(IA32), x64(AMD64, x86-64) by C++

-----------------------------------------------------------------------------
<Abstract>
Expand All @@ -12,11 +12,11 @@ x64(AMD64, x86-64) mnemonic.
header file only
you can use Xbyak's functions at once if xbyak.h is included.

MMX/MMX2/SSE/SSE2/SSE3/SSSE3/SSE4/FPU(partial) are available.
MMX/MMX2/SSE/SSE2/SSE3/SSSE3/SSE4/FPU(partial)/AVX are available.

Windows Xp(32bit, 64bit), Vista, Linux(32bit, 64bit), Intel Mac ready
support Visual Studio C++ 2005 Express Ed., VC2008 Pro,
mingw 3.4.2, icc 7.2, gcc 4.1.1, and so on.
support Visual Studio C++ 2005 Express Ed., VC2008 Pro, VC2010,
mingw 3.4.2, icc 7.2, gcc 4.5, and so on.

Note: "-fno-operator-names" option is required on gcc to avoid analyzing
"and", "or", etc. as operators.
Expand Down Expand Up @@ -148,6 +148,9 @@ http://www.opensource.org/licenses/bsd-license.php
-----------------------------------------------------------------------------
<History>

2011/Feb/04 ver 2.99 beta support AVX
2010/Dec/08 ver 2.31 fix ptr [rip + 32bit offset], support rdtscp
2010/Oct/19 ver 2.30 support pclmulqdq, aesdec, aesdeclast, aesenc, aesenclast, aesimc, aeskeygenassist
2010/Jun/07 ver 2.29 fix call(<label>)
2010/Jun/17 ver 2.28 move some member functions to public
2010/Jun/01 ver 2.27 support encoding of mov(reg64, imm) like yasm(not nasm)
Expand Down Expand Up @@ -187,5 +190,5 @@ http://www.opensource.org/licenses/bsd-license.php
MITSUNARI Shigeo(herumi at nifty dot com)

---
$Revision: 1.49 $
$Date: 2010/07/07 01:00:04 $
$Revision: 1.54 $
$Date: 2011/02/04 03:27:59 $
11 changes: 9 additions & 2 deletions sample/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ endif
ifeq ($(BIT),64)
TARGET += test64 bf64 memfunc64 test_util64
ifeq ($(BOOST_EXIT),1)
TARGET += calc64
TARGET += calc64 calc2_64
endif
endif

ifeq ($(BOOST_EXIT),1)
TARGET += calc
TARGET += calc calc2
endif

all: $(TARGET)
Expand All @@ -38,6 +38,10 @@ calc:
g++ $(CFLAGS) calc.cpp -o $@ -m32
calc64:
g++ $(CFLAGS) calc.cpp -o $@ -m64
#calc2:
# g++ $(CFLAGS) calc2.cpp -o $@ -m32
#calc2_64:
# g++ $(CFLAGS) calc2.cpp -o $@ -m64

bf:
g++ $(CFLAGS) bf.cpp -o $@ -m32
Expand Down Expand Up @@ -67,10 +71,13 @@ test64: test0.cpp $(XBYAK_INC)
quantize : quantize.cpp $(XBYAK_INC)
calc : calc.cpp $(XBYAK_INC)
calc64 : calc.cpp $(XBYAK_INC)
calc2 : calc2.cpp $(XBYAK_INC)
calc2_64 : calc2.cpp $(XBYAK_INC)
bf : bf.cpp $(XBYAK_INC)
bf64 : bf.cpp $(XBYAK_INC)
memfunc : memfunc.cpp $(XBYAK_INC)
memfunc64 : memfunc.cpp $(XBYAK_INC)
toyvm : toyvm.cpp $(XBYAK_INC)
test_util : test_util.cpp $(XBYAK_INC) ../xbyak/xbyak_util.h
test_util2 : test_util.cpp $(XBYAK_INC) ../xbyak/xbyak_util.h

27 changes: 16 additions & 11 deletions sample/bf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Brainfuck : public Xbyak::CodeGenerator {
is.unget();
return count;
}
Brainfuck(std::istream& is) : CodeGenerator(10000)
Brainfuck(std::istream& is) : CodeGenerator(100000)
{
// void (*)(void* putchar, void* getchar, int *stack)
using namespace Xbyak;
Expand Down Expand Up @@ -160,7 +160,7 @@ class Brainfuck : public Xbyak::CodeGenerator {

void dump(const Xbyak::uint8 *code, size_t size)
{
puts("#include <stdio.h>\nstatic int stack[32768];\nstatic const unsigned char code[] = {");
puts("#include <stdio.h>\nstatic int stack[128 * 1024];\nstatic const unsigned char code[] = {");
for (size_t i = 0; i < size; i++) {
printf("0x%02x,", code[i]); if ((i % 16) == 15) putchar('\n');
}
Expand All @@ -183,23 +183,28 @@ void dump(const Xbyak::uint8 *code, size_t size)
int main(int argc, char *argv[])
{
#ifdef XBYAK32
puts("32bit mode");
fprintf(stderr, "32bit mode\n");
#else
puts("64bit mode");
fprintf(stderr, "64bit mode\n");
#endif
if (argc == 1) {
fprintf(stderr, "bf filename.bf [0|1]\n");
return 1;
}
std::ifstream ifs(argv[1]);
int mode = argc == 3 ? atoi(argv[2]) : 0;
Brainfuck bf(ifs);
if (mode == 0) {
static int stack[32768];
((void (*)(void*, void*, int *))bf.getCode())((void*)putchar, (void*)getchar, stack);
} else {
dump(bf.getCode(), bf.getSize());
try {
Brainfuck bf(ifs);
if (mode == 0) {
static int stack[128 * 1024];
((void (*)(void*, void*, int *))bf.getCode())((void*)putchar, (void*)getchar, stack);
} else {
dump(bf.getCode(), bf.getSize());
}
} catch (Xbyak::Error err) {
printf("ERR:%s(%d)\n", Xbyak::ConvertErrorToString(err), err);
} catch (...) {
printf("unknown error\n");
}
return 0;
}

10 changes: 4 additions & 6 deletions sample/calc.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
@author herumi
@date $Date: 2010/04/15 06:52:07 $
@date $Date: 2010/11/17 02:58:03 $
tiny calculator 2
tiny calculator
This program generates a function to calc the value of
polynomial given by user in run-time.
use boost::sprit
use boost::spirit::classic
see calc2.cpp for new version of boost::spirit
*/
#include <stdio.h>
#include <sstream>
Expand All @@ -16,8 +16,6 @@
#pragma warning(disable : 4127) // for boost(constant condition)
#pragma warning(disable : 4512) // for boost
#endif
//#include <boost/spirit/iterator/file_iterator.hpp>
//#include <boost/spirit/core.hpp>
#include <boost/spirit/include/classic_file_iterator.hpp>
#include <boost/spirit/include/classic_core.hpp>
#include <boost/bind.hpp>
Expand Down
1 change: 0 additions & 1 deletion sample/test0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,5 @@ int main()
} catch (...) {
printf("unknown error\n");
}
return 0;
}

29 changes: 27 additions & 2 deletions sample/test_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

#define NUM_OF_ARRAY(x) (sizeof(x) / sizeof(x[0]))

struct PopCountTest : public Xbyak::CodeGenerator {
PopCountTest(int n)
{
mov(eax, n);
popcnt(eax, eax);
ret();
}
};

void putCPUinfo()
{
using namespace Xbyak::util;
Expand All @@ -27,18 +36,34 @@ void putCPUinfo()
{ Cpu::tE3DN, "e3dn" },
{ Cpu::tSSE4a, "sse4a" },
{ Cpu::tSSE5, "sse5" },
{ Cpu::tAESNI, "aesni" },
{ Cpu::tRDTSCP, "rdtscp" },
{ Cpu::tOSXSACE, "osxsace(xgetvb)" },
{ Cpu::tPCLMULQDQ, "pclmulqdq" },
{ Cpu::tAVX, "avx" },
{ Cpu::tFMA, "fma" },
};
for (size_t i = 0; i < NUM_OF_ARRAY(tbl); i++) {
if (cpu.has(tbl[i].type)) printf(" %s", tbl[i].str);
}
printf("\n");
if (cpu.has(Cpu::tPOPCNT)) {
const int n = 0x12345678; // bitcount = 13
const int ok = 13;
int r = ((int (*)())(PopCountTest(n).getCode()))();
if (r == ok) {
puts("popcnt ok");
} else {
printf("popcnt ng %d %d\n", r, ok);
}
}
}

#ifdef XBYAK32
struct EipTest : public Xbyak::util::EnableSetEip<Xbyak::CodeGenerator> {
struct EipTest : public Xbyak::CodeGenerator {
EipTest()
{
setEipTo(eax);
Xbyak::util::setEipTo(this, eax);
ret();
}
};
Expand Down
5 changes: 5 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ test: normalize_prefix jmp
./test_address.sh 64
./jmp

test_avx:
./test_avx.sh
./test_avx.sh Y
./test_avx.sh 64
./test_avx.sh Y64
clean:
rm -rf *.o $(TARGET)

Expand Down
Loading

0 comments on commit 3510943

Please sign in to comment.