Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
herumi committed Dec 26, 2023
2 parents f17cb9d + ee26c09 commit 5438fc6
Show file tree
Hide file tree
Showing 12 changed files with 259 additions and 123 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.5)

project(xbyak LANGUAGES CXX VERSION 7.02)
project(xbyak LANGUAGES CXX VERSION 7.03)

file(GLOB headers xbyak/*.h)

Expand Down
1 change: 1 addition & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# History

* 2023/Dec/26 ver 7.03 set the default value of dfv to 0
* 2023/Dec/20 ver 7.02 SHA* support APX
* 2023/Dec/19 ver 7.01 support AESKLE, WIDE_KL, KEYLOCKER, KEYLOCKER_WIDE, detection of APX10/APX
* 2023/Dec/01 ver 7.00 support APX
Expand Down
10 changes: 10 additions & 0 deletions doc/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ vpdpbusd(xm0, xm1, xm2); // VEX encoding
- `imul(ax|T_zu, cx, 0x1234);` // Set ND=ZU
- `imul(ax|T_zu|T_nf, cx, 0x1234);` // Set ND=ZU and EVEX.NF=1
- `setb(r31b|T_zu);` // same as set(r31b); movzx(r31, r31b);
- See [sample/zero_upper.cpp](../sample/zero_upper.cpp)

### ccmpSCC and ctestSCC

- ccmpSCC(op1, op2, dfv = 0); // eflags = eflags == SCC ? cmp(op1, op2) : dfv
- ctestSCC(op1, op2, dfv = 0); // eflags = eflags == SCC ? test(op1, op2) : dfv
- SCC means source condition code such as z, a, gt.
- See [sample/ccmp.cpp](../sample/ccmp.cpp)
- Specify the union of T_of(=8), T_sf(=4), T_zf(=2), or T_cf(=1) for dfv.


## Label
Two kinds of Label are supported. (String literal and Label class).
Expand Down
8 changes: 4 additions & 4 deletions gen/gen_code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,10 +635,10 @@ void put()
// ccmpscc
// true if SCC = 0b1010, false if SCC = 0b1011 (see APX Architecture Specification p.266)
const char *s = p->ext == 10 ? "t" : p->ext == 11 ? "f" : p->name;
printf("void ccmp%s(const Operand& op1, const Operand& op2, int dfv) { opCcmp(op1, op2, dfv, 0x38, %d); }\n", s, p->ext);
printf("void ccmp%s(const Operand& op, int imm, int dfv) { opCcmpi(op, imm, dfv, %d); }\n", s, p->ext);
printf("void ctest%s(const Operand& op, const Reg& r, int dfv) { opCcmp(op, r, dfv, 0x84, %d); }\n", s, p->ext);
printf("void ctest%s(const Operand& op, int imm, int dfv) { opTesti(op, imm, dfv, %d); }\n", s, p->ext);
printf("void ccmp%s(const Operand& op1, const Operand& op2, int dfv = 0) { opCcmp(op1, op2, dfv, 0x38, %d); }\n", s, p->ext);
printf("void ccmp%s(const Operand& op, int imm, int dfv = 0) { opCcmpi(op, imm, dfv, %d); }\n", s, p->ext);
printf("void ctest%s(const Operand& op, const Reg& r, int dfv = 0) { opCcmp(op, r, dfv, 0x84, %d); }\n", s, p->ext);
printf("void ctest%s(const Operand& op, int imm, int dfv = 0) { opTesti(op, imm, dfv, %d); }\n", s, p->ext);
}
}
{
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
project(
'xbyak',
'cpp',
version: '7.02',
version: '7.03',
license: 'BSD-3-Clause',
default_options: 'b_ndebug=if-release'
)
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# Xbyak 7.02 [![Badge Build]][Build Status]
# Xbyak 7.03 [![Badge Build]][Build Status]

*A C++ JIT assembler for x86 (IA32), x64 (AMD64, x86-64)*

Expand Down
3 changes: 2 additions & 1 deletion 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 7.02
C++用x86(IA-32), x64(AMD64, x86-64) JITアセンブラ Xbyak 7.03

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

2023/12/26 ver 7.03 dfvのデフォルト値を0に設定
2023/12/20 ver 7.02 SHA*のAPX対応
2023/12/19 ver 7.01 AESKLE, WIDE_KL, KEYLOCKER, KEYLOCKER_WIDE対応 APX10/APX判定対応
2023/12/01 ver 7.00 APX対応
Expand Down
10 changes: 9 additions & 1 deletion sample/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ else
endif

ifeq ($(BIT),64)
TARGET += test64 bf64 memfunc64 test_util64 jmp_table64
TARGET += test64 bf64 memfunc64 test_util64 jmp_table64 zero_upper ccmp
ifeq ($(BOOST_EXIST),1)
TARGET += calc64 #calc2_64
endif
Expand Down Expand Up @@ -103,6 +103,14 @@ profiler: profiler.cpp ../xbyak/xbyak_util.h
$(CXX) $(CFLAGS) profiler.cpp -o $@
profiler-vtune: profiler.cpp ../xbyak/xbyak_util.h
$(CXX) $(CFLAGS) profiler.cpp -o $@ -DXBYAK_USE_VTUNE -I /opt/intel/vtune_amplifier/include/ -L /opt/intel/vtune_amplifier/lib64 -ljitprofiling -ldl
zero_upper: zero_upper.cpp $(XBYAK_INC)
$(CXX) $(CFLAGS) zero_upper.cpp -o $@
test_zero_upper: zero_upper
sde -future -- ./zero_upper
ccmp: ccmp.cpp $(XBYAK_INC)
$(CXX) $(CFLAGS) ccmp.cpp -o $@
test_ccmp: ccmp
sde -future -- ./ccmp

clean:
rm -rf $(TARGET) profiler profiler-vtune
Expand Down
68 changes: 68 additions & 0 deletions sample/ccmp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
An example of ccmp
> g++ ccmp.cpp -I ../xbyak
> sde -future -- ./a.out
*/
#include <stdio.h>
#include <xbyak/xbyak.h>
#include <xbyak/xbyak_util.h>

using namespace Xbyak;

struct Code1 : Xbyak::CodeGenerator {
Code1()
{
Xbyak::util::StackFrame sf(this, 2);
const auto& p1 = sf.p[0];
const auto& p2 = sf.p[1];
int dfv = 0;
cmp(p1, 3);
ctesta(p2, 1, dfv); // eflags = (p1 > 3) ? (p2 & 1) : dfv;
setz(al|T_zu);
}
};

struct Code2 : Xbyak::CodeGenerator {
Code2()
{
Xbyak::util::StackFrame sf(this, 3);
const auto& p1 = sf.p[0];
const auto& p2 = sf.p[1];
const auto& p3 = sf.p[2];
int dfv = 0;
cmp(p1, 1);
ccmpe(p2, 2, dfv); // eflags = p1==1 ? p2==2 : dfv;
ccmpe(p3, 3, dfv); // eflags = (p1==1 && p2==2) ? p3==3 : dfv;
setz(al|T_zu); // p1==1 && p2==2 && p3==3
}
};


int main()
try
{
{
puts("(p1 > 3) && ((p2 & 1) == 0)");
Code1 c;
auto f = c.getCode<int (*)(int, int)>();
for (int p1 = 2; p1 < 5; p1++) {
for (int p2 = 0; p2 < 3; p2++) {
printf("p1=%d p2=%d ret=%d (%d)\n", p1, p2, f(p1, p2), p1 > 3 && ((p2&1) == 0));
}
}
}
{
puts("p1 == 1 && p2 == 2 && p3 == 3");
Code2 c;
auto f = c.getCode<int (*)(int, int, int)>();
for (int p1 = 0; p1 < 3; p1++) {
for (int p2 = 1; p2 < 4; p2++) {
for (int p3 = 2; p3 < 5; p3++) {
printf("p1=%d p2=%d p3=%d ret=%d (%d)\n", p1, p2, p3, f(p1, p2, p3), p1==1 && p2==2 && p3==3);
}
}
}
}
} catch (std::exception& e) {
printf("ERR %s\n", e.what());
}
48 changes: 48 additions & 0 deletions sample/zero_upper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
An example of T_zu (zero upper) flag
> g++ zero_upper.cpp -I ../xbyak
> sde -future -- ./a.out
*/
#include <stdio.h>
#include <xbyak/xbyak.h>

using namespace Xbyak;

struct Code : Xbyak::CodeGenerator {
Code(int mode)
{
mov(eax, 0x12345678);
cmp(eax, eax); // ZF=1
switch (mode) {
case 0: // imul
puts("imul");
imul(ax,ax, 0x1234);
break;
case 1: // imul+zu
puts("imul+zu");
imul(ax|T_zu, ax, 0x1234);
break;
case 2: // setz
puts("setz");
setz(al);
break;
case 3: // setz+zu
puts("setz+zu");
setz(al|T_zu);
break;
}
ret();
}
};

int main()
try
{
for (int mode = 0; mode < 4; mode++) {
Code c(mode);
auto f = c.getCode<int (*)()>();
printf("ret=%08x\n", f());
}
} catch (std::exception& e) {
printf("ERR %s\n", e.what());
}
2 changes: 1 addition & 1 deletion xbyak/xbyak.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ namespace Xbyak {

enum {
DEFAULT_MAX_CODE_SIZE = 4096,
VERSION = 0x7020 /* 0xABCD = A.BC(.D) */
VERSION = 0x7030 /* 0xABCD = A.BC(.D) */
};

#ifndef MIE_INTEGER_TYPE_DEFINED
Expand Down
Loading

0 comments on commit 5438fc6

Please sign in to comment.