summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-12 00:21:37 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-12 00:21:37 +0000
commit5e9b7bacc3731b909ea6341d7158ef6b34e09f2d (patch)
tree13de30bb8713467ef344ade2c58ed34afe4baa0e
parent0e9cad9a8e25282be170d3e4240bd2ba6ce1a419 (diff)
ruby/util.h: DECIMAL_SIZE_OF_BITS
* include/ruby/util.h (DECIMAL_SIZE_OF_BITS): a preprocessor constant macro to approximate decimal representation size of n-bits integer. * iseq.c (register_label): use DECIMAL_SIZE_OF_BITS for better approximation. * ext/bigdecimal/bigdecimal.c (BigMath_s_log): ditto. * common.mk (iseq.o), ext/bigdecimal/depend (bigdecimal.o): add dependency to ruby/util.h for DECIMAL_SIZE_OF_BITS. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44562 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog14
-rw-r--r--common.mk4
-rw-r--r--ext/bigdecimal/bigdecimal.c3
-rw-r--r--ext/bigdecimal/depend2
-rw-r--r--include/ruby/util.h3
-rw-r--r--iseq.c3
6 files changed, 25 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 6845924348b..7efa712e90e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+Sun Jan 12 09:21:35 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * include/ruby/util.h (DECIMAL_SIZE_OF_BITS): a preprocessor
+ constant macro to approximate decimal representation size of n-bits
+ integer.
+
+ * iseq.c (register_label): use DECIMAL_SIZE_OF_BITS for better
+ approximation.
+
+ * ext/bigdecimal/bigdecimal.c (BigMath_s_log): ditto.
+
+ * common.mk (iseq.o), ext/bigdecimal/depend (bigdecimal.o): add
+ dependency to ruby/util.h for DECIMAL_SIZE_OF_BITS.
+
Fri Jan 10 16:27:20 2014 Yuki Yugui Sonoda <yugui@google.com>
* vm_exec.c (cfp): Avoid generating invalid binary for
diff --git a/common.mk b/common.mk
index f30df0fee0f..4f081c24f9a 100644
--- a/common.mk
+++ b/common.mk
@@ -786,7 +786,9 @@ compile.$(OBJEXT): {$(VPATH)}compile.c {$(VPATH)}iseq.h \
{$(VPATH)}internal.h {$(VPATH)}vm_opts.h
iseq.$(OBJEXT): {$(VPATH)}iseq.c {$(VPATH)}gc.h {$(VPATH)}iseq.h \
$(RUBY_H_INCLUDES) $(VM_CORE_H_INCLUDES) {$(VPATH)}insns.inc \
- {$(VPATH)}insns_info.inc {$(VPATH)}node_name.inc {$(VPATH)}internal.h {$(VPATH)}vm_opts.h {$(VPATH)}ruby_atomic.h {$(VPATH)}eval_intern.h
+ {$(VPATH)}insns_info.inc {$(VPATH)}node_name.inc {$(VPATH)}internal.h \
+ {$(VPATH)}vm_opts.h {$(VPATH)}ruby_atomic.h {$(VPATH)}eval_intern.h \
+ {$(VPATH)}util.h
vm.$(OBJEXT): {$(VPATH)}vm.c {$(VPATH)}gc.h {$(VPATH)}iseq.h \
{$(VPATH)}eval_intern.h $(RUBY_H_INCLUDES) $(ENCODING_H_INCLUDES) \
$(VM_CORE_H_INCLUDES) {$(VPATH)}vm_method.c {$(VPATH)}vm_eval.c \
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index c5a3326fb7a..16fba2211ff 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -18,6 +18,7 @@
# define BIGDECIMAL_ENABLE_VPRINT 1
#endif
#include "bigdecimal.h"
+#include "ruby/util.h"
#ifndef BIGDECIMAL_DEBUG
# define NDEBUG
@@ -2919,7 +2920,7 @@ get_vp_value:
RB_GC_GUARD(vn) = SSIZET2NUM(n);
expo = VpExponent10(vx);
if (expo < 0 || expo >= 3) {
- char buf[SIZEOF_VALUE * CHAR_BIT / 3 + 4];
+ char buf[DECIMAL_SIZE_OF_BITS(SIZEOF_VALUE * CHAR_BIT) + 4];
snprintf(buf, sizeof(buf), "1E%"PRIdVALUE, -expo);
x = BigDecimal_mult2(x, ToValue(VpCreateRbObject(1, buf)), vn);
}
diff --git a/ext/bigdecimal/depend b/ext/bigdecimal/depend
index a68128478c4..0a83c1f17fb 100644
--- a/ext/bigdecimal/depend
+++ b/ext/bigdecimal/depend
@@ -1 +1 @@
-bigdecimal.o: bigdecimal.c bigdecimal.h $(HDRS) $(ruby_headers)
+bigdecimal.o: bigdecimal.c bigdecimal.h $(HDRS) $(ruby_headers) $(hdrdir)/ruby/util.h
diff --git a/include/ruby/util.h b/include/ruby/util.h
index 5be5f2e0b42..8443af74d99 100644
--- a/include/ruby/util.h
+++ b/include/ruby/util.h
@@ -47,6 +47,9 @@ extern "C" {
RUBY_SYMBOL_EXPORT_BEGIN
+#define DECIMAL_SIZE_OF_BITS(n) (((n) * 3010 + 9998) / 9999)
+/* an approximation of ceil(n * log10(2)), upto 65536 at least */
+
#define scan_oct(s,l,e) ((int)ruby_scan_oct((s),(l),(e)))
unsigned long ruby_scan_oct(const char *, size_t, size_t *);
#define scan_hex(s,l,e) ((int)ruby_scan_hex((s),(l),(e)))
diff --git a/iseq.c b/iseq.c
index a829089ea4d..befa0364dcf 100644
--- a/iseq.c
+++ b/iseq.c
@@ -10,6 +10,7 @@
**********************************************************************/
#include "ruby/ruby.h"
+#include "ruby/util.h"
#include "internal.h"
#include "eval_intern.h"
@@ -1612,7 +1613,7 @@ static VALUE
register_label(struct st_table *table, unsigned long idx)
{
VALUE sym;
- char buff[8 + (sizeof(idx) * CHAR_BIT * 32 / 100)];
+ char buff[7 + DECIMAL_SIZE_OF_BITS(sizeof(idx) * CHAR_BIT)];
snprintf(buff, sizeof(buff), "label_%lu", idx);
sym = ID2SYM(rb_intern(buff));