Movatterモバイル変換
[0]ホーム
{-# LANGUAGE Trustworthy #-}{-# LANGUAGE CPP, MagicHash, UnboxedTuples, NoImplicitPrelude #-}{-# OPTIONS_GHC -O2 #-}{-# OPTIONS_HADDOCK hide #-}------------------------------------------------------------------------------- |-- Module : GHC.Float.ConversionUtils-- Copyright : (c) Daniel Fischer 2010-- License : see libraries/base/LICENSE---- Maintainer : cvs-ghc@haskell.org-- Stability : internal-- Portability : non-portable (GHC Extensions)---- Utilities for conversion between Double/Float and Rational-------------------------------------------------------------------------------#include "MachDeps.h"moduleGHC.Float.ConversionUtils(elimZerosInteger,elimZerosInt#)whereimportGHC.BaseimportGHC.Integer#if WORD_SIZE_IN_BITS < 64importGHC.IntWord64#endifdefault()#if WORD_SIZE_IN_BITS < 64#define TO64 integerToInt64toByte64#::Int64#->Int#toByte64#i=word2Int#(and#255##(int2Word#(int64ToInt#i)))-- Double mantissae have 53 bits, too much for Int#elim64#::Int64#->Int#->(#Integer,Int##)elim64#ne=casezeroCount(toByte64#n)oft|isTrue#(e<=#t)->(#int64ToInteger(uncheckedIShiftRA64#ne),0##)|isTrue#(t<#8#)->(#int64ToInteger(uncheckedIShiftRA64#nt),e-#t#)|otherwise->elim64#(uncheckedIShiftRA64#n8#)(e-#8#)#else#define TO64 integerToInt-- Double mantissae fit it Int#elim64#::Int#->Int#->(#Integer,Int##)elim64#=elimZerosInt##endif{-# INLINEelimZerosInteger#-}elimZerosInteger::Integer->Int#->(#Integer,Int##)elimZerosIntegerme=elim64#(TO64m)eelimZerosInt#::Int#->Int#->(#Integer,Int##)elimZerosInt#ne=casezeroCount(toByte#n)oft|isTrue#(e<=#t)->(#smallInteger(uncheckedIShiftRA#ne),0##)|isTrue#(t<#8#)->(#smallInteger(uncheckedIShiftRA#nt),e-#t#)|otherwise->elimZerosInt#(uncheckedIShiftRA#n8#)(e-#8#){-# INLINEzeroCount#-}zeroCount::Int#->Int#zeroCounti=casezeroCountArrofBAba->indexInt8Array#baitoByte#::Int#->Int#toByte#i=word2Int#(and#255##(int2Word#i))dataBA=BAByteArray#-- Number of trailing zero bits in a bytezeroCountArr::BAzeroCountArr=letmkArrs=casenewByteArray#256#sof(#s1,mba#)->casewriteInt8Array#mba0#8#s1ofs2->letfillAstepvalidxst|isTrue#(idx<#256#)=casewriteInt8Array#mbaidxvalstofnx->fillAstepval(idx+#step)nx|isTrue#(step<#256#)=fillA(2#*#step)(val+#1#)stepst|otherwise=stincasefillA2#0#1#s2ofs3->caseunsafeFreezeByteArray#mbas3of(#_,ba#)->baincasemkArrrealWorld#ofb->BAb
[8]ページ先頭