[Bpf] Éric Vyncke's feedback on byteswap functions

Dave Thaler <dthaler1968@googlemail.com> Thu, 20 June 2024 19:59 UTC

Return-Path: <dthaler1968@googlemail.com>
X-Original-To: bpf@ietfa.amsl.com
Delivered-To: bpf@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 85AEAC14F6F4; Thu, 20 Jun 2024 12:59:47 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.857
X-Spam-Level:
X-Spam-Status: No, score=-1.857 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, URIBL_DBL_BLOCKED_OPENDNS=0.001, URIBL_ZEN_BLOCKED_OPENDNS=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=googlemail.com
Received: from mail.ietf.org ([50.223.129.194]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pgRl0aQJXLSR; Thu, 20 Jun 2024 12:59:43 -0700 (PDT)
Received: from mail-yw1-x112b.google.com (mail-yw1-x112b.google.com [IPv6:2607:f8b0:4864:20::112b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 9ED00C14F6AA; Thu, 20 Jun 2024 12:59:43 -0700 (PDT)
Received: by mail-yw1-x112b.google.com with SMTP id 00721157ae682-63bca6db118so12759427b3.3; Thu, 20 Jun 2024 12:59:43 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20230601; t=1718913582; x=1719518382; darn=ietf.org; h=content-language:thread-index:content-transfer-encoding :mime-version:message-id:date:subject:in-reply-to:references:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=s1gm4mrkLYYNsR1aNVEW8CLMsBv5dgCHIpVEZYhiuGs=; b=b1BIYaDxXgPsIUfsy/FoQ32GJ+aQCfUwT51pBHbRwvt7AqIx062RFbN4OG/CD/Ddqk tKbK4VCuiL2tW1H+pEjtM8F0UdmQ3+ytU3amzsVxuj2ao85wIUbMFkrcfB2HyWcZonnR qXnYK7jBRQVCmaarrSdXJuzpXJiDAluKOrc/F7OyQwy2gUviFKGsJZyXwRuh0GMl/Lbg hHt8tyQRBXZuzu/52dXCoiQmEHBF3h4Zym4lZ1xLOp2DXFo0MG/FGCkpbpft+glCwlEa sif38nheAK7E7HkeUes6EZblmLZJSJ545+Wvrry6oHf8T/i7nyxkbZSVET0XiqBIUpIG LWfw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718913582; x=1719518382; h=content-language:thread-index:content-transfer-encoding :mime-version:message-id:date:subject:in-reply-to:references:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=s1gm4mrkLYYNsR1aNVEW8CLMsBv5dgCHIpVEZYhiuGs=; b=u0OJkwUzpHHG0i8qBjtzuwLiljK9ngW8rIGLeofFbeiX9ZHtAkMRiQn78ykIMMUPVu 9CccTOUyBhm1ehqrl2rrfyJS8djm69zhNJu0opKWHDkBzrRcz9ZITHccgKXjqZowgdR1 IqkTXKLpLGHsjGHyYGYWgizsKByq0eatgHkh2c/9Ra97hsFPA9/RVcp5QGlGygSdM20O Kcvnkq1HMpdEjA8A5rrYwW9P3eAtwFj6xvWRiMip+5Qbqg7JAtYzhOoy92U19XCi5iRk AJW3nSvK1NbYiNQW7gEf3H1kBhrGO/1xEHc4XEbkrdw6skOFmDwkJBeZp52lfR0SolDv g/Xw==
X-Forwarded-Encrypted: i=1; AJvYcCVTaZDBlHYSaiNKe4vNR2HEflMifXEzx6LsB9hO1UTRSryAz2m2irIWQMBgS1tjFuay+G7IL1vPLrhwEnEK95Vm4QmsHcoMgxMrr0m0LTCVsY8=
X-Gm-Message-State: AOJu0YxJIgkhYs8APL0ix1hsX9CazKgGHZM4etH7kkTTuIGRGYFsR3qx OG2RiJ1A+xOehCPx5Y5DHtvwdka2YqRiKrUCjUtEwUosOB4mujjkJGwy5A==
X-Google-Smtp-Source: AGHT+IEnCM7sTEOQc+HgbTvVTkTKj6uv4J1Fa4tZj8SS4EfpHnkwa29SXrCl0TJ/Ps4Ui+I7GnXDUw==
X-Received: by 2002:a0d:eb08:0:b0:62c:c660:72af with SMTP id 00721157ae682-63a8e0e3110mr65740137b3.24.1718913582421; Thu, 20 Jun 2024 12:59:42 -0700 (PDT)
Received: from ArmidaleLaptop ([2600:381:bf1c:7784:eca4:cc56:8003:c9fb]) by smtp.gmail.com with ESMTPSA id 00721157ae682-63f14a3cabfsm313327b3.88.2024.06.20.12.59.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2024 12:59:42 -0700 (PDT)
From: Dave Thaler <dthaler1968@googlemail.com>
X-Google-Original-From: "Dave Thaler" <dthaler1968@gmail.com>
To: 'Éric Vyncke' <evyncke@cisco.com>
References: <171811793126.62184.9537540105321678706@ietfa.amsl.com>
In-Reply-To: <171811793126.62184.9537540105321678706@ietfa.amsl.com>
Date: Thu, 20 Jun 2024 12:59:37 -0700
Message-ID: <1b3701dac34c$6337e7f0$29a7b7d0$@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
X-Mailer: Microsoft Outlook 16.0
Thread-Index: AdrDTFRuaKtttYUtSxCgO66OsWwKwQ==
Content-Language: en-us
Message-ID-Hash: ESN6TVVVVMDGTZWLE7Y7S4VSPJXCNQ57
X-Message-ID-Hash: ESN6TVVVVMDGTZWLE7Y7S4VSPJXCNQ57
X-MailFrom: dthaler1968@googlemail.com
X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header
CC: draft-ietf-bpf-isa@ietf.org, bpf-chairs@ietf.org, bpf@ietf.org, void@manifault.com, bpf@vger.kernel.org
X-Mailman-Version: 3.3.9rc4
Precedence: list
Subject: [Bpf] Éric Vyncke's feedback on byteswap functions
List-Id: Discussion of BPF/eBPF standardization efforts within the IETF <bpf.ietf.org>
Archived-At: <https://mailarchive.ietf.org/arch/msg/bpf/KBWXbMeDcSrq4vsKR_KkBbV6hI4>
List-Archive: <https://mailarchive.ietf.org/arch/browse/bpf>
List-Help: <mailto:bpf-request@ietf.org?subject=help>
List-Owner: <mailto:bpf-owner@ietf.org>
List-Post: <mailto:bpf@ietf.org>
List-Subscribe: <mailto:bpf-join@ietf.org>
List-Unsubscribe: <mailto:bpf-leave@ietf.org>

Éric Vyncke wrote: 
> 2) I find puzzling the absence of betoh16() in the presence of htobe16()
> functions.

Since the implementation is identical, I believe it wouldn't make sense to
use up another instruction with the same implementation.  

Table 6 in section 4.2 uses the direction-agnostic description for TO_BE of
"convert between host byte order and big endian" which I think is good.
But then it says:

> {END, TO_BE, ALU} with 'imm' = 16/32/64 means:
>
> dst = htobe16(dst)
> dst = htobe32(dst)
> dst = htobe64(dst)

Where section 2.2 confusingly defines it as direction-specific as you noted:

> htobe16: Takes an unsigned 16-bit number in host-endian format and
> returns the equivalent number as an unsigned 16-bit number in big-endian format.

Whereas bswap16 is direction agnostic:
> bswap16: Takes an unsigned 16-bit number in either big- or little-endian format
> and returns the equivalent number with the same bit width but opposite endianness.

I think the right way to address your comment is to change 2.2 and perhaps
the function name to be direction agnostic and match the description in table 6.
For example:

* bebswap16: Takes an unsigned 16-bit number and converts it between host byte
order and big endian.  That is, on a big-endian platform the value is left unchanged
and on a little-endian platform the behavior is the same as bswap16.

Dave