[#32945] Shift_JIS variants and UTF-16 support — "U.Nakamura" <usa@...>

こんにちは、なかむら(う)です。

22 messages 2008/01/07
[#32953] Re: Shift_JIS variants and UTF-16 support — Martin Duerst <duerst@...> 2008/01/07

中村さん、こんにちは。

[#32955] Re: Shift_JIS variants and UTF-16 support — Yukihiro Matsumoto <matz@...> 2008/01/07

まつもと ゆきひろです

[#32959] Re: Shift_JIS variants and UTF-16 support — "NARUSE, Yui" <naruse@...> 2008/01/07

成瀬です。

[#32960] Re: Shift_JIS variants and UTF-16 support — Yukihiro Matsumoto <matz@...> 2008/01/07

まつもと ゆきひろです

[#32992] ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — "NARUSE, Yui" <naruse@...>

成瀬です。

18 messages 2008/01/08
[#32994] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — Yukihiro Matsumoto <matz@...> 2008/01/09

まつもと ゆきひろです

[#32995] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — Martin Duerst <duerst@...> 2008/01/09

At 18:13 08/01/09, Yukihiro Matsumoto wrote:

[#33011] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — "NARUSE, Yui" <naruse@...> 2008/01/11

成瀬です。

[#33012] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — Yukihiro Matsumoto <matz@...> 2008/01/11

まつもと ゆきひろです

[#33014] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — "NARUSE, Yui" <naruse@...> 2008/01/11

成瀬です。

[#33015] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — Yukihiro Matsumoto <matz@...> 2008/01/11

まつもと ゆきひろです

[#33239] Re: [ruby-cvs:22386] Ruby:r15149 (trunk): * string.c (rb_str_each_char): move forward. — Tanaka Akira <akr@...>

In article <200801210259.m0L2x3CW017171@ci.ruby-lang.org>,

11 messages 2008/01/21
[#33240] Re: [ruby-cvs:22386] Ruby:r15149 (trunk): * string.c (rb_str_each_char): move forward. — Nobuyoshi Nakada <nobu@...> 2008/01/21

なかだです。

[#33303] Time#strftimeのエンコーディング — rubikitch@...

るびきちです。

13 messages 2008/01/23
[#33305] Re: Time#strftimeのエンコーディング — Yukihiro Matsumoto <matz@...> 2008/01/23

まつもと ゆきひろです

[#33368] summary of script encoding — "U.Nakamura" <usa@...>

こんにちは、なかむら(う)です。

22 messages 2008/01/25
[#33375] Re: summary of script encoding — Yukihiro Matsumoto <matz@...> 2008/01/25

まつもと ゆきひろです

[#33376] Re: summary of script encoding — "U.Nakamura" <usa@...> 2008/01/25

こんにちは、なかむら(う)です。

[#33387] HashからStructを作る — rubikitch@...

るびきちです。

19 messages 2008/01/25
[#33455] Re: HashからStructを作る — Yukihiro Matsumoto <matz@...> 2008/01/28

まつもと ゆきひろです

[#33505] Re: HashからStructを作る — rubikitch@... 2008/01/29

From: Yukihiro Matsumoto <matz@ruby-lang.org>

[#33507] Re: HashからStructを作る — Yukihiro Matsumoto <matz@...> 2008/01/29

まつもと ゆきひろです

[#33508] Re: HashからStructを作る — rubikitch@... 2008/01/29

From: Yukihiro Matsumoto <matz@ruby-lang.org>

[#33433] Win32OLE: set encoding to OLE string — "U.Nakamura" <usa@...>

こんにちは、なかむら(う)です。

16 messages 2008/01/28

[#33461] Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — MORITA Hideyuki <h-morita@...>

=1B$B?9ED$H?=3D$7$^$9!#=1B(B

19 messages 2008/01/28
[#33473] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — Nobuyoshi Nakada <nobu@...> 2008/01/28

なかだです。

[#33503] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — MORITA Hideyuki <h-morita@...> 2008/01/29

森田です。

[#33514] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — Nobuyoshi Nakada <nobu@...> 2008/01/29

なかだです。

[#33518] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — MORITA Hideyuki <h-morita@...> 2008/01/30

森田です。

[#33545] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — Ryutaro Amano <wn9r-amn@...> 2008/01/31

天野竜太郎と申します。

[#33546] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — MORITA Hideyuki <h-morita@...> 2008/01/31

森田です。

[#33547] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — Ryutaro Amano <wn9r-amn@...> 2008/01/31

天野です。

[#33551] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — MORITA Hideyuki <h-morita@...> 2008/01/31

森田です。

[#33488] 現在の script encoding の値を得る方法は? — Hidetoshi NAGAI <nagai@...>

永井@知能.九工大です.

20 messages 2008/01/29
[#33491] Re: 現在の script encoding の値を得る方法は? — Yukihiro Matsumoto <matz@...> 2008/01/29

まつもと ゆきひろです

[#33500] Re: 現在の script encoding の値を得る方法は? — Hidetoshi NAGAI <nagai@...> 2008/01/29

永井@知能.九工大です.

[#33501] Re: 現在の script encoding の値を得る方法は? — "NARUSE, Yui" <naruse@...> 2008/01/29

成瀬です。

[#33515] Re: 現在の script encoding の値を得る方法は? — Hidetoshi NAGAI <nagai@...> 2008/01/30

永井@知能.九工大です.

[#33516] Re: 現在の script encoding の値を得る方法は? — "NARUSE, Yui" <naruse@...> 2008/01/30

成瀬です。

[#33519] Re: 現在の script encoding の値を得る方法は? — Hidetoshi NAGAI <nagai@...> 2008/01/30

永井@知能.九工大です.

[#33522] Re: 現在の script encoding の値を得る方法は? — "NARUSE, Yui" <naruse@...> 2008/01/30

成瀬です。

[ruby-dev:33139] Bignum#* might invoke GC parallelly?

From: "Yusuke ENDOH" <mame@...>
Date: 2008-01-16 16:13:53 UTC
List: ruby-dev #33139
遠藤と申します。

rb_big_mul や divrem は rb_thread_blocking_region の中で実行されますが、
その中でオブジェクトを生成するため、GC が GVL をロックしない状態で発生
する (下手をすると GC が並列に動作する) 可能性があるような気がしました。

他人事のように言ってますが、rb_thread_blocking_region で実行するように
提案してパッチを書いたのは私です ([ruby-dev:32632]) 。ごめんなさい。

危なそうな例でも落ちたことはないので実は問題ないのかもしれません。でも
少し怖いので、オブジェクトの生成を rb_thread_blocking_region の外で行う
パッチを書いてみました。ご検討ください。

また、FFT を用いた乗算 ([ruby-dev:32629]) のことも検討していただけると
嬉しいです。


Index: bignum.c
===================================================================
--- bignum.c	(revision 15080)
+++ bignum.c	(working copy)
@@ -1449,7 +1449,7 @@
 }

 struct big_mul_struct {
-    VALUE x, y, stop;
+    VALUE x, y, z, stop;
 };

 static VALUE
@@ -1458,11 +1458,10 @@
     struct big_mul_struct *bms = (struct big_mul_struct*)ptr;
     long i, j;
     BDIGIT_DBL n = 0;
-    VALUE x = bms->x, y = bms->y, z;
+    VALUE x = bms->x, y = bms->y, z = bms->z;
     BDIGIT *zds;

     j = RBIGNUM_LEN(x) + RBIGNUM_LEN(y) + 1;
-    z = bignew(j, RBIGNUM_SIGN(x)==RBIGNUM_SIGN(y));
     zds = BDIGITS(z);
     while (j--) zds[j] = 0;
     for (i = 0; i < RBIGNUM_LEN(x); i++) {
@@ -1488,7 +1487,7 @@
 rb_big_mul0(VALUE x, VALUE y)
 {
     struct big_mul_struct bms;
-    VALUE z;
+    volatile VALUE z;

     switch (TYPE(y)) {
       case T_FIXNUM:
@@ -1507,6 +1506,7 @@

     bms.x = x;
     bms.y = y;
+    bms.z = bignew(RBIGNUM_LEN(x) + RBIGNUM_LEN(y),
RBIGNUM_SIGN(x)==RBIGNUM_SIGN(y));
     bms.stop = Qfalse;

     if (RBIGNUM_LEN(x) + RBIGNUM_LEN(y) > 10000) {
@@ -1533,20 +1533,64 @@
 }

 struct big_div_struct {
-    VALUE x, y, *divp, *modp, stop;
+    long nx, ny;
+    BDIGIT *yds, *zds;
+    VALUE stop;
 };

 static VALUE
 bigdivrem1(void *ptr)
 {
     struct big_div_struct *bds = (struct big_div_struct*)ptr;
-    VALUE x = bds->x, y = bds->y, *divp = bds->divp, *modp = bds->modp;
+    long nx = bds->nx, ny = bds->ny;
+    long i, j;
+    BDIGIT *yds = bds->yds, *zds = bds->zds;
+    BDIGIT_DBL_SIGNED num;
+    BDIGIT_DBL t2;
+    BDIGIT q;
+
+    j = nx==ny?nx+1:nx;
+    do {
+	if (bds->stop) return Qnil;
+	if (zds[j] ==  yds[ny-1]) q = BIGRAD-1;
+	else q = (BDIGIT)((BIGUP(zds[j]) + zds[j-1])/yds[ny-1]);
+	if (q) {
+	    i = 0; num = 0; t2 = 0;
+	    do {			/* multiply and subtract */
+		BDIGIT_DBL ee;
+		t2 += (BDIGIT_DBL)yds[i] * q;
+		ee = num - BIGLO(t2);
+		num = (BDIGIT_DBL)zds[j - ny + i] + ee;
+		if (ee) zds[j - ny + i] = BIGLO(num);
+		num = BIGDN(num);
+		t2 = BIGDN(t2);
+	    } while (++i < ny);
+	    num += zds[j - ny + i] - t2;/* borrow from high digit; don't update */
+	    while (num) {		/* "add back" required */
+		i = 0; num = 0; q--;
+		do {
+		    BDIGIT_DBL ee = num + yds[i];
+		    num = (BDIGIT_DBL)zds[j - ny + i] + ee;
+		    if (ee) zds[j - ny + i] = BIGLO(num);
+		    num = BIGDN(num);
+		} while (++i < ny);
+		num--;
+	    }
+	}
+	zds[j] = q;
+    } while (--j >= ny);
+    return Qnil;
+}
+
+static VALUE
+bigdivrem(VALUE x, VALUE y, VALUE *divp, VALUE *modp)
+{
+    struct big_div_struct bds;
     long nx = RBIGNUM_LEN(x), ny = RBIGNUM_LEN(y);
     long i, j;
-    VALUE yy, z;
+    volatile VALUE yy, z;
     BDIGIT *xds, *yds, *zds, *tds;
     BDIGIT_DBL t2;
-    BDIGIT_DBL_SIGNED num;
     BDIGIT dd, q;

     if (BIGZEROP(y)) rb_num_zerodiv();
@@ -1612,36 +1656,18 @@
 	while (j--) zds[j] = xds[j];
     }

-    j = nx==ny?nx+1:nx;
-    do {
-	if (bds->stop) return Qnil;
-	if (zds[j] ==  yds[ny-1]) q = BIGRAD-1;
-	else q = (BDIGIT)((BIGUP(zds[j]) + zds[j-1])/yds[ny-1]);
-	if (q) {
-	    i = 0; num = 0; t2 = 0;
-	    do {			/* multiply and subtract */
-		BDIGIT_DBL ee;
-		t2 += (BDIGIT_DBL)yds[i] * q;
-		ee = num - BIGLO(t2);
-		num = (BDIGIT_DBL)zds[j - ny + i] + ee;
-		if (ee) zds[j - ny + i] = BIGLO(num);
-		num = BIGDN(num);
-		t2 = BIGDN(t2);
-	    } while (++i < ny);
-	    num += zds[j - ny + i] - t2;/* borrow from high digit; don't update */
-	    while (num) {		/* "add back" required */
-		i = 0; num = 0; q--;
-		do {
-		    BDIGIT_DBL ee = num + yds[i];
-		    num = (BDIGIT_DBL)zds[j - ny + i] + ee;
-		    if (ee) zds[j - ny + i] = BIGLO(num);
-		    num = BIGDN(num);
-		} while (++i < ny);
-		num--;
-	    }
-	}
-	zds[j] = q;
-    } while (--j >= ny);
+    bds.nx = nx;
+    bds.ny = ny;
+    bds.zds = zds;
+    bds.yds = yds;
+    bds.stop = Qfalse;
+    if (RBIGNUM_LEN(x) > 10000 || RBIGNUM_LEN(y) > 10000) {
+	z = rb_thread_blocking_region(bigdivrem1, &bds, rb_big_stop, &bds.stop);
+    }
+    else {
+	z = bigdivrem1(&bds);
+    }
+
     if (divp) {			/* move quotient down in z */
 	*divp = rb_big_clone(z);
 	zds = BDIGITS(*divp);
@@ -1665,26 +1691,6 @@
 	RBIGNUM_SET_LEN(*modp, ny);
 	RBIGNUM_SET_SIGN(*modp, RBIGNUM_SIGN(x));
     }
-    return Qnil;
-}
-
-static VALUE
-bigdivrem(VALUE x, VALUE y, VALUE *divp, VALUE *modp)
-{
-    struct big_div_struct bds;
-    VALUE z;
-
-    bds.x = x;
-    bds.y = y;
-    bds.divp = divp;
-    bds.modp = modp;
-    bds.stop = Qfalse;
-    if (RBIGNUM_LEN(x) > 10000 || RBIGNUM_LEN(y) > 10000) {
-	z = rb_thread_blocking_region(bigdivrem1, &bds, rb_big_stop, &bds.stop);
-    }
-    else {
-	z = bigdivrem1(&bds);
-    }
     return z;
 }


-- 
Yusuke ENDOH <mame@tsg.ne.jp>

In This Thread

Prev Next