mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Cc: gregkh@linuxfoundation.org, Kees Cook <keescook@chromium.org>,
	linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 09/11] tty: vt: separate array juggling to juggle_array()
Date: Thu, 12 Jan 2023 12:15:32 +0200 (EET)	[thread overview]
Message-ID: <73d26b6d-6272-37cf-f09e-3e652c5212d0@linux.intel.com> (raw)
In-Reply-To: <20230112080136.4929-9-jirislaby@kernel.org>

On Thu, 12 Jan 2023, Jiri Slaby (SUSE) wrote:

> The algorithm used for scrolling is the array juggling. It has
> complexity O(N) and space complexity O(1). I.e. quite fast w/o
> requirements for temporary storage.
> 
> Move the algorithm to a separate function so it is obvious what it is.
> It is almost generic (except the array type), so if anyone else wants
> array rotation, feel free to make it generic and move it to include/.
> 
> And rename all the variables from i, j, k, sz, d, and so on to something
> saner.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
>  drivers/tty/vt/vt.c | 52 ++++++++++++++++++++++++---------------------
>  1 file changed, 28 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
> index 74db07b32abe..7cda18b7ee3d 100644
> --- a/drivers/tty/vt/vt.c
> +++ b/drivers/tty/vt/vt.c
> @@ -398,40 +398,44 @@ static void vc_uniscr_clear_lines(struct vc_data *vc, unsigned int y,
>  			memset32(vc->vc_uni_lines[y++], ' ', vc->vc_cols);
>  }
>  
> +/* juggling array rotation algorithm (complexity O(N), size complexity O(1)) */
> +static void juggle_array(u32 **array, unsigned int size, unsigned int nr)
> +{
> +	unsigned int gcd_idx;
> +
> +	for (gcd_idx = 0; gcd_idx < gcd(nr, size); gcd_idx++) {
> +		u32 *gcd_idx_val = array[gcd_idx];
> +		unsigned int dst_idx = gcd_idx;
> +
> +		while (1) {
> +			unsigned int src_idx = (dst_idx + nr) % size;
> +			if (src_idx == gcd_idx)
> +				break;
> +
> +			array[dst_idx] = array[src_idx];
> +			dst_idx = src_idx;
> +		}
> +
> +		array[dst_idx] = gcd_idx_val;
> +	}
> +}
> +
>  static void vc_uniscr_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
>  			     enum con_scroll dir, unsigned int nr)
>  {
>  	u32 **uni_lines = vc->vc_uni_lines;
> -	unsigned int i, j, k, sz, d, clear;
> +	unsigned int size = b - t;
>  
>  	if (!uni_lines)
>  		return;
>  
> -	sz = b - t;
> -	clear = b - nr;
> -	d = nr;
> -
>  	if (dir == SM_DOWN) {
> -		clear = t;
> -		d = sz - nr;
> -	}
> -
> -	for (i = 0; i < gcd(d, sz); i++) {
> -		u32 *tmp = uni_lines[t + i];
> -		j = i;
> -		while (1) {
> -			k = j + d;
> -			if (k >= sz)
> -				k -= sz;
> -			if (k == i)
> -				break;
> -			uni_lines[t + j] = uni_lines[t + k];
> -			j = k;
> -		}
> -		uni_lines[t + j] = tmp;
> +		juggle_array(&uni_lines[top], size, size - nr);

top? Should be t I think.

> +		vc_uniscr_clear_lines(vc, t, nr);
> +	} else {
> +		juggle_array(&uni_lines[top], size, nr);

Ditto.

> +		vc_uniscr_clear_lines(vc, b - nr, nr);
>  	}
> -
> -	vc_uniscr_clear_lines(vc, clear, nr);
>  }
>  
>  static void vc_uniscr_copy_area(u32 **dst_lines,
> 



-- 
 i.


  reply	other threads:[~2023-01-12 10:17 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-12  8:01 [PATCH 01/11] tty: vt: remove vc_uniscr_debug_check() Jiri Slaby (SUSE)
2023-01-12  8:01 ` [PATCH 02/11] tty: vt: drop get_vc_uniscr() Jiri Slaby (SUSE)
2023-01-12  8:41   ` Ilpo Järvinen
2023-01-12  8:01 ` [PATCH 03/11] tty: vt: remove reference to undefined NO_VC_UNI_SCREEN Jiri Slaby (SUSE)
2023-01-12  8:44   ` Ilpo Järvinen
2023-01-12  8:01 ` [PATCH 04/11] tty: vt: use sizeof(*variable) where possible Jiri Slaby (SUSE)
2023-01-12  8:58   ` Ilpo Järvinen
2023-01-12  8:01 ` [PATCH 05/11] tty: vt: remove char32_t typedef Jiri Slaby (SUSE)
2023-01-12  8:52   ` Ilpo Järvinen
2023-01-12  9:34   ` Ilpo Järvinen
2023-01-12  8:01 ` [PATCH 06/11] tty: vt: remove struct uni_screen Jiri Slaby (SUSE)
2023-01-12  9:42   ` Ilpo Järvinen
2023-01-12  8:01 ` [PATCH 07/11] tty: vt: replace BUG_ON() by WARN_ON_ONCE() Jiri Slaby (SUSE)
2023-01-12  9:42   ` Ilpo Järvinen
2023-01-12  8:01 ` [PATCH 08/11] tty: vt: simplify some unicode conditions Jiri Slaby (SUSE)
2023-01-12  9:52   ` Ilpo Järvinen
2023-01-12  8:01 ` [PATCH 09/11] tty: vt: separate array juggling to juggle_array() Jiri Slaby (SUSE)
2023-01-12 10:15   ` Ilpo Järvinen [this message]
2023-01-12  8:01 ` [PATCH 10/11] tty: vt: saner names for more scroll variables Jiri Slaby (SUSE)
2023-01-12  9:59   ` Ilpo Järvinen
2023-01-12  8:01 ` [PATCH 11/11] tty: vt: cache row count in con_scroll() Jiri Slaby (SUSE)
2023-01-12 10:00   ` Ilpo Järvinen
2023-01-12  8:43 ` [PATCH 01/11] tty: vt: remove vc_uniscr_debug_check() Ilpo Järvinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=73d26b6d-6272-37cf-f09e-3e652c5212d0@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®