www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/27/13:40:18

Message-Id: <m0z0rEP-000S4rC@inti.gov.ar>
Comments: Authenticated sender is <salvador AT natacha DOT inti DOT gov DOT ar>
From: "Salvador Eduardo Tropea (SET)" <salvador AT inti DOT gov DOT ar>
Organization: INTI
To: EDWARD CASHIN <cashin AT pollux DOT cs DOT uga DOT edu>, djgpp AT delorie DOT com
Date: Mon, 27 Jul 1998 14:48:24 +0000
MIME-Version: 1.0
Subject: Re: implementation of modulo operator in djgpp
In-reply-to: <199807271629.MAA14391@woodstock.cs.uga.edu>

EDWARD CASHIN <cashin AT pollux DOT cs DOT uga DOT edu> wrote:

> Hello.  I was just considering the case of a circular
> buffer.  Indexing the subscripts could be done with
> something like this:
> 
> /* subscripts: "front" is subscript of first stored value
> 	       "back" is subscript of last stored value
> 	       "last" is subscript of the last available 
> 			array spot */
> 
> front = (front + 1 > last) ? 0 : front + 1;
> back = (back + 1 > last) ? 0 : back + 1;
> 
> ...or you could say:
> 
> front = (++front) % last;
> back = (++back) % last;
> 
> ...which begs the question, "How fast is the modulo?"
> and more specifically, how is it implemented?

Modulo is just the rest of a division. So if last is a variable (not a macro 
and not a constant) you'll get a div or idiv and that's sllloooowwww.
But I think you must call gcc with -S to take a look at the generated 
assembler ;-)

SET 
------------------------------------ 0 --------------------------------
Visit my home page: http://set-soft.home.ml.org/
or
http://www.geocities.com/SiliconValley/Vista/6552/
Salvador Eduardo Tropea (SET). (Electronics Engineer)
Alternative e-mail: set-soft AT usa DOT net set AT computer DOT org
ICQ: 2951574
Address: Curapaligue 2124, Caseros, 3 de Febrero
Buenos Aires, (1678), ARGENTINA
TE: +(541) 759 0013

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019