.
D 2000-12-13T06:25:23
J icomment Following\sup\son\sJeff's\sclaim\sthat\sthis\sbug\sis\snot\npresent\son\sall\s64-bit\ssystems\safter\sall,\sI\sbuilt\nTcl\son\san\sAlpha\susing\sboth\sthe\sGnu\sC\scompiler,\sand\nthe\sCompaq\sC\sCompiler\n\nhttp://www5.compaq.com/products/software/compilers/candcxx.html\n\nSure\senough,\sthe\sCompaq\sC\sCompiler\sproduces\sa\sTcl\nlibrary\sthat\sdoes\snot\sexhibit\sBug\s121072.\s\sThe\sTcl\nlibrary\scompiled\sby\sthe\sGNU\sC\sCompiler\sdoes\ssuffer\nfrom\sBug\s121072.\n\nThe\sdifference\scomes\sdown\sto\sthe\scompilers'\sinterpretation\nof\sline\s4099\sof\srevision\s1.17\sof\sgeneric/tclExecute.c.\nThat\sline\sincludes\sthe\sexpression\n\niPtr->randSeed\s-\stmp*RAND_IQ\n\nwhere\siPtr->randSeed\sis\sa\slong,\stmp\sis\san\sint,\sand\s\nRAND_IQ\sis\sthe\sliteral\s127773.\s\sThe\sCompaq\scompiler\npromotes\sall\sthree\squantities\sto\slongs\sbefore\scomputing\nthe\sexpression.\s\sThe\sGNU\scompiler,\showever,\ssees\sthe\nproduct\sof\stmp\s(an\sint)\sand\s127773\s(an\sint\sconstant),\nand\scomputes\sthe\smultiply\susing\sints,\swhich\scan\soverflow\n(and\sdoes\soverflow\sin\sthe\sBug\s121072\sexample).\s\sThis\ndifference\scauses\sthe\stwo\scompilers\sto\sproduce\scode\nthat\scompute\sdifferent\sresults.\n\nThe\sstrange\sthing\sis\sthat\sby\smy\sreading\sof\sK&R's\sANSI\nC\sbook,\sit\sis\sthe\sGNU\sCompiler\sthat\sis\sbehaving\scorrectly\s--\sthe\sproduct\sof\stwo\sints\sshould\sbe\sstored\sin\san\sint\s--\sand\sTcl's\scode\sis\sdepending\son\sthe\sbroken\sbehavior\sof\sthe\sCompaq\scompiler\s(and\sothers?).\s\sA\scolleague\sreports\sthat\sSGI's\nC\scompiler\swith\sthe\s-64\soption\salso\sworks\scorrectly,\sso\sa\sTcl\slibrary\sbuilt\son\sSGI\swith\sthe\s-64\soption\salso\sexhibits\sBug\s121072.\n\nIsn't\sit\sfun\sworking\saround\scompiler\sbugs!\s\s:(\s[**]\n\nThe\stiniest\sfix\sfor\sBug\s121072\sis\sto\sdeclare\stmp\sto\sbe\nof\stype\slong,\srather\sthan\stype\sint,\sand\sleave\severything\nelse\salone.\s\sThat\swill\sfix\sthe\sproblem.\s\sSo,\sif\syou\sprefer\na\sminimum-code-changes\sapproach,\swe\scould\sjust\sdo\sthat.\n\nHowever,\sPatch\s102781\sprovides\sa\smore\ssubstantial\srewrite.\nIt\savoids\sthe\soverflow\sproblem\sentirely\sby\skeeping\sTcl's\nimplementation\swithin\sthe\sconstraints\sof\sthe\salgorithm\ndescribed\sin\sthe\sPress\s&\sTeukolsky\sreference.\s\sAfter\sall,\nthe\sP&T\salgortihm\swas\sespecially\swritten\sto\savoid\noverflows\sof\s32-bit\sregisters.\s\sBecause\sPatch\s102781\sis\sa\smore\sfaithful\simplementation\sof\sP&T's\salgortihm,\sit\sis\salso\sable\sto\scompletely\sdispense\swith\sthe\sbizarre\s[*]\sincantation\scurrently\sin\splace\sto\sperform\sbit-masking\sacross\smany\scompilers\sand\splatforms.\s\sIMHO,\sthe\s\sadditional\scomments\salso\sdo\san\simproved\sjob\sof\sexplaining\swhat\sis\sgoing\son.\n\nAnother\sreason\sPatch\s102781\sis\sbetter\sis\sthat\sit\sis\nfuture-proof\sagainst\sa\sworld\swhere\sints\sare\s64\sbits,\sand\slongs\sare\seven\slonger.\s\sThe\sP&T\salgorithm\smakes\sthe\sspecific\sassumption\sof\sa\s32\sbit\sregister.\s\sPatch\s102781\sproperly\smasks\sseed\svalues\sto\s31\sbits\sbefore\sthe\srecurrence\sbegins,\sso\sthis\sassumption\sis\senforced.\n\nIf\swe\sassume\sthat\sTcl\swill\snever\sbe\sbuilt\son\sa\splatform\nwith\sints\ssmaller\sthan\s32\sbits,\sthen\sthe\spromotion\sof\sthe\svariable\stmp\sto\stype\slong\sin\sPatch\s102781\sis\sunnecessary.\s\sIt\swas\sadded\ssimply\sbecause\sI\swas\salready\smodifying\sthe\scode,\sand\sit\sseemed\sa\sgood\sopportunity\sto\sbetter\sconform\sto\sANSI\sstandards.\s\sIt\sis\snot\sessential\sto\sproper\sworking\sof\nPatch\s102781.\s\sBut\sit\sdoesn't\shurt,\sand\sit\smight\seven\shelp\ssomeone\ssomeday\strying\sto\sport\sTcl\sto\san\sexotic\splatform,\sso\sI'd\sprefer\sto\skeep\sit\sin.\n\n[*]\sNot\smy\sdescription,\sthat's\sstraight\sfrom\sa\scomment\nalready\sin\sthe\scode.\n\n[**]\sTry\sthis\stest\sprogram\sto\ssee\sif\syour\scompiler\sis\nbroken.\s\sIt\sshould\sprint\sthe\ssame\svalue\stwice:\n\n#include\s<stdio.h>\n\n#define\sQ\s127773\n\nint\smain(int\sargc,\schar\s**argv)\n{\nlong\sl\s=\s1L\s<<\s37;\nint\stmp\s=\sl\s/\sQ;\nint\si\s=\stmp*Q;\n\nfprintf(stderr,\s"d\s\s\s=\s%ld\\n",\sl\s-\stmp*Q);\nfprintf(stderr,\s"l-i\s=\s%ld\\n",\sl\s-\si);\n}\n\n
J login dgp
J mimetype text/plain
J username dgp
K 402781ffffffffffffffffffffffffffffffffff
U dgp
Z 509f0a3e222f28098fb36880d2a71a00