Skip to content

Commit 3987ea7

Browse files
committed
Make specialization of x64 zend_safe_address() for nmemb==1
There are typically 3 forms of calls to this function: 1. nmemb>1, offset=0||size=0 2. nmemb=1, size>0, offset>0 3. nmemb>1, size>0, offset>0 This specializes the second form.
1 parent 541620c commit 3987ea7

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Zend/zend_multiply.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static zend_always_inline size_t zend_safe_address(size_t nmemb, size_t size, si
176176

177177
static zend_always_inline size_t zend_safe_address(size_t nmemb, size_t size, size_t offset, bool *overflow)
178178
{
179-
size_t res = nmemb;
179+
size_t res;
180180
zend_ulong m_overflow = 0;
181181

182182
#ifdef __ILP32__ /* x32 */
@@ -186,12 +186,21 @@ static zend_always_inline size_t zend_safe_address(size_t nmemb, size_t size, si
186186
#endif
187187

188188
if (ZEND_CONST_COND(offset == 0, 0)) {
189+
res = nmemb;
189190
__asm__ ("mul" LP_SUFF " %3\n\t"
190191
"adc $0,%1"
191192
: "=&a"(res), "=&d" (m_overflow)
192193
: "%0"(res),
193194
"rm"(size));
195+
} else if (ZEND_CONST_COND(nmemb == 1, 0)) {
196+
res = size;
197+
__asm__ ("add %2, %0\n\t"
198+
"adc $0,%1"
199+
: "+r"(res), "+r" (m_overflow)
200+
: "rm"(offset)
201+
: "cc");
194202
} else {
203+
res = nmemb;
195204
__asm__ ("mul" LP_SUFF " %3\n\t"
196205
"add %4,%0\n\t"
197206
"adc $0,%1"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy