From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id 5D3FF3858D1E for ; Fri, 5 Jan 2024 12:46:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5D3FF3858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=loongson.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5D3FF3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:470:142:3::10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704458769; cv=none; b=U2ypCV9msDItDD3QYX7zlbUrW8GpcxL0Ernsl/8WVnXzuLFqJOBXgtFdBFCIcXfdwMe7N79dBduWKlP2hus9nOA3v0u/ww61NG2HPRdskfCFHWhuLK5tUaGhpN5BmXjDJciWNFtZBpCSx2owgN+wDr529rt39qMx7BIagZ50TuA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704458769; c=relaxed/simple; bh=WudxPwxzYbQEntnAMSGU32mjipCv2HFeNfTggJeJ9/I=; h=Subject:To:From:Message-ID:Date:MIME-Version; b=Ika/jiO77+ICV3QK69MzWfJjl55+wIbP31Kmp/sv9645RsL6yaqratvuEc+kqj4qG+0lQAa3H9j5s0GcA89WmOhvBz4xN7fUDVHe/7usFdcdF9dobBr/SD7gTtKf3NR3JSiy2ID3JaK0Q9s+QkSfaZJud9jkGqhFox6JnyRJGeE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLjaL-0000bm-0J for gcc-patches@gcc.gnu.org; Fri, 05 Jan 2024 07:46:06 -0500 Received: from loongson.cn (unknown [117.129.62.51]) by gateway (Coremail) with SMTP id _____8CxbbsB+pdlI1MCAA--.278S3; Fri, 05 Jan 2024 20:45:53 +0800 (CST) Received: from [192.168.2.109] (unknown [117.129.62.51]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxbNz_+ZdlvXUDAA--.9043S3; Fri, 05 Jan 2024 20:45:53 +0800 (CST) Subject: Re: [PATCH v2 2/2] LoongArch: When the code model is extreme, the symbol address is obtained through macro instructions regardless of the value of -mexplicit-relocs. To: Xi Ruoyao , gcc-patches@gcc.gnu.org Cc: i@xen0n.name, xuchenghua@loongson.cn References: <20240105034021.30177-1-chenglulu@loongson.cn> <20240105034021.30177-3-chenglulu@loongson.cn> <0fe0f370-a593-d060-d260-0e190986f833@loongson.cn> <4cdfda6960e75ccc6ccea6263ac02e79c9dba572.camel@xry111.site> <74482b5cbfef5a9d07185cd63430b3907fb389d1.camel@xry111.site> From: chenglulu Message-ID: Date: Fri, 5 Jan 2024 20:45:51 +0800 User-Agent: Mozilla/5.0 (X11; Linux loongarch64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <74482b5cbfef5a9d07185cd63430b3907fb389d1.camel@xry111.site> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-CM-TRANSID:AQAAf8BxbNz_+ZdlvXUDAA--.9043S3 X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBj93XoWxJr45GF18KFyxury3tF48Zrc_yoW5Jr43pF W7ua1jga1kWrn3Cr1jy3s2qFsIka15t3y5Xwn5XFyFyFZ8Jr1Sqr45trs09asrWrs7Z3WS vr48t34xZF4rZ3gCm3ZEXasCq-sJn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9Sb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y6r17McIj6I8E87Iv 67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lc7I2V7IY0VAS07 AlzVAYIcxG8wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C2 67AKxVWUXVWUAwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI 8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWU CwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r 1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBI daVFxhVjvjDU0xZFpf9x07jYSoJUUUUU= Received-SPF: pass client-ip=114.242.206.163; envelope-from=chenglulu@loongson.cn; helo=mail.loongson.cn X-Spam_score_int: -37 X-Spam_score: -3.8 X-Spam_bar: --- X-Spam_report: (-3.8 / 5.0 requ) BAYES_00=-1.9,NICE_REPLY_A=-1.854,SPF_HELO_NONE=0.001,SPF_PASS=-0.001,T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,BODY_8BITS,KAM_DMARC_STATUS,NICE_REPLY_A,SPF_FAIL,SPF_HELO_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 在 2024/1/5 下午7:55, Xi Ruoyao 写道: > On Fri, 2024-01-05 at 18:25 +0800, Xi Ruoyao wrote: >> On Fri, 2024-01-05 at 17:57 +0800, chenglulu wrote: >>> 在 2024/1/5 下午4:37, Xi Ruoyao 写道: >>>> On Fri, 2024-01-05 at 11:40 +0800, Lulu Cheng wrote: >>>>>   bool >>>>>   loongarch_explicit_relocs_p (enum loongarch_symbol_type type) >>>>>   { >>>>> +  /* Instructions pcalau12i, addi.d, lu32i.d and lu52i.d must be adjancent >>>>> +     so that the linker can infer the PC of pcalau12i to apply relocations >>>>> +     to lu32i.d and lu52i.d.  Otherwise, the results would be incorrect if >>>>> +     these four instructions are not in the same 4KiB page. >>>>> +     Therefore, macro instructions are used when cmodel=extreme.  */ >>>>> +  if (loongarch_symbol_extreme_p (type)) >>>>> +    return false; >>>> I think this is a bit of strange.  With -mexplicit-relocs={auto,always} >>>> we should still use explicit relocs, but coding all 4 instructions >>>> altogether as >>>> >>>> "pcalau12i.d\t%1,%pc64_hi12(%2)\n\taddi.d\t%0,$r0,%pclo12(%2)\n\tlu32i.d\t%0,%pc64_lo20(%2)\n\tlu52i.d\t%0,%0,%pc64_hi12(%2)" >>>> >>>> Give me several hours trying to implement this... >>>> >>> I think there is no difference between macros and these instructions put >>> together. If implement it in a split form, I think I can try it through >>> TARGET_SCHED_MACRO_FUSION_PAIR_P > We don't need to split the insn. We can just add a "large insn" > containing the assembly output we want. > > See the attached patch. Note that TLS LE/LD/GD needs a fix too because > they are basically an variation of GOT addressing. > > I've ran some small tests and now trying to bootstrap GCC with - > mcmodel=extreme in BOOT_CFLAGS... > >> There is a difference: >> >> int x; >> int t() { return x; } >> >> pcalau12i.d t0, %pc_hi20(x) >> addi.d t1, r0, %pc_lo12(x) >> lu32i.d t1, %pc64_lo20(x) >> lu52i.d t1, t1, %pc64_hi12(x) >> ldx.w a0, t0, t1 >> >> is slightly better than >> >> pcalau12i.d t0, %pc_hi20(x) >> addi.d t1, r0, %pc_lo12(x) >> lu32i.d t1, %pc64_lo20(x) >> lu52i.d t1, t1, %pc64_hi12(x) >> addi.d t0, t0, t1 >> ld.w a0, t0, 0 >> >> And generating macros when -mexplicit-relocs=always can puzzle people >> (it says "always" :-\ ). >> Thumbs up! This method is much better than my method, I learned something! grateful! But I still have to test the accuracy.