8000 Prune a lot of unused C code. Make sure `miniruby` still builds. (#185) · kddnewton/ruby@661dc50 · GitHub
[go: up one dir, main page]

Skip to content

Commit 661dc50

Browse files
authored
Prune a lot of unused C code. Make sure miniruby still builds. (ruby#185)
* Prune a lot of unused C code. Make sure miniruby still builds. * Prune yet more C code
1 parent ef1db76 commit 661dc50

File tree

10 files changed

+13
-2125
lines changed

10 files changed

+13
-2125
lines changed

common.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17693,5 +17693,4 @@ yjit.$(OBJEXT): {$(VPATH)}yjit_core.c
1769317693
yjit.$(OBJEXT): {$(VPATH)}yjit_core.h
1769417694
yjit.$(OBJEXT): {$(VPATH)}yjit_iface.c
1769517695
yjit.$(OBJEXT): {$(VPATH)}yjit_iface.h
17696-
yjit.$(OBJEXT): {$(VPATH)}yjit_utils.c
1769717696
# AUTOGENERATED DEPENDENCIES END

yjit.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,9 @@
3737
#include "yjit_asm.c"
3838

3939
// Code block into which we write machine code
40-
static codeblock_t block;
4140
static codeblock_t *cb = NULL;
4241

4342
// Code block into which we write out-of-line machine code
44-
static codeblock_t outline_block;
4543
static codeblock_t *ocb = NULL;
4644

4745
// NOTE: We can trust that uint8_t has no "padding bits" since the C spec
@@ -326,7 +324,7 @@ rb_get_ec_cfp(rb_execution_context_t *ec) {
326324

327325
VALUE*
328326
rb_get_cfp_pc(struct rb_control_frame_struct *cfp) {
329-
return cfp->pc;
327+
return (VALUE*)cfp->pc;
330328
}
331329

332330
VALUE*
@@ -341,7 +339,7 @@ rb_get_cfp_self(struct rb_control_frame_struct *cfp) {
341339

342340
VALUE*
343341
rb_get_cfp_ep(struct rb_control_frame_struct *cfp) {
344-
return cfp->ep;
342+
return (VALUE*)cfp->ep;
345343
}
346344

347345
VALUE
@@ -390,7 +388,6 @@ rb_get_call_data_ci(struct rb_call_data* cd) {
390388
// break out of invalidation race when there are multiple ractors.
391389
static uint32_t yjit_codepage_frozen_bytes = 0;
392390

393-
#include "yjit_utils.c"
394391
#include "yjit_core.c"
395392
#include "yjit_iface.c"
396393
#include "yjit_codegen.c"

yjit_asm.c

Lines changed: 0 additions & 254 deletions
Original file line numberDiff line numberDiff line change
@@ -61,55 +61,6 @@ x86opnd_t mem_opnd(uint32_t num_bits, x86opnd_t base_reg, int32_t disp)
6161
return opnd;
6262
}
6363

64-
#if 0
65-
x86opnd_t mem_opnd_sib(uint32_t num_bits, x86opnd_t base_reg, x86opnd_t index_reg, int32_t scale, int32_t disp)
66-
{
67-
uint8_t scale_exp;
68-
switch (scale) {
69-
case 8:
70-
scale_exp = 3;
71-
break;
72-
case 4:
73-
scale_exp = 2;
74-
break;
75-
case 2:
76-
scale_exp = 1;
77-
break;
78-
case 1:
79-
scale_exp = 0;
80-
break;
81-
default:
82-
rb_bug("yjit: scale not one of 1,2,4,8");
83-
break;
84-
}
85-
86-
bool is_iprel = base_reg.as.reg.reg_type == REG_IP;
87-
88-
x86opnd_t opnd = {
89-
OPND_MEM,
90-
num_bits,
91-
.as.mem = {
92-
.base_reg_no = base_reg.as.reg.reg_no,
93-
.idx_reg_no = index_reg.as.reg.reg_no,
94-
.has_idx = 1,
95-
.scale_exp = scale_exp,
96-
.is_iprel = is_iprel,
97-
.disp = disp
98-
}
99-
};
100-
101-
return opnd;
102-
}
103-
#endif
104-
105-
static x86opnd_t resize_opnd(x86opnd_t opnd, uint32_t num_bits)
106-
{
107-
assert (num_bits % 8 == 0);
108-
x86opnd_t sub = opnd;
109-
sub.num_bits = num_bits;
110-
return sub;
111-
}
112-
11364
x86opnd_t imm_opnd(int64_t imm)
11465
{
11566
x86opnd_t opnd = {
@@ -1578,98 +1529,6 @@ void pop(codeblock_t *cb, x86opnd_t opnd)
15781529
}
15791530
}
15801531

1581-
/// popfq - Pop the flags register (64-bit)
1582-
void popfq(codeblock_t *cb)
1583-
{
1584-
//cb.writeASM("popfq");
1585-
1586-
// REX.W + 0x9D
1587-
cb_write_bytes(cb, 2, 0x48, 0x9D);
1588-
}
1589-
1590-
/// push - Push an operand on the stack
1591-
void push(codeblock_t *cb, x86opnd_t opnd)
1592-
{
1593-
assert (opnd.num_bits == 64);
1594-
1595-
//cb.writeASM("push", opnd);
1596-
1597-
if (opnd.type == OPND_REG) {
1598-
if (rex_needed(opnd))
1599-
cb_write_rex(cb, false, 0, 0, opnd.as.reg.reg_no);
1600-
cb_write_opcode(cb, 0x50, opnd);
1601-
}
1602-
else if (opnd.type == OPND_MEM) {
1603-
cb_write_rm(cb, false, false, NO_OPND, opnd, 6, 1, 0xFF);
1604-
}
1605-
else {
1606-
assert(false && "unexpected operand type");
1607-
}
1608-
}
1609-
1610-
/// pushfq - Push the flags register (64-bit)
1611-
void pushfq(codeblock_t *cb)
1612-
{
1613-
//cb.writeASM("pushfq");
1614-
cb_write_byte(cb, 0x9C);
1615-
}
1616-
1617-
/// ret - Return from call, popping only the return address
1618-
void ret(codeblock_t *cb)
1619-
{
1620-
//cb.writeASM("ret");
1621-
cb_write_byte(cb, 0xC3);
1622-
}
1623-
1624-
#if 0
1625-
// sal - Shift arithmetic left
1626-
void sal(codeblock_t *cb, x86opnd_t opnd0, x86opnd_t opnd1)
1627-
{
1628-
cb_write_shift(
1629-
cb,
1630-
"sal",
1631-
0xD1, // opMemOnePref,
1632-
0xD3, // opMemClPref,
1633-
0xC1, // opMemImmPref,
1634-
0x04,
1635-
opnd0,
1636-
opnd1
1637-
);
1638-
}
1639-
#endif
1640-
1641-
/// sar - Shift arithmetic right (signed)
1642-
void sar(codeblock_t *cb, x86opnd_t opnd0, x86opnd_t opnd1)
1643-
{
1644-
cb_write_shift(
1645-
cb,
1646-
"sar",
1647-
0xD1, // opMemOnePref,
1648-
0xD3, // opMemClPref,
1649-
0xC1, // opMemImmPref,
1650-
0x07,
1651-
opnd0,
1652-
opnd1
1653-
);
1654-
}
1655-
1656-
#if 0
1657-
// shl - Shift logical left
1658-
void shl(codeblock_t *cb, x86opnd_t opnd0, x86opnd_t opnd1)
1659-
{
1660-
cb_write_shift(
1661-
cb,
1662-
"shl",
1663-
0xD1, // opMemOnePref,
1664-
0xD3, // opMemClPref,
1665-
0xC1, // opMemImmPref,
1666-
0x04,
1667-
opnd0,
1668-
opnd1
1669-
);
1670-
}
1671-
#endif
1672-
16731532
/// shr - Shift logical right (unsigned)
16741533
void shr(codeblock_t *cb, x86opnd_t opnd0, x86opnd_t opnd1)
16751534
{
@@ -1704,119 +1563,6 @@ void sub(codeblock_t *cb, x86opnd_t opnd0, x86opnd_t opnd1)
17041563
);
17051564
}
17061565

1707-
/// test - Logical Compare
1708-
void test(codeblock_t *cb, x86opnd_t rm_opnd, x86opnd_t test_opnd)
1709-
{
1710-
assert (rm_opnd.type == OPND_REG || rm_opnd.type == OPND_MEM);
1711-
assert (test_opnd.type == OPND_REG || test_opnd.type == OPND_IMM);
1712-
1713-
// If the second operand is an immediate
1714-
if (test_opnd.type == OPND_IMM)
1715-
{
1716-
x86opnd_t imm_opnd = test_opnd;
1717-
1718-
if (imm_opnd.as.imm >= 0)
1719-
{
1720-
assert (unsig_imm_size(imm_opnd.as.unsig_imm) <= 32);
1721-
assert (unsig_imm_size(imm_opnd.as.unsig_imm) <= rm_opnd.num_bits);
1722-
1723-
// Use the smallest operand size possible
1724-
rm_opnd = resize_opnd(rm_opnd, unsig_imm_size(imm_opnd.as.unsig_imm));
1725-
1726-
if (rm_opnd.num_bits == 8)
1727-
{
1728-
cb_write_rm(cb, false, false, NO_OPND, rm_opnd, 0x00, 1, 0xF6);
1729-
cb_write_int(cb, imm_opnd.as.imm, rm_opnd.num_bits);
1730-
}
1731-
else
1732-
{
1733-
cb_write_rm(cb, rm_opnd.num_bits == 16, false, NO_OPND, rm_opnd, 0x00, 1, 0xF7);
1734-
cb_write_int(cb, imm_opnd.as.imm, rm_opnd.num_bits);
1735-
}
1736-
}
1737-
else
1738-
{
1739-
// This mode only applies to 64-bit R/M operands with 32-bit signed immediates
1740-
assert (imm_opnd.as.imm < 0);
1741-
assert (sig_imm_size(imm_opnd.as.imm) <= 32);
1742-
assert (rm_opnd.num_bits == 64);
1743-
cb_write_rm(cb, false, true, NO_OPND, rm_opnd, 0x00, 1, 0xF7);
1744-
cb_write_int(cb, imm_opnd.as.imm, 32);
1745-
}
1746-
}
1747-
else
1748-
{
1749-
assert (test_opnd.num_bits == rm_opnd.num_bits);
1750-
1751-
if (rm_opnd.num_bits == 8)
1752-
{
1753-
cb_write_rm(cb, false, false, test_opnd, rm_opnd, 0xFF, 1, 0x84);
1754-
}
1755-
else
1756-
{
1757-
cb_write_rm(cb, rm_opnd.num_bits == 16, rm_opnd.num_bits == 64, test_opnd, rm_opnd, 0xFF, 1, 0x85);
1758-
}
1759-
}
1760-
}
1761-
1762-
#if 0
1763-
/// Undefined opcode
1764-
void ud2(codeblock_t *cb)
1765-
{
1766-
cb_write_bytes(cb, 2, 0x0F, 0x0B);
1767-
}
1768-
#endif
1769-
1770-
#if 0
1771-
/// xchg - Exchange Register/Memory with Register
1772-
void xchg(codeblock_t *cb, x86opnd_t rm_opnd, x86opnd_t r_opnd)
1773-
{
1774-
assert (rm_opnd.num_bits == 64);
1775-
assert (r_opnd.num_bits == 64);
1776-
assert (rm_opnd.type == OPND_REG);
1777-
assert (r_opnd.type == OPND_REG);
1778-
1779-
// If we're exchanging with RAX
1780-
if (rm_opnd.type == OPND_REG && rm_opnd.as.reg.reg_no == RAX.as.reg.reg_no)
1781-
{
1782-
// Write the REX byte
1783-
cb_write_rex(cb, rm_opnd.num_bits == 64, 0, 0, r_opnd.as.reg.reg_no);
1784-
1785-
// Write the opcode and register number
1786-
cb_write_byte(cb, 0x90 + (r_opnd.as.reg.reg_no & 7));
1787-
}
1788-
else
1789-
{
1790-
cb_write_rm(cb, rm_opnd.num_bits == 16, rm_opnd.num_bits == 64, r_opnd, rm_opnd, 0xFF, 1, 0x87);
1791-
}
1792-
}
1793-
#endif
1794-
1795-
/// xor - Exclusive bitwise OR
1796-
void xor(codeblock_t *cb, x86opnd_t opnd0, x86opnd_t opnd1)
1797-
{
1798-
cb_write_rm_multi(
1799-
cb,
1800-
"xor",
1801-
0x30, // opMemReg8
1802-
0x31, // opMemRegPref
1803-
0x32, // opRegMem8
1804-
0x33, // opRegMemPref
1805-
0x80, // opMemImm8
1806-
0x83, // opMemImmSml
1807-
0x81, // opMemImmLrg
1808-
0x06, // opExtImm
1809-
opnd0,
1810-
opnd1
1811-
);
1812-
}
1813-
1814-
// LOCK - lock prefix for atomic shared memory operations
1815-
void cb_write_lock_prefix(codeblock_t *cb)
1816-
{
1817-
cb_write_byte(cb, 0xF0);
1818-
}
1819-
18201566
void cb_mark_all_writeable(codeblock_t * cb)
18211567
{
18221568
if (mprotect(cb->mem_block_, cb->mem_size, PROT_READ | PROT_WRITE)) {

0 commit comments

Comments
 (0)
0