Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:596 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 15089 invoked from network); 2 Apr 2003 08:52:43 -0000 Received: from unknown (HELO milton.schell.de) (217.160.72.35) by pb1.pair.com with SMTP; 2 Apr 2003 08:52:43 -0000 Received: (qmail 17188 invoked by uid 501); 2 Apr 2003 08:52:42 -0000 Received: from unknown (HELO eco.foo) (80.143.48.171) by kdserv.de with SMTP; 2 Apr 2003 08:52:42 -0000 Received: from localhost (localhost [127.0.0.1]) by eco.foo (Postfix) with ESMTP id 4FE6837C8F for ; Wed, 2 Apr 2003 10:52:42 +0200 (CEST) Date: Wed, 2 Apr 2003 10:52:42 +0200 (CEST) X-X-Sender: sas@eco.foo To: internals@lists.php.net Message-ID: MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="662784-86782208-1049273562=:8659" Subject: signed_multiply_long From: sascha@schumann.cx (Sascha Schumann) --662784-86782208-1049273562=:8659 Content-Type: TEXT/PLAIN; charset=US-ASCII The attached source presents a multiplication routine with built-in overflow detection. For x86/GCC, we can avoid floating point arithmetic by using a small assembler fragment. Support for other platforms can be added as necessary. There are two distinct uses for this in PHP: - the engine needs to verify whether the result of a integer multiplication fits into its integral type (script context) - the memory allocator has to ensure that no integer overflows happen Your input is appreciated. - Sascha --662784-86782208-1049273562=:8659 Content-Type: TEXT/plain; name="mul_result.c" Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: Content-Disposition: attachment; filename="mul_result.c" LyogQ29weXJpZ2h0IChjKSAyMDAzIFNhc2NoYSBTY2h1bWFubiAqLw0KDQoN CiNpbmNsdWRlIDxsaW1pdHMuaD4NCg0KdHlwZWRlZiBlbnVtIHsNCglNUl9P SywNCglNUl9PVkVSRkxPVywNCglNUl9PVkVSRkxPV19GUF9TVE9SRUQNCn0g bXVsX3Jlc3VsdDsNCg0KbXVsX3Jlc3VsdCBzaWduZWR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