[前][次][番号順一覧][スレッド一覧]

ruby-changes:32483

From: nobu <ko1@a...>
Date: Sun, 12 Jan 2014 09:21:44 +0900 (JST)
Subject: [ruby-changes:32483] nobu:r44562 (trunk): ruby/util.h: DECIMAL_SIZE_OF_BITS

nobu	2014-01-12 09:21:37 +0900 (Sun, 12 Jan 2014)

  New Revision: 44562

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44562

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/common.mk
    trunk/ext/bigdecimal/bigdecimal.c
    trunk/ext/bigdecimal/depend
    trunk/include/ruby/util.h
    trunk/iseq.c
Index: include/ruby/util.h
===================================================================
--- include/ruby/util.h	(revision 44561)
+++ include/ruby/util.h	(revision 44562)
@@ -47,6 +47,9 @@ extern "C" { https://github.com/ruby/ruby/blob/trunk/include/ruby/util.h#L47
 
 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)))
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44561)
+++ ChangeLog	(revision 44562)
@@ -1,3 +1,17 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Jan 12 09:21:35 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@g...>
 
 	* vm_exec.c (cfp): Avoid generating invalid binary for
Index: iseq.c
===================================================================
--- iseq.c	(revision 44561)
+++ iseq.c	(revision 44562)
@@ -10,6 +10,7 @@ https://github.com/ruby/ruby/blob/trunk/iseq.c#L10
 **********************************************************************/
 
 #include "ruby/ruby.h"
+#include "ruby/util.h"
 #include "internal.h"
 #include "eval_intern.h"
 
@@ -1612,7 +1613,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/iseq.c#L1613
 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));
Index: common.mk
===================================================================
--- common.mk	(revision 44561)
+++ common.mk	(revision 44562)
@@ -786,7 +786,9 @@ compile.$(OBJEXT): {$(VPATH)}compile.c { https://github.com/ruby/ruby/blob/trunk/common.mk#L786
   {$(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 \
Index: ext/bigdecimal/depend
===================================================================
--- ext/bigdecimal/depend	(revision 44561)
+++ ext/bigdecimal/depend	(revision 44562)
@@ -1 +1 @@
-bigdecimal.o: bigdecimal.c bigdecimal.h $(HDRS) $(ruby_headers)
+bigdecimal.o: bigdecimal.c bigdecimal.h $(HDRS) $(ruby_headers) $(hdrdir)/ruby/util.h
Index: ext/bigdecimal/bigdecimal.c
===================================================================
--- ext/bigdecimal/bigdecimal.c	(revision 44561)
+++ ext/bigdecimal/bigdecimal.c	(revision 44562)
@@ -18,6 +18,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L18
 # 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: https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L2920
     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);
     }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]