[M3commit] CVS Update: cm3

Jay K jay.krell at cornell.edu
Wed Sep 12 01:24:41 CEST 2012


Fyi, 32bit DIV/MOD by any constant is optimizable by any decent compiler with 64bit operations available. Worst case, they get implemented as 64bit fixed point operations.This works for all 32bit values. The AMD optimization manual prescribes this and includes code for computing reciprocals.For example, division by 10:  E:\>type 1.c
int div10(int a) { return a / 10; } E:\>cl -Ox -c 1.c
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.278 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.  E:\>link -dump -disasm 1.obj
div10:
  0000000000000000: B8 67 66 66 66     mov         eax,66666667h
  0000000000000005: F7 E9              imul        ecx
  0000000000000007: C1 FA 02           sar         edx,2
  000000000000000A: 8B C2              mov         eax,edx
  000000000000000C: C1 E8 1F           shr         eax,1Fh
  000000000000000F: 03 C2              add         eax,edx
  0000000000000011: C3                 ret  That's still not free, but it is much cheaper than general division.  I should fix M3x86 do to this. :)On the other hand, it makes for larger code.  E:\>cl -c 1.c
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.278 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.1.cE:\>link -dump -disasm 1.obj
Microsoft (R) COFF/PE Dumper Version 8.00.50727.278
Copyright (C) Microsoft Corporation.  All rights reserved.
Dump of file 1.objFile Type: COFF OBJECTdiv10:
  0000000000000000: 89 4C 24 08        mov         dword ptr [rsp+8],ecx
  0000000000000004: 8B 44 24 08        mov         eax,dword ptr [rsp+8]
  0000000000000008: 99                 cdq
  0000000000000009: B9 0A 00 00 00     mov         ecx,0Ah
  000000000000000E: F7 F9              idiv        eax,ecx
  0000000000000010: C3                 ret
  - Jay
 > Date: Tue, 4 Sep 2012 16:20:48 +0000
> To: m3commit at elegosoft.com
> From: hosking at elego.de
> Subject: [M3commit] CVS Update: cm3
> 
> CVSROOT:	/usr/cvs
> Changes by:	hosking at birch.	12/09/04 16:20:48
> 
> Modified files:
> 	cm3/m3-sys/m3middle/src/: M3Buf.m3 
> 
> Log message:
> 	Undo gratuitous damage:
> 	
> 	1) ChunkSize is carefully designed to have an alignable size.
> 	2) Comparison order is logical given dependent IF clause.
> 	3) digits arrays are designed for speed to avoid overhead of DIV/MOD when not
> 	needed.
> 
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3commit/attachments/20120911/5c575238/attachment-0002.html>


More information about the M3commit mailing list