Skip to content

Commit 78d8059

Browse files
committed
Use @(rodata) where possible
1 parent bf43dba commit 78d8059

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

core/math/big/internal.odin

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2791,7 +2791,8 @@ internal_int_count_lsb :: proc(a: ^Int) -> (count: int, err: Error) {
27912791
x *= _DIGIT_BITS
27922792
x += internal_count_lsb(q)
27932793
} else {
2794-
lnz := []int{
2794+
@(static, rodata)
2795+
lnz := [?]int{
27952796
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
27962797
}
27972798

core/math/big/prime.odin

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ internal_int_kronecker :: proc(a, p: ^Int, allocator := context.allocator) -> (k
134134
a1, p1, r := &Int{}, &Int{}, &Int{}
135135
defer internal_destroy(a1, p1, r)
136136

137-
table := []int{0, 1, 0, -1, 0, -1, 0, 1}
137+
@(static, rodata)
138+
table := [?]int{0, 1, 0, -1, 0, -1, 0, 1}
138139

139140
if internal_int_is_zero(p) {
140141
if a.used == 1 && a.digit[0] == 1 {

core/math/big/private.odin

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3217,6 +3217,7 @@ _private_int_shr_leg :: proc(quotient: ^Int, digits: int, allocator := context.a
32173217
Tables used by `internal_*` and `_*`.
32183218
*/
32193219

3220+
@(rodata)
32203221
_private_int_rem_128 := [?]DIGIT{
32213222
0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
32223223
0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
@@ -3229,6 +3230,7 @@ _private_int_rem_128 := [?]DIGIT{
32293230
}
32303231
#assert(128 * size_of(DIGIT) == size_of(_private_int_rem_128))
32313232

3233+
@(rodata)
32323234
_private_int_rem_105 := [?]DIGIT{
32333235
0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
32343236
0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1,
@@ -3241,6 +3243,7 @@ _private_int_rem_105 := [?]DIGIT{
32413243
#assert(105 * size_of(DIGIT) == size_of(_private_int_rem_105))
32423244

32433245
_PRIME_TAB_SIZE :: 256
3246+
@(rodata)
32443247
_private_prime_table := [_PRIME_TAB_SIZE]DIGIT{
32453248
0x0002, 0x0003, 0x0005, 0x0007, 0x000B, 0x000D, 0x0011, 0x0013,
32463249
0x0017, 0x001D, 0x001F, 0x0025, 0x0029, 0x002B, 0x002F, 0x0035,
@@ -3281,6 +3284,7 @@ _private_prime_table := [_PRIME_TAB_SIZE]DIGIT{
32813284
#assert(_PRIME_TAB_SIZE * size_of(DIGIT) == size_of(_private_prime_table))
32823285

32833286
when MATH_BIG_FORCE_64_BIT || (!MATH_BIG_FORCE_32_BIT && size_of(rawptr) == 8) {
3287+
@(rodata)
32843288
_factorial_table := [35]_WORD{
32853289
/* f(00): */ 1,
32863290
/* f(01): */ 1,
@@ -3319,6 +3323,7 @@ when MATH_BIG_FORCE_64_BIT || (!MATH_BIG_FORCE_32_BIT && size_of(rawptr) == 8) {
33193323
/* f(34): */ 295_232_799_039_604_140_847_618_609_643_520_000_000,
33203324
}
33213325
} else {
3326+
@(rodata)
33223327
_factorial_table := [21]_WORD{
33233328
/* f(00): */ 1,
33243329
/* f(01): */ 1,

core/math/big/radix.odin

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,7 @@ radix_size :: proc(a: ^Int, radix: i8, zero_terminate := false, allocator := con
357357
internal_set(la, bit_count) or_return
358358

359359
/* k = floor(2^29/log_2(radix)) + 1 */
360-
lb := _log_bases
361-
internal_set(k, lb[radix]) or_return
360+
internal_set(k, _log_bases[radix]) or_return
362361

363362
/* n = floor((la * k) / 2^29) + 1 */
364363
internal_mul(k, la, k) or_return
@@ -564,8 +563,9 @@ internal_int_unpack :: proc(a: ^Int, buf: []$T, nails := 0, order := Order.LSB_F
564563
*/
565564

566565
_RADIX_SIZE_SCALE :: 29
567-
_log_bases :: [65]u32{
568-
0, 0, 0x20000001, 0x14309399, 0x10000001,
566+
@(rodata)
567+
_log_bases := [65]u32{
568+
0, 0, 0x20000001, 0x14309399, 0x10000001,
569569
0xdc81a35, 0xc611924, 0xb660c9e, 0xaaaaaab, 0xa1849cd,
570570
0x9a209a9, 0x94004e1, 0x8ed19c2, 0x8a5ca7d, 0x867a000,
571571
0x830cee3, 0x8000001, 0x7d42d60, 0x7ac8b32, 0x7887847,
@@ -584,6 +584,7 @@ _log_bases :: [65]u32{
584584
Characters used in radix conversions.
585585
*/
586586
RADIX_TABLE := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/"
587+
@(rodata)
587588
RADIX_TABLE_REVERSE := [RADIX_TABLE_REVERSE_SIZE]u8{
588589
0x3e, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x01, 0x02, 0x03, 0x04, /* +,-./01234 */
589590
0x05, 0x06, 0x07, 0x08, 0x09, 0xff, 0xff, 0xff, 0xff, 0xff, /* 56789:;<=> */

0 commit comments

Comments
 (0)