ときどきの雑記帖 倒行逆施編

最新ページへのリンク
目次ページへのリンク

一つ前へ 2015年9月(下旬)
一つ後へ 2015年10月(中旬)

ホームへ

2015年10月10日

■_

本文を読み比べてはいないんだけど、なんで Open Source: Billions Upon Billions Of Free - ReadWrite というタイトルが オープンソース: 多大なリソースの上に成り立つフリーソフト | ReadWrite Japan こーなるの?

■_

■_

A Language is More Than A Language - Google Slides についての A Language Is More Than a Language | Hacker News で、 Don't like Java? Try COBOL. Then you will like Java. というコメントがあってヤヤウケ。

2015年10月09日

■_

不安がキタキツネ。

■_

■_

PDP-10 用 FORTH (Tenth) のつづき。 の前にちょっと寄り道。 PDP-10アセンブラ・命令解説書



■  浮動小数点演算について 
不動小数点は36ビットの1ワードで次のように表現されます。 
 0 00000000 011111111112222222222333333 
 0 12345678 901234567890123456789012345 
 ______________________________________
| |       |                            |
|S| EXP   |     Fraction               |
|_|_______|____________________________|
もし、Sが0ならば、符号は正です。もし、Sが1ならば、符号は負で、ワード全体は2の補数になってい 
ます。小数(Fraction)は、ビット8と9の間に小数点があるものとして解釈されます。指数は、 
2を底とする指数として表現され、200(8進数)を越します。 
 
???不明 
 
普通の浮動小数点数では、ビット9はビット0とは違う値です。ただし、負の数で、ビット10から35ま 
でが全て0の場合、ビット0と9はともに1となります。浮動小数点数の0は、ワードの全ビットが0とし 
て表現されます。浮動小数点数は、絶対値が 0.5*2^-128 から、(1-2^-27)*2^127 までの数と、0を表 
現できます。 
ビット0が1で、ビット9から35が0の数は、全ての浮動小数点演算命令で、間違った答えを出す可能性 
があります。小数が0で、指数が0でないワードは、浮動小数点加算、減算命令のオペランドとして使われ 
ると、極度に正確性を欠く恐れがあります。

指数は、 2を底とする指数として表現され、200(8進数)を越します。 の、「越します」ってなんじゃいと原文らしきものに当たってみると

PDP-10 Floating-Point

Floating Point Arithmetic 
Single precision floating point numbers are represented in one 36 bit word as follows: 
 
 0 00000000 011111111112222222222333333 
 0 12345678 901234567890123456789012345 
 ______________________________________ 
| |       |                            |
|S| EXP   |     Fraction               |
|_|_______|____________________________|

If S is zero, the sign is positive. If S is one the sign is negative and the word is in twos complement format. The fraction is interpreted as having a binary point between bits 8 and 9. The exponent is an exponent of 2 represented in excess 200 (octal) notation. In a normalized floating point number bit 9 is different from bit 0, except in a negative number bits 0 and 9 may both be one if bits 10:35 are all zero. A floating point zero is represented by a word with 36 bits of zero. Floating point numbers can represent numbers with magnitude within the range 0.5*2^|-128 to (1-2^|-27)*2^|127, and zero.

A number that in which bit 0 is one and bits 9-35 are zero can produce an incorrect result in any floating point operation. Any word with a zero fraction and non-zero exponent can produce extreme loss of precision if used as an operand in a floating point addition or subtraction.

In KI10 (and KL10) double precision floating point, a second word is included which contains in bits 1:35 an additional 35 fraction bits. The additional fraction bits do not significantly affect the range of representable numbers, rather they extend the precision.

The KA10 lacks double precision floating point hardware, however there are several instructions by which software may implement double precision. These instructions are DFN, UFA, FADL, FSBL, FMPL, and FDVL. Users of the KL10 are strongly advised to avoid using these intructions.

In the PDP-6 floating pointing is somewhat different. Consult a wizard.

あー、The exponent is an exponent of 2 represented in excess 200 (octal) notation. の excess を動詞だと取っちゃったのね。 → 符号付数値表現 - Wikipedia

