public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: Paul Iannetta <piannetta@kalrayinc.com>
Cc: binutils@sourceware.org
Subject: Re: [PATCH] kvx: fix 32-bit build and validation
Date: Wed, 23 Aug 2023 09:57:26 +0930	[thread overview]
Message-ID: <ZOVSbiZnCRN2D7oD@squeak.grove.modra.org> (raw)
In-Reply-To: <20230822160142.ocnjgkuboicpncii@ws2202.lin.mbt.kalray.eu>

On Tue, Aug 22, 2023 at 06:01:42PM +0200, Paul Iannetta via Binutils wrote:
>    kvx-*-*)
> -    targ_defvec=kvx_elf32_vec
> -#ifdef BFD64
> -    targ64_selvecs=kvx_elf64_vec
> -#endif
> +    targ_defvec=kvx_elf64_vec
> +    targ_selvecs="kvx_elf64_vec kvx_elf32_vec"
> +    want64=true

It isn't necessary to put kvx_elf64_vec into targ_selvecs, but doesn't
hurt.  I mention this only because..

> -    kvx_elf64_vec)		 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa" ;;
> -    kvx_elf64_linux_vec)	 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa" ;;
> +    kvx_elf64_vec)		 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa"; target_size=64 ;;
> +    kvx_elf64_linux_vec)	 tb="$tb elf64-kvx.lo elfxx-kvx.lo elf64.lo $elf $ipa"; target_size=64 ;;

..I don't see kvx_elf64_linux_vec defined anywhere.  Delete it?

>    if (class == classes->imm_classes)
>      {
> -      unsigned long long uval = token_val_p
> +      uint64_t uval = token_val_p
>  	? token->val
>  	: strtoull (tok + (tok[0] == '-') + (tok[0] == '+'), NULL, 0);
> -      long long val = uval;
> -      long long pval = val < 0 ? -val : val;
> -      int neg_power2_p = val < 0 && !(pval & (pval - 1));
> +      uint64_t sign_bit = ((~0ULL >> 1) ^ ~0ULL);
> +      int64_t pval = sign_bit & uval ? 1 + (~0ULL >> 1) - (~sign_bit & uval) : (~sign_bit & uval);
> +      int neg_power2_p = (sign_bit & uval) && !(pval & (pval - 1));
>        unsigned int len = 8 * sizeof (pval) - __builtin_clzll (pval);
>        for (; class[cur].class_id != -1
>  	  && ((unsigned int) (class[cur].sz < 0 ? - class[cur].sz - !neg_power2_p : class[cur].sz) < len

I'm about to commit a patch I wrote yesterday that fixes ubsan
warnings in the above, which will make this change unnecessary (except
of course you might like to make the variables {u,}int64_t).  The
expressions you're using for sign_bit and pval to avoid signed integer
overflow will no doubt work (unless unsigned long long is larger than
uint64_t!), but are more complicated than the following.

 int64_t val = uval;
 int64_t pval = val < 0 ? -uval : uval;
 int neg_power2_p = val < 0 && !(uval & (uval - 1));

> index 3cf6b27976d..00aec6c858e 100644
> --- a/gas/config/tc-kvx.c
> +++ b/gas/config/tc-kvx.c
> @@ -1419,6 +1419,9 @@ kvx_set_cpu (void)
>    if (env.params.core == -1)
>        env.params.core = kvx_core_info->elf_core;
>  
> +  if (!strcmp (TARGET_OS, "linux-gnu"))
> +      env.params.osabi = ELFOSABI_GNU;
> +
>    int kvx_bfd_mach;
>    print_insn = kvx_print_insn;
>  

Do you really need this?  Other targets automatically use ELFOSABI_GNU
when the ELF bfd code detects known ABI extensions.  See
has_gnu_osabi.  Hmm, likely you shouldn't be setting e_ident in
tc-kvx.c:kvx_end.

-- 
Alan Modra
Australia Development Lab, IBM

  reply	other threads:[~2023-08-23  0:27 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-22 16:01 Paul Iannetta
2023-08-23  0:27 ` Alan Modra [this message]
2023-08-23  7:44   ` Paul Iannetta
2023-08-23 12:14     ` Alan Modra
2023-08-23 14:39       ` [PATCH 0/4] kvx: various fixes Paul Iannetta
2023-08-23 14:39         ` [PATCH 1/4] kvx: remove kvx_elf64_linux_vec Paul Iannetta
2023-08-23 14:39         ` [PATCH 2/4] kvx: fix handling of STB_GNU_UNIQUE symbols Paul Iannetta
2023-08-23 14:39         ` [PATCH 3/4] kvx: use {u,}int32_t and {u,}int64_t Paul Iannetta
2023-08-23 14:39         ` [PATCH 4/4] kvx: bfd/config.bfd & ld/configure.tgt Paul Iannetta
2023-08-24  3:12         ` [PATCH 0/4] kvx: various fixes Alan Modra
2023-08-24  6:26           ` Paul Iannetta
2023-08-24  8:49           ` [PATCH] kvx: fix kvx_reassemble_bundle index 8 out of bounds Paul Iannetta
2023-08-24  9:08             ` Alan Modra
2023-08-24  9:26               ` Paul Iannetta
2023-09-07 12:46                 ` Alan Modra
2023-09-07 15:27                   ` Paul Iannetta
2023-08-23 14:40       ` [PATCH] kvx: fix 32-bit build and validation Paul Iannetta
2023-08-23  3:16 ` Alan Modra
2023-08-23 13:39   ` Luis Machado

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=ZOVSbiZnCRN2D7oD@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=piannetta@kalrayinc.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).