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

ruby-changes:30963

From: nobu <ko1@a...>
Date: Wed, 25 Sep 2013 16:58:56 +0900 (JST)
Subject: [ruby-changes:30963] nobu:r43042 (trunk): internal.h: move inline functions

nobu	2013-09-25 16:58:49 +0900 (Wed, 25 Sep 2013)

  New Revision: 43042

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

  Log:
    internal.h: move inline functions
    
    * internal.h (rb_float_value, rb_float_new): move inline functions
      from ruby/ruby.h.
    * numeric.c (rb_float_value, rb_float_new): define external functions
      for extension libraries.

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/ruby.h
    trunk/internal.h
    trunk/numeric.c
Index: include/ruby/ruby.h
===================================================================
--- include/ruby/ruby.h	(revision 43041)
+++ include/ruby/ruby.h	(revision 43042)
@@ -805,85 +805,10 @@ struct RFloat { https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L805
     double float_value;
 };
 
+double rb_float_value(VALUE);
+VALUE rb_float_new(double);
 VALUE rb_float_new_in_heap(double);
 
-#if USE_FLONUM
-#define RUBY_BIT_ROTL(v, n) (((v) << (n)) | ((v) >> ((sizeof(v) * 8) - n)))
-#define RUBY_BIT_ROTR(v, n) (((v) >> (n)) | ((v) << ((sizeof(v) * 8) - n)))
-
-static inline double
-rb_float_value(VALUE v)
-{
-    if (FLONUM_P(v)) {
-	if (v != (VALUE)0x8000000000000002) { /* LIKELY */
-	    union {
-		double d;
-		VALUE v;
-	    } t;
-
-	    VALUE b63 = (v >> 63);
-	    /* e: xx1... -> 011... */
-	    /*    xx0... -> 100... */
-	    /*      ^b63           */
-	    t.v = RUBY_BIT_ROTR((2 - b63) | (v & ~0x03), 3);
-	    return t.d;
-	}
-	else {
-	    return 0.0;
-	}
-    }
-    else {
-	return ((struct RFloat *)v)->float_value;
-    }
-}
-
-static inline VALUE
-rb_float_new(double d)
-{
-    union {
-	double d;
-	VALUE v;
-    } t;
-    int bits;
-
-    t.d = d;
-    bits = (int)((VALUE)(t.v >> 60) & 0x7);
-    /* bits contains 3 bits of b62..b60. */
-    /* bits - 3 = */
-    /*   b011 -> b000 */
-    /*   b100 -> b001 */
-
-    if (t.v != 0x3000000000000000 /* 1.72723e-77 */ &&
-	!((bits-3) & ~0x01)) {
-	return (RUBY_BIT_ROTL(t.v, 3) & ~(VALUE)0x01) | 0x02;
-    }
-    else {
-	if (t.v == (VALUE)0) {
-	    /* +0.0 */
-	    return 0x8000000000000002;
-	}
-	else {
-	    /* out of range */
-	    return rb_float_new_in_heap(d);
-	}
-    }
-}
-
-#else /* USE_FLONUM */
-
-static inline double
-rb_float_value(VALUE v)
-{
-    return ((struct RFloat *)v)->float_value;
-}
-
-static inline VALUE
-rb_float_new(double d)
-{
-    return rb_float_new_in_heap(d);
-}
-#endif
-
 #define RFLOAT_VALUE(v) rb_float_value(v)
 #define DBL2NUM(dbl)  rb_float_new(dbl)
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43041)
+++ ChangeLog	(revision 43042)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Sep 25 16:58:33 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* internal.h (rb_float_value, rb_float_new): move inline functions
+	  from ruby/ruby.h.
+
+	* numeric.c (rb_float_value, rb_float_new): define external functions
+	  for extension libraries.
+
 Wed Sep 25 15:37:02 2013  Koichi Sasada  <ko1@a...>
 
 	* test/rdoc/test_rdoc_generator_darkfish.rb: add a guard for windows.
Index: numeric.c
===================================================================
--- numeric.c	(revision 43041)
+++ numeric.c	(revision 43042)
@@ -4063,3 +4063,17 @@ Init_Numeric(void) https://github.com/ruby/ruby/blob/trunk/numeric.c#L4063
     sym_to = ID2SYM(rb_intern("to"));
     sym_by = ID2SYM(rb_intern("by"));
 }
+
+#undef rb_float_value
+double
+rb_float_value(VALUE v)
+{
+    return rb_float_value_inline(v);
+}
+
+#undef rb_float_new
+VALUE
+rb_float_new(double d)
+{
+    return rb_float_new_inline(d);
+}
Index: internal.h
===================================================================
--- internal.h	(revision 43041)
+++ internal.h	(revision 43042)
@@ -478,6 +478,70 @@ int rb_num_negative_p(VALUE); https://github.com/ruby/ruby/blob/trunk/internal.h#L478
 VALUE rb_int_succ(VALUE num);
 VALUE rb_int_pred(VALUE num);
 
+#if USE_FLONUM
+#define RUBY_BIT_ROTL(v, n) (((v) << (n)) | ((v) >> ((sizeof(v) * 8) - n)))
+#define RUBY_BIT_ROTR(v, n) (((v) >> (n)) | ((v) << ((sizeof(v) * 8) - n)))
+#endif
+
+static inline double
+rb_float_value_inline(VALUE v)
+{
+#if USE_FLONUM
+    if (FLONUM_P(v)) {
+	if (v != (VALUE)0x8000000000000002) { /* LIKELY */
+	    union {
+		double d;
+		VALUE v;
+	    } t;
+
+	    VALUE b63 = (v >> 63);
+	    /* e: xx1... -> 011... */
+	    /*    xx0... -> 100... */
+	    /*      ^b63           */
+	    t.v = RUBY_BIT_ROTR((2 - b63) | (v & ~0x03), 3);
+	    return t.d;
+	}
+	else {
+	    return 0.0;
+	}
+    }
+#endif
+    return ((struct RFloat *)v)->float_value;
+}
+
+static inline VALUE
+rb_float_new_inline(double d)
+{
+#if USE_FLONUM
+    union {
+	double d;
+	VALUE v;
+    } t;
+    int bits;
+
+    t.d = d;
+    bits = (int)((VALUE)(t.v >> 60) & 0x7);
+    /* bits contains 3 bits of b62..b60. */
+    /* bits - 3 = */
+    /*   b011 -> b000 */
+    /*   b100 -> b001 */
+
+    if (t.v != 0x3000000000000000 /* 1.72723e-77 */ &&
+	!((bits-3) & ~0x01)) {
+	return (RUBY_BIT_ROTL(t.v, 3) & ~(VALUE)0x01) | 0x02;
+    }
+    else if (t.v == (VALUE)0) {
+	/* +0.0 */
+	return 0x8000000000000002;
+    }
+    /* out of range */
+#endif
+    return rb_float_new_in_heap(d);
+}
+
+#define rb_float_value(v) rb_float_value_inline(v)
+#define rb_float_new(d)   rb_float_new_inline(d)
+
 /* object.c */
 VALUE rb_obj_equal(VALUE obj1, VALUE obj2);
 

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

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