このあとの 普通の浮動小数点数では、 からもおかしいね。 normalized floating point number は「正規化された浮動小数点数」てところでしょう。 number bit 9 ~ 以下は浮動小数点数のフォーマットの詳細がわからないと 何ともいえない部分があるかなあ。 正の数(符号ビットが0)のときは、仮数部で「ケチビット」使っていないのであれば bit0(符号ビット)とbit9(仮数部の最上位ビット)が常に違うというのは納得。

んで、負の数の場合でさらに……あ、こういうこと? 負の数ではbit0(符号ビット)とbit9(仮数部の最上位ビット)は「同じ(どちらも1)」なんだけど、 bit10からbit35がすべて0の場合は 仮数部を正規化してもその最上位ビットは符号ビットと違う値になる。と。 んでも、正規化してない数ではないとしたらそれはどんな数値だろう? ゼロそのものは符号ビット、指数部、仮数部がすべて0で表すわけだから、 仮数部がオール0で符号ビットが1(そして指数部は don't care) なものって? よくわからんなー

Floating-Point FormatsThe PDP-10 (and its compatible relatives, the PDP-6 and the DECSYSTEM-20) and the Xerox Sigma computers (which, like the System/360, also used a hexadecimal exponent), which both used two's complement notation for integers, performed a two's complement on the combined exponent and mantissa fields of a floating-point number when it was negative. This meant that all normalized floating-point numbers, whether they were positive or negative, could be compared by integer compare instructions, producing correct results. を読み解けばいいのかな。 でも面倒なので後にする。

さて、他の部分にもこの種の間違いはありそうだけど 報告すべきか否か……

■_

んで Tenth のほう。

tenth/tenth.s at master · aap/tenth

X=14  # pointer into code/parameter field 
PC=15 # the interpreter's program counter 
PP=16 # parameter stack pointer 
P=17  # return stack pointe

ソースコード冒頭のこれ↑、八進表記でのレジスター番号ってことでいいのかな。

tenth/tenth.s at master · aap/tenth

APR=0 
CTYIN=32 
CTYOUT=33 
 
PDLLEN=100 
PDL: .=.+PDLLEN 
PPDL: .=.+PDLLEN 
RSP: -PDLLEN,,PDL-1 
PSP: -PDLLEN,,PPDL-1 
INP: 0 
INBUF: 0; .=.+40 
INBUFBP: 440700,,INBUF+1 
WORDBUF: 0; .=.+10 
WORDBUFBP: 440700,,WORDBUF+1 
 
START: 
	SETZM	CTYIN 
	MOVE	P,RSP 
	MOVE	PP,PSP
	MOVEI	PC,{ _QUIT } 
	JRST	NEXT

んと、最初の命令三つはおいといて、 (プロセッサーの、ではなくインタープリターの) PC に __QUIT 番地をセットして NEXT 番地へ飛ぶ。かな。

tenth/tenth.s at master · aap/tenth

__QUIT: __INTERPRET; 0,,4; ASCII "QUIT" 
_QUIT:	DOCOL 
	{ ASM; MOVE P,RSP; JRST NEXT } 
	_INTERPRET 
	_BRANCH 
	-2 
 
__ABORT: __QUIT; 0,,5; ASCII "ABORT" 
_ABORT: DOCOL 
	{ ASM; MOVE PP,PSP; JRST NEXT } 
	_QUIT

お、いかにもFORTHっぽい構造が。

ソースコードでは順番が逆だけど _INTERPRET へ

tenth/tenth.s at master · aap/tenth

__INTERPRET: __EXIT; 0,,9; ASCII "INTERPRET" 
_INTERPRET: ASM 
	SKIPN	INBUF
	PUSHJ	P,GETS
NEXTW:	MOVEI	0,40	# space
	PUSH	PP,0
	PUSHJ	P,PARSEWORD
	JRST	OK	# end of line
	MOVEI	1,WORDBUF
	PUSHJ	P,FIND
	JRST	NUMBER
	HLR	X,1(1)	# get flags
	PUSHJ	P,TCFA
	JUMPN	X,.+3	# immediate
	SKIPE	STATE
	JRST	COMPW	# compile word
	MOVE	X,1	# interpret word
	MOVE	1,(X)
	JRST	(1)
COMPW:	MOVE	2,HERE
	MOVEM	1,(2)
	AOS	HERE
	JRST	NEXTW
NUMBER:	MOVEI	1,WORDBUF
	PUSHJ	P,CHECKNUM
	JRST	PANIC
	SKIPE	STATE
	JRST	COMPN	# compile number
	PUSH	PP,0	# interpret number
	JRST	NEXTW
COMPN:	MOVE	1,HERE
	MOVEI	2,_LITERAL
	MOVEM	2,(1)
	MOVEM	0,1(1)
	AOS	HERE
	AOS	HERE
	JRST	NEXTW
OK:	SKIPE	STATE
	JRST	.+3
	MOVEI	0,{ASCII "	ok\n\0"}
	JRST	.+2
	MOVEI	0,{ASCII "	compiled\n\0"}
	PUSHJ	P,PUTS
	JRST	NEXTW-1
 

んー、オペランドに出てくる生の数字はレジスタ番号?

2015年10月08日

■_

久しぶりにヤングジャンプ購入。 続けては買わない。たぶん。

Perl5 と Perl6 の違い。 Perl6::Perl5::Differences

■_

■_

11じゃなくて10の方か。 A simple bare-metal forth for the PDP-10 | Hacker News

aap/tenth

Tenth 
 
A simple bare-metal forth for PDP-10 

Why? 

Ever since I got to play with Jörg Hoppe's awesome KI10 front panel at the VCFB 2014 I wanted to do something with the PDP-10. To have something to show at the VCFB 2015 I wrote a simple assembler and started to write some basic console IO functions. I began to really like the instruction set and started porting my very primitive PDP-11 forth. Since this time I used an assembler it was much faster to modify the code and I got the basics working in time for the VCFB. The next few days after the VCFB I extended it a bit to make it presentable. I used jonesforth as a guide or inspiration for some things but the main code was written independently.

ソースコードの、内部インタプリターの辺りを眺めてみる。 tenth/tenth.s at master · aap/tenth

tenth/tenth.s at master · aap/tenth
 
# 
# forth things 
# 
 
# Code field values 
ASM: 
	AOS X 
	JRST (X) 
	
DOCON: 
	AOS X 
	MOVE 0,(X) 
	PUSH PP,0 
	JRST NEXT 
	
DOVAR: 
	AOS X 
	PUSH PP,X 
	JRST NEXT 
	
DOCOL: 
	AOS X 
	PUSH P,PC 
	MOVE PC,X 
	JRST NEXT 
	
# counterpart of DOCOL 
__EXIT: 0; 0,,4; ASCII "EXIT" 
_EXIT: ASM 
	POP P,PC 
	JRST NEXT 
	
# execute forth word at PC and increment PC 
NEXT: MOVE X,(PC) 
	AOS PC 
	MOVE 1,(X) 
	JRST (1) 

ふむ。正確な動作が分からない命令がいくつかあるけど 雰囲気は分かるなw PDP-10 - Wikipedia PDP-10アセンブラ・命令解説書

2015年10月07日

■_

光学ドライブ内蔵しないでいいんだけどなー○| ̄|_ パナソニック、レッツノートSZ5で見せた軽量化への追求 ~ネジ1本にも拘った1g単位の調整の積み重ね - PC Watch 光学ドライブ搭載12.1型で世界最軽量の「レッツノートSZ5」 ~他のシリーズはSkylake/Windows 10搭載に - PC Watch ニュース - パナソニック、929グラムのレッツノート新製品を発表会で披露:ITpro

まだこない。>learn c the hard way

そろそろ順番が回ってくる頃じゃなかったかと思って確認してみたら まだ一か月くらいあった○| ̄|_ >東京駅100周年記念SUICA

■_

■_

本の虫: Sarah Sharp、Linuxカーネルコミュニティの暴力性に嫌気がさして貢献をやめる

本の虫: Sarah Sharp、Linuxカーネルコミュニティの暴力性に嫌気がさして貢献をやめる

ドアは閉められた 

この記事は一年もの間、下書きフォルダーに入れてた。いまこそ投稿すべき時。炎上は怖かったので、 この問題について触れるのはなるべく避けてきたのだけれど、部屋の中の象を指摘しないのはもやもやする。 そういうわけで、公開する。

元記事のタイトルは「Closing a door」なんで、「閉められた」って過去形に していいんだろうかと思ったけどそれはおいといて、 「部屋の中の象」ってなんのこっちゃいと原文をみると

Closing a door | The Geekess

Closing a door 

This post has been sitting in my drafts folder for a year now. It has never been the right time to post this. I have always been worried about the backlash. I’ve skirted around talking about this issue publicly for some time, but not acknowledging the elephant in the room has eaten away at me a bit. So, here goes.

原文もthe elephant in the room だった。 ぐぐるとそういう言い回しがあるみたいですね。なるほど。 にしても、書かれたものならこうやって調べる余裕もあるけど 会話で出てきたらお手上げだなw

■_

昨日書き忘れたけど

だいありー

Index: string.c
===================================================================
--- string.c	(revision 52040)
+++ string.c	(working copy)
@@ -1250,11 +1250,18 @@
 VALUE
 rb_str_resurrect(VALUE str)
 {
+#if 0
     if (RUBY_DTRACE_STRING_CREATE_ENABLED()) {
 	RUBY_DTRACE_STRING_CREATE(RSTRING_LEN(str),
 				  rb_sourcefile(), rb_sourceline());
     }
     return str_duplicate(rb_cString, str);
+#endif
+    VALUE dup = str_alloc(rb_cString);
+    // str_replace(dup, str);
+    RBASIC(dup)->flags = RBASIC(dup)->flags | (RBASIC(str)->flags & (RSTRING_NOEMBED | RSTRING_EMBED_LEN_MASK | RUBY_ENC_CODERANGE_MASK | RUBY_ENCODING_MASK));
+    MEMCPY(RSTRING(dup)->as.ary, RSTRING(str)->as.ary, VALUE, 3);
+    return dup;
 }
 
 /*

↑のパッチのフラグ操作のところ、 RBASIC(dup)->flags |= (略) でいいような気がするんだけどどうなんだろ。

■_

perl6

2015年10月06日

■_

■_

■_

だいありー

だいありー

個人的には、松本さんが 3.0 で文字列リテラルを freeze するんだ! という堅い意思があり、 それを目指すためならマジコメも移行パスとしてしょうがない、と思ってたんだけど、実は実験らしいので、 そんなに硬い意思でもなかったらしい(まぁ、意固地に堅い意思でも困るのだが)。 3.0 でそうならないなら、マジコメ嫌だなぁ。

三回出てくる「かたいいし」の二回目だけ「硬い」なのは何か深い意味があるのかとか そもそも「意志」ではなく「意思」を使っているのは以下略。

2015年10月05日

■_

「マジコメ」ってなんじゃい。ってしばし考えてしまった。

■_

■_

strcpy_s とも違う。のかな(確かめない)。 Linux 4.3-rc4 Kernel Released: Adds A New & Better String Copy Function - Phoronix

Linux 4.3-rc4 Kernel Released: Adds A New & Better String Copy Function - Phoronix

While Linus likes this new strscpy() function for the kernel, he held off on pulling the code to think about it and forewarning he doesn't want developers going around now and making use of this new function for currently-working code when it could lead to problems if ill-tested. Basically, if it isn't broke, don't fix it. He commented, "Every time we introduce a new-and-improved interface, people start doing these interminable series of trivial conversion patches. And every time that happens, somebody does some silly mistake, and the conversion patch to the improved interface actually makes things worse. Because the patch is mindnumbing and trivial, nobody has the attention span to look at it carefully, and it's usually done over large swatches of source code which means that not every conversion gets tested." More comments on the strscpy() kernel function via this Git pull. With Linux 4.3-rc4 the interface is there, but isn't used yet.

で、プルリクエスト。 kernel/git/torvalds/linux.git - Linux kernel source tree

kernel/git/torvalds/linux.git - Linux kernel source tree

The new "strscpy()" function is definitely easier to use and more secure 
than either strncpy() or strlcpy(), both of which are horrible nasty 
interfaces that have serious and irredeemable problems. 
 
strncpy() has a useless return value, and doesn't NUL-terminate an 
overlong result. To make matters worse, it pads a short result with 
zeroes, which is a performance disaster if you have big buffers. 
 
strlcpy(), by contrast, is a mis-designed "fix" for strlcpy(), lacking 
the insane NUL padding, but having a differently broken return value 
which returns the original length of the source string. Which means 
that it will read characters past the count from the source buffer, and 
you have to trust the source to be properly terminated. It also makes 
error handling fragile, since the test for overflow is unnecessarily 
subtle. 
 
strscpy() avoids both these problems, guaranteeing the NUL termination 
(but not excessive padding) if the destination size wasn't zero, and 
making the overflow condition very obvious by returning -E2BIG. It also 
doesn't read past the size of the source, and can thus be used for 
untrusted source data too. 
 
So why did I waffle about this for so long? 
 
Every time we introduce a new-and-improved interface, people start doing 
these interminable series of trivial conversion patches. 
 
And every time that happens, somebody does some silly mistake, and the 
conversion patch to the improved interface actually makes things worse. 
Because the patch is mindnumbing and trivial, nobody has the attention 
span to look at it carefully, and it's usually done over large swatches 
of source code which means that not every conversion gets tested. 
 
So I'm pulling the strscpy() support because it *is* a better interface. 
But I will refuse to pull mindless conversion patches. Use this in 
places where it makes sense, but don't do trivial patches to fix things 
that aren't actually known to be broken. 

この後のパッチに strscpy の実装があるんだけど結構複雑(いろいろなケースに対処)だねえ。

■_

ruby - How to combine two procs into one? - Stack Overflow のやりとりで、 Needs more sugar! とか Please explain what sugar is missing from this answer? とかでてくるのがおもしろい。 こういう使い方するのか。

■_

Turn off your monitor… — Medium

2015年10月04日

■_

Nexus 7(2012)が起動しなくなったので代わりに買ったタブレットがいきなり沈黙。 もう●●●●の製品には手をださねーっ。

■_

■_

これかな。 今週の本棚:若島正・評 『エニグマ−アラン・チューリング伝 上・下』=アンドルー・ホッジス著 - 毎日新聞

2015年10月03日

■_

代々木駅の山手線ホームにホームドアが着いてた(未稼働)。

某書店洋書コーナーで Learn C the Hard way を本棚で見つけて (発売されたのは知ってはいたけど) おお、本当に出たーと一人密やかに興奮するなど。 Learn C the Hard Way: Practical Exercises on the Computational Subjects You Keep Avoiding (Like C) (Zed Shaw's Hard Way Series)
Learn C the Hard Way: Practical Exercises on the Computational Subjects You Keep Avoiding (Like C) (Zed Shaw's Hard Way Series)

んで、そういえば amazon.com で買ったのが(船便で)発送されたってメールは来たけど いつ頃届くんだっけとチェックすると……着荷予定 10/2。 おい。

一緒に見つけた本。 オライリーと pragprog の本なら知ってても不思議じゃないのにこんなの出てたとは気がつかなかった。 Discussing Design: Improving Communication and Collaboration Through Critique
Discussing Design: Improving Communication and Collaboration Through Critique Discussing Design: Improving Communication and Collaboration through Critique
Discussing Design: Improving Communication and Collaboration through Critique Exercises for Programmers: 57 Challenges to Develop Your Coding Skills
Exercises for Programmers: 57 Challenges to Develop Your Coding Skills

どんな本か詳しくは出版社のページで。 The Pragmatic Bookshelf | Exercises for Programmers Articulating Design Decisions - O'Reilly Media

■_

■_

Exercises for Programmers のこともあったので 改めてpragprogのサイトで新刊近刊をチェックすると…… The Pragmatic Bookshelf | Ruby Performance Optimization The Pragmatic Bookshelf | Programming Phoenix この二つは前にも見たかな。 次のサイバーマンデー辺りでセールしてたら買おう。

オライリーのサイトにあるけどオライリーの本じゃない本から。

Creating Great Teams - O'Reilly Media
Publisher: Pragmatic Bookshelf
Final Release Date: November 2015 (est.)
Pages: 100

Modern Perl, 4th Edition - O'Reilly Media
Publisher: Pragmatic Bookshelf
Final Release Date: January 2016 (est.)
Pages: 300

Learn to Program with Small Basic - O'Reilly Media
Publisher: No Starch Press
Final Release Date: January 2016 (est.)
Pages: 304

Modern Perl って翻訳も出た奴かな? でも pragprog の本だったっけ? Creating Great Team はまた控えめなページ数だこと。

2015年10月02日

■_

bash起動時の設定ファイル実行順序 - Qiita そういや「歴史的経緯」もあってごちゃごちゃしてるよなあ。

6.2 Bash Startup Files
  http://www.gnu.org/software/bash/manual/bash.html#Bash-Startup-Files
    This section describes how Bash executes its startup files.

「なるほど・ザ・ガーリック」 「稲田堤の幸福な獣」

■_

■_

The Evolution of a Software Engineer : programming The Evolution of a Software Engineer - Medium 肝心のコード部分が画像になっているので引用はしないけど、 1年目→2年目→3年目→5年目→10年目でコードがどのように変わっていくかの図。 落ちが(ぴー)だけど、「にやり」くらいはするかな。

2015年10月01日

■_

APL\B5500: The Language and Its Implementation – Gary A. Kildall (1970) [pdf] | Hacker News キルドールがAPL処理系書いてたというのに驚き。 リンク先のPDFは100ページくらいあるので お手軽に読むというわけにはいかないけど ちょっと目を通した感じでは面白そう。 He was into quite a lot of things. One of the rare examples of a person who was ... | Hacker News

IO Monad Realized in 1965 (2012) | Hacker News これから派生したっぽい? This reminds me of a paper by Gary Kildall published in 1970 called "APL\B5500: The Language And Its Implementation" [1], which I think will fascinate many by just how modern it reads.

■_

■_

26 tips on C++ programming — Medium で、26個。 詳しい解説は元記事のこのリストがリンクになっているのでそちらで。

  1. Beware of the ?: operator and enclose it in parentheses
  2. Copy once, check thrice
  3. Larger than 0 does not mean 1
  4. Use available tools to analyze your code
  5. Don’t Do the Compiler’s Job
  6. Do not call the alloca() function inside loops
  7. Check all the fragments where a pointer is explicitly cast to integer types
  8. Beware of throwing exceptions in destructors
  9. Avoid using multiple small #ifdef blocks
  10. Use the ‘\0’ literal for the terminal null character
  11. Don’t try to squeeze as many operations as possible in one line
  12. When using Copy-Paste, be especially careful with the last lines
  13. A good compiler and coding style aren’t always enough
  14. Start using enum class in your code, if possible
  15. Don’t spare code lines
  16. Table-style formatting
  17. Use dedicated functions to clear private data
  18. Delegating constructors make life easier
  19. Make sure you work with data in streams the right way
  20. Table-style formatting (continuation)
  21. Do not use #pragma warning(default:X)
  22. Evaluate the string literal length automatically
  23. Use the keyword “override” when overriding virtual functions
  24. Do not compare ‘this’ to nullptr anymore
  25. Insidious VARIANT_BOOL
  26. Make your code more stable

一つ前へ 2015年9月(下旬)
一つ後へ 2015年10月(中旬)

ホームへ


リンクはご自由にどうぞ

メールの宛先はこちらkbk AT kt DOT rim DOT or DOT jp