serious bit fiddling, div10 using shift magic
forgot that arm has no division (or respectively only later models have) many magic formulae out there, none seem to work 1000% on the interpreter. some big 0 ending numbers are 1 off.
This commit is contained in:
@ -8,6 +8,88 @@ class Integer < Value
|
||||
end
|
||||
end
|
||||
|
||||
int high_times( int by_high , int by_low)
|
||||
|
||||
int num_high = self >> 16
|
||||
int num_low = self & 65535
|
||||
|
||||
int res_high = by_high * num_high
|
||||
|
||||
num_low = by_high * num_low
|
||||
num_high = num_high * by_low
|
||||
|
||||
num_high = num_low + num_high
|
||||
|
||||
num_high = num_high >> 16
|
||||
|
||||
res_high = res_high + num_high
|
||||
|
||||
return res_high
|
||||
|
||||
end
|
||||
|
||||
int low_times( int by_high , int by_low)
|
||||
|
||||
int num_high = self >> 16
|
||||
int num_low = self & 65535
|
||||
|
||||
int res_low = by_low * num_low
|
||||
|
||||
num_low = by_high * num_low
|
||||
num_high = num_high * by_low
|
||||
|
||||
num_low = num_low + num_high
|
||||
|
||||
num_low = num_low << 16
|
||||
|
||||
res_low = res_low + num_low
|
||||
|
||||
return res_low
|
||||
|
||||
end
|
||||
|
||||
int div10()
|
||||
int minus_10 = self - 10
|
||||
int me = self
|
||||
|
||||
int tmp = me >> 2
|
||||
me = me - tmp
|
||||
|
||||
tmp = me >> 4
|
||||
me = me + tmp
|
||||
|
||||
tmp = me >> 8
|
||||
me = me + tmp
|
||||
|
||||
tmp = me >> 16
|
||||
me = me + tmp
|
||||
me = me >> 3
|
||||
|
||||
int tmp2 = me << 2
|
||||
tmp2 = me + tmp2
|
||||
|
||||
tmp2 = tmp2 << 1
|
||||
minus_10 = tmp2 - minus_10
|
||||
|
||||
if_minus(minus_10)
|
||||
me = me + 1
|
||||
end
|
||||
return me
|
||||
end
|
||||
|
||||
int div10_almost()
|
||||
int me = self
|
||||
if_zero( me >> 26 )
|
||||
me = me + 1
|
||||
end
|
||||
int res_high = me.high_times( 26214 , 26215 )
|
||||
int res_low = self >> 31
|
||||
res_high = res_high >> 2
|
||||
|
||||
return res_high + res_low
|
||||
|
||||
end
|
||||
|
||||
Word as_string(Word str)
|
||||
if_minus( self - 10 )
|
||||
int num = as_char()
|
||||
|
@ -5,7 +5,7 @@ class Word < Object
|
||||
word_index = word_index >> 2
|
||||
word_index = word_index + 3
|
||||
int rest = index - 1
|
||||
rest = rest.mod(4)
|
||||
rest = rest.mod4()
|
||||
int char = get_internal(word_index)
|
||||
int shifted = 8 * rest
|
||||
shifted = char >> shifted
|
||||
@ -27,7 +27,7 @@ class Word < Object
|
||||
word_index = word_index + 3
|
||||
|
||||
int rest = index - 1
|
||||
rest = rest.mod(4)
|
||||
rest = rest.mod4()
|
||||
|
||||
int shifted = rest * 8
|
||||
shifted = char << shifted
|
||||
|
Reference in New Issue
Block a user