Skip to content

Commit

Permalink
builtin: reduce the number of array allocations for consts in all V p…
Browse files Browse the repository at this point in the history
…rograms (#18889)
  • Loading branch information
ArtemkaKun committed Jul 19, 2023
1 parent 44d2f2b commit 1ed0cd9
Show file tree
Hide file tree
Showing 12 changed files with 1,317 additions and 644 deletions.
4 changes: 2 additions & 2 deletions vlib/math/bits/bits.v
Expand Up @@ -7,11 +7,11 @@ const (
// See http://supertech.csail.mit.edu/papers/debruijn.pdf
de_bruijn32 = u32(0x077CB531)
de_bruijn32tab = [u8(0), 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13,
23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9]
23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9]!
de_bruijn64 = u64(0x03f79d71b4ca8b09)
de_bruijn64tab = [u8(0), 1, 56, 2, 57, 49, 28, 3, 61, 58, 42, 50, 38, 29, 17, 4, 62, 47, 59,
36, 45, 43, 51, 22, 53, 39, 33, 30, 24, 18, 12, 5, 63, 55, 48, 27, 60, 41, 37, 16, 46,
35, 44, 21, 52, 32, 23, 11, 54, 26, 40, 15, 34, 20, 31, 10, 25, 14, 19, 9, 13, 8, 7, 6]
35, 44, 21, 52, 32, 23, 11, 54, 26, 40, 15, 34, 20, 31, 10, 25, 14, 19, 9, 13, 8, 7, 6]!
)

const (
Expand Down
8 changes: 4 additions & 4 deletions vlib/math/bits/bits_tables.v
Expand Up @@ -21,7 +21,7 @@ const (
0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01,
0x00, 0x05, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00,
0x01, 0x00, 0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02,
0x00, 0x01, 0x00]
0x00, 0x01, 0x00]!
pop_8_tab = [u8(0x00), 0x01, 0x01, 0x02, 0x01, 0x02, 0x02, 0x03, 0x01, 0x02, 0x02, 0x03, 0x02,
0x03, 0x03, 0x04, 0x01, 0x02, 0x02, 0x03, 0x02, 0x03, 0x03, 0x04, 0x02, 0x03, 0x03, 0x04,
0x03, 0x04, 0x04, 0x05, 0x01, 0x02, 0x02, 0x03, 0x02, 0x03, 0x03, 0x04, 0x02, 0x03, 0x03,
Expand All @@ -39,7 +39,7 @@ const (
0x03, 0x04, 0x04, 0x05, 0x04, 0x05, 0x05, 0x06, 0x04, 0x05, 0x05, 0x06, 0x05, 0x06, 0x06,
0x07, 0x03, 0x04, 0x04, 0x05, 0x04, 0x05, 0x05, 0x06, 0x04, 0x05, 0x05, 0x06, 0x05, 0x06,
0x06, 0x07, 0x04, 0x05, 0x05, 0x06, 0x05, 0x06, 0x06, 0x07, 0x05, 0x06, 0x06, 0x07, 0x06,
0x07, 0x07, 0x08]
0x07, 0x07, 0x08]!
rev_8_tab = [u8(0x00), 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0, 0x30,
0xb0, 0x70, 0xf0, 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, 0x18, 0x98, 0x58, 0xd8,
0x38, 0xb8, 0x78, 0xf8, 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, 0x14, 0x94, 0x54,
Expand All @@ -57,7 +57,7 @@ const (
0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b,
0xfb, 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7,
0x77, 0xf7, 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f,
0xbf, 0x7f, 0xff]
0xbf, 0x7f, 0xff]!
len_8_tab = [u8(0x00), 0x01, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
Expand All @@ -75,5 +75,5 @@ const (
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08]
0x08, 0x08, 0x08]!
)
4 changes: 2 additions & 2 deletions vlib/strconv/atofq.c.v
Expand Up @@ -236,7 +236,7 @@ const (
u64(0x7d987706b0213d0a), u64(0x7dce94c85c298c4c), u64(0x7e031cfd3999f7b0),
u64(0x7e37e43c8800759c), u64(0x7e6ddd4baa009303), u64(0x7ea2aa4f4a405be2),
u64(0x7ed754e31cd072da), u64(0x7f0d2a1be4048f90), u64(0x7f423a516e82d9ba),
u64(0x7f76c8e5ca239029), u64(0x7fac7b1f3cac7433), u64(0x7fe1ccf385ebc8a0)]
u64(0x7f76c8e5ca239029), u64(0x7fac7b1f3cac7433), u64(0x7fe1ccf385ebc8a0)]!
// negative exp of 10 binary form
neg_exp = [u64(0x3ff0000000000000), u64(0x3fb999999999999a), u64(0x3f847ae147ae147b),
u64(0x3f50624dd2f1a9fc), u64(0x3f1a36e2eb1c432d), u64(0x3ee4f8b588e368f1),
Expand Down Expand Up @@ -345,5 +345,5 @@ const (
u64(0x0000002f201d49fb), u64(0x00000004b6695433), u64(0x0000000078a42205),
u64(0x000000000c1069cd), u64(0x000000000134d761), u64(0x00000000001ee257),
u64(0x00000000000316a2), u64(0x0000000000004f10), u64(0x00000000000007e8),
u64(0x00000000000000ca), u64(0x0000000000000014), u64(0x0000000000000002)]
u64(0x00000000000000ca), u64(0x0000000000000014), u64(0x0000000000000002)]!
)
2 changes: 1 addition & 1 deletion vlib/strconv/f32_str.c.v
Expand Up @@ -35,7 +35,7 @@ const (
u32(1000000000),
u32(10000000000),
u32(100000000000),
]
]!
)

//=============================================================================
Expand Down
4 changes: 2 additions & 2 deletions vlib/strconv/f64_str.c.v
Expand Up @@ -187,7 +187,7 @@ fn f64_to_decimal(mant u64, exp u64) Dec64 {
k := pow5_inv_num_bits_64 + pow5_bits(int(q)) - 1
i := -e2 + int(q) + k

mul := pow5_inv_split_64[q]
mul := *(&Uint128(&pow5_inv_split_64_x[q * 2]))
vr = mul_shift_64(u64(4) * m2, mul, i)
vp = mul_shift_64(u64(4) * m2 + u64(2), mul, i)
vm = mul_shift_64(u64(4) * m2 - u64(1) - mm_shift, mul, i)
Expand Down Expand Up @@ -215,7 +215,7 @@ fn f64_to_decimal(mant u64, exp u64) Dec64 {
i := -e2 - int(q)
k := pow5_bits(i) - pow5_num_bits_64
j := int(q) - k
mul := pow5_split_64[i]
mul := *(&Uint128(&pow5_split_64_x[i * 2]))
vr = mul_shift_64(u64(4) * m2, mul, j)
vp = mul_shift_64(u64(4) * m2 + u64(2), mul, j)
vm = mul_shift_64(u64(4) * m2 - u64(1) - mm_shift, mul, j)
Expand Down
2 changes: 1 addition & 1 deletion vlib/strconv/f64_str.v
Expand Up @@ -23,7 +23,7 @@ const (
u64(100000000000000000),
u64(1000000000000000000),
u64(10000000000000000000),
]
]!
)

//=============================================================================
Expand Down
2 changes: 1 addition & 1 deletion vlib/strconv/format.v
Expand Up @@ -43,7 +43,7 @@ const (
0.000000000000000005,
0.0000000000000000005,
0.00000000000000000005,
]
]!
)

/*
Expand Down

0 comments on commit 1ed0cd9

Please sign in to comment.