File tree 3 files changed +66
-1
lines changed
3 files changed +66
-1
lines changed Original file line number Diff line number Diff line change 1
1
HEADER =../xbyak_riscv/xbyak_riscv_mnemonic.hpp
2
2
3
- test : $(HEADER ) jmp_test.exe
3
+ test : $(HEADER ) jmp_test.exe misc_test.exe
4
4
./jmp_test.exe
5
+ ./misc_test.exe
5
6
./test.sh
6
7
# ./test.sh svc
7
8
Original file line number Diff line number Diff line change
1
+ #include < cybozu/test.hpp>
2
+ #include < xbyak_riscv/xbyak_riscv.hpp>
3
+
4
+ using namespace Xbyak_riscv ;
5
+
6
+ CYBOZU_TEST_AUTO (align)
7
+ {
8
+ struct Code : CodeGenerator {
9
+ Code ()
10
+ {
11
+ nop ();
12
+ addr1 = getCurr ();
13
+ align (16 );
14
+ addr2 = getCurr ();
15
+ nop ();
16
+ nop ();
17
+ addr3 = getCurr ();
18
+ align (16 );
19
+ addr4 = getCurr ();
20
+ for (int i = 0 ; i < 4 ; i++) nop ();
21
+ addr5 = getCurr ();
22
+ // already aligned
23
+ align (16 );
24
+ addr6 = getCurr ();
25
+
26
+ }
27
+ const uint8_t *addr1;
28
+ const uint8_t *addr2;
29
+ const uint8_t *addr3;
30
+ const uint8_t *addr4;
31
+ const uint8_t *addr5;
32
+ const uint8_t *addr6;
33
+ } c;
34
+ c.ready ();
35
+ printf (" addr1=%p\n " , c.addr1 );
36
+ printf (" addr2=%p\n " , c.addr2 );
37
+ printf (" addr3=%p\n " , c.addr3 );
38
+ printf (" addr4=%p\n " , c.addr4 );
39
+ printf (" addr5=%p\n " , c.addr5 );
40
+ printf (" addr6=%p\n " , c.addr6 );
41
+ CYBOZU_TEST_ASSERT (size_t (c.addr1 ) % 16 );
42
+ CYBOZU_TEST_ASSERT ((size_t (c.addr2 ) % 16 ) == 0 );
43
+ CYBOZU_TEST_ASSERT (size_t (c.addr3 ) % 16 );
44
+ CYBOZU_TEST_ASSERT ((size_t (c.addr4 ) % 16 ) == 0 );
45
+ CYBOZU_TEST_ASSERT ((size_t (c.addr5 ) % 16 ) == 0 );
46
+ CYBOZU_TEST_EQUAL (c.addr5 , c.addr6 );
47
+ }
48
+
49
+
Original file line number Diff line number Diff line change @@ -102,6 +102,7 @@ enum {
102
102
ERR_CANT_ALLOC,
103
103
ERR_BAD_PARAMETER,
104
104
ERR_MUNMAP,
105
+ ERR_BAD_ALIGN,
105
106
ERR_INTERNAL // Put it at last.
106
107
};
107
108
@@ -123,6 +124,7 @@ inline const char *ConvertErrorToString(int err)
123
124
" can't alloc" ,
124
125
" bad parameter" ,
125
126
" munmap" ,
127
+ " bad align" ,
126
128
" internal error"
127
129
};
128
130
assert (ERR_INTERNAL == sizeof (errTbl) / sizeof (*errTbl));
@@ -1349,6 +1351,19 @@ class CodeGenerator : public CodeArray {
1349
1351
// set read/exec
1350
1352
void readyRE () { return ready (PROTECT_RE); }
1351
1353
1354
+ void align (size_t x)
1355
+ {
1356
+ if (x == 1 ) return ;
1357
+ if (x < 4 || (x & (x - 1 ))) XBYAK_RISCV_THROW (ERR_BAD_ALIGN)
1358
+ size_t remain = size_t (getCurr ()) % x;
1359
+ if (remain % 4 ) XBYAK_RISCV_THROW (ERR_INTERNAL)
1360
+ if (remain) {
1361
+ for (size_t i = 0 ; i < (x - remain) / 4 ; i++) {
1362
+ nop ();
1363
+ }
1364
+ }
1365
+ }
1366
+
1352
1367
#include " xbyak_riscv_mnemonic.hpp"
1353
1368
#if defined(XBYAK_RISCV_V) && XBYAK_RISCV_V == 1
1354
1369
#include " xbyak_riscv_v.hpp"
You can’t perform that action at this time.
0 commit comments