Status: New
Owner: ----
New issue 3696 by [email protected]: slow code for 'integer' checks
https://code.google.com/p/v8/issues/detail?id=3696
See attached code.
Both check1 and check2 are common ways of testing if a number is an integer.
(int32 and double with integral value).
I have marked the Smi path in the optimized functions with '*'.
The checks should be much faster for Smi values, since being a Smi
guarantees a 'true' result.
The optimized code is very naive.
The x value is Smi-checked twice. I would have expected at least the
conversion to be GVN-ed.
I see a lot of unnecessary Smi checks in V8 code. This seems like a large
area for improvement.
check1 - an int32 check.
--- Raw source ---
(x) { return (x|0) === x; }
15 instructions on fast (smi) path
* 0x51d54184 36 8b4508 mov eax,[ebp+0x8]
;;; <@16,#30> tagged-to-i
* 0x51d54187 39 d1f8 sar eax,1 ;; debug:
position 32
* 0x51d54189 41 0f8253000000 jc 130 (0x51d541e2)
;;; <@17,#30> gap
* 0x51d5418f 47 8b4d08 mov ecx,[ebp+0x8]
;;; <@18,#29> double-untag
* 0x51d54192 50 f6c101 test_b cl,0x1
* 0x51d54195 53 7414 jz 75 (0x51d541ab)
0x51d54197 55 8179ff7181f04e cmp [ecx-0x1],0x4ef08171 ;; object:
0x4ef08171 <Map(elements=3)>
0x51d5419e 62 0f85b2000000 jnz 246 (0x51d54256)
0x51d541a4 68 f20f104903 movsd xmm1,[ecx+0x3]
0x51d541a9 73 eb0b jmp 86 (0x51d541b6)
* 0x51d541ab 75 89ca mov edx,ecx
* 0x51d541ad 77 d1fa sar edx,1
* 0x51d541af 79 0f57c9 xorps xmm1,xmm1
* 0x51d541b2 82 f20f2aca cvtsi2sd xmm1,edx
;;; <@20,#32> int32-to-double
* 0x51d541b6 86 0f57d2 xorps xmm2,xmm2
* 0x51d541b9 89 f20f2ad0 cvtsi2sd xmm2,eax
;;; <@23,#15> compare-numeric-and-branch
* 0x51d541bd 93 660f2ed1 ucomisd xmm2,xmm1
* 0x51d541c1 97 0f8a06000000 jpe 109 (0x51d541cd)
* 0x51d541c7 103 0f840a000000 jz 119 (0x51d541d7)
An integral value check.
--- Raw source ---
(x) { return x == Math.floor(x); }
19 instructions on fast (smi) path.
* 0x51d542e4 36 8b4508 mov eax,[ebp+0x8] ;; debug:
position 76
;;; <@18,#31> double-untag
* 0x51d542e7 39 a801 test al,0x1
* 0x51d542e9 41 7414 jz 63 (0x51d542ff)
0x51d542eb 43 8178ff7181f04e cmp [eax-0x1],0x4ef08171 ;; object:
0x4ef08171 <Map(elements=3)>
0x51d542f2 50 0f8567000000 jnz 159 (0x51d5435f)
0x51d542f8 56 f20f104803 movsd xmm1,[eax+0x3]
0x51d542fd 61 eb0b jmp 74 (0x51d5430a)
* 0x51d542ff 63 89c1 mov ecx,eax
* 0x51d54301 65 d1f9 sar ecx,1
* 0x51d54303 67 0f57c9 xorps xmm1,xmm1
* 0x51d54306 70 f20f2ac9 cvtsi2sd xmm1,ecx
;;; <@20,#15> math-floor
* 0x51d5430a 74 0f57c0 xorps xmm0,xmm0
* 0x51d5430d 77 660f2ec8 ucomisd xmm1,xmm0
* 0x51d54311 81 750d jnz 96 (0x51d54320)
0x51d54313 83 660f50c9 movmskpd ecx,xmm1
0x51d54317 87 f6c101 test_b cl,0x1
0x51d5431a 90 0f8544000000 jnz 164 (0x51d54364)
* 0x51d54320 96 660f3a0bc109 roundsd xmm0,xmm1,9
* 0x51d54326 102 f20f2cc8 cvttsd2si ecx,xmm0
* 0x51d5432a 106 83f901 cmp ecx,0x1
* 0x51d5432d 109 0f8031000000 jo 164 (0x51d54364)
;;; <@22,#32> int32-to-double
* 0x51d54333 115 0f57d2 xorps xmm2,xmm2
* 0x51d54336 118 f20f2ad1 cvtsi2sd xmm2,ecx
;;; <@25,#16> compare-numeric-and-branch
* 0x51d5433a 122 660f2eca ucomisd xmm1,xmm2
* 0x51d5433e 126 0f8a06000000 jpe 138 (0x51d5434a)
* 0x51d54344 132 0f840a000000 jz 148 (0x51d54354)
Attachments:
intcheck.js 579 bytes
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.