diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-08-20 16:57:33 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-08-21 15:25:58 +0900 |
| commit | 36632f55f418bd711112b72d7fe1b6b1745058e5 (patch) | |
| tree | 30a9a0e83fced5759b5da8f2354b7ba02280e2b8 /src | |
| parent | 4ea80913c27264df0c7088367109c5a0678879f1 (diff) | |
| download | mruby-36632f55f418bd711112b72d7fe1b6b1745058e5.tar.gz mruby-36632f55f418bd711112b72d7fe1b6b1745058e5.zip | |
boxing_word.h: embed `mrb_float` in `mrb_value` if possible.
Embedding reduce memory consumption, sacrificing precision. It clips least
significant 2 bits from `mrb_float`, so if you need to keep float precision,
define `MRB_USE_FLOAT_FULL_PRECISION`.
`MRB_WORD_BOXING` and `MRB_INT64`:
`mrb_float` (`double`) is embedded in `mrb_value` clipped last 2 bits.
`MRB_WORD_BOXING` and `MRB_INT64` and `MRB_USE_FLOAT_FULL_PRECISION`:
`mrb_float` is allocated in the heaps wrapped by `struct RFloat`.
`MRB_WORD_BOXING` and `MRB_INT32` and `MRB_USE_FLOAT32`:
`mrb_float` (`float`) is embedded in `mrb_value` clipped last 2 bits.
In addition, to reserve bit space in the `mrb_value`, maximum inline
symbol length become 4 (instead of 5) in the configuration.
`MRB_WORD_BOXING` and `MRB_INT32`:
Assume `MRB_USE_FLOAT_FULL_PRECISION` and allocate Float values in heap.
Diffstat (limited to 'src')
| -rw-r--r-- | src/etc.c | 17 | ||||
| -rw-r--r-- | src/symbol.c | 4 |
2 files changed, 21 insertions, 0 deletions
@@ -158,11 +158,28 @@ mrb_word_boxing_float_value(mrb_state *mrb, mrb_float f) { union mrb_value_ v; +#ifndef MRB_USE_FLOAT_FULL_PRECISION + v.f = f; + v.w = (v.w & ~3) | 2; +#else v.p = mrb_obj_alloc(mrb, MRB_TT_FLOAT, mrb->float_class); v.fp->f = f; MRB_SET_FROZEN_FLAG(v.bp); +#endif return v.value; } + + +#ifndef MRB_USE_FLOAT_FULL_PRECISION +MRB_API mrb_float +mrb_word_boxing_value_float(mrb_value v) +{ + union mrb_value_ u; + u.value = v; + u.w = u.w & ~3; + return u.f; +} +#endif #endif /* MRB_NO_FLOAT */ MRB_API mrb_value diff --git a/src/symbol.c b/src/symbol.c index 9d68b5cf3..dbdeca459 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -73,7 +73,11 @@ static const char pack_table[] = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRS static mrb_sym sym_inline_pack(const char *name, size_t len) { +#if defined(MRB_WORD_BOXING) && defined(MRB_32BIT) && !defined(MRB_USE_FLOAT_FULL_PRECISION) + const size_t pack_length_max = 4; +#else const size_t pack_length_max = 5; +#endif char c; const char *p; |
