From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by sourceware.org (Postfix) with ESMTPS id 6FF773858D1E for ; Fri, 20 Oct 2023 10:19:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6FF773858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6FF773858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::62e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697797173; cv=none; b=Dgjdw5ck6yxQ03WKT+DgA0Yyuc7e4fYx8XIFfSHrXWlt5hmpUKkSGeepnqL1EgtmE9KaZmiHlg0rUhhSXn8HSknqZS23HzsAaN9Ayn30BP0okb06/zxrQmrskLtqqzxn6R0FD7vib8TeOfxRQ8Nl0e4Dq5sxF5w1sr3CBQBmGAc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697797173; c=relaxed/simple; bh=rMoTNU37xNbK9RpnNp+pFJtVQXko8jXZ+jKWHBGYX2U=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=SJ3br2+qropHShMfIHQCdo6pIrZl0uMcl3kgY+DmD6j5YufnQegdzdYchza8boxJPDerRJn7rJuY0XnBTmgwcUKf3ErZzCA3D5XU7QwaO/WRRYfzbmnaU+sdN9yGzkNZAhx0ZMwQo9FsZzVRQsUky0Ka2hHVkhLD60KFoVT5YSc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-9a6190af24aso105965366b.0 for ; Fri, 20 Oct 2023 03:19:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697797169; x=1698401969; darn=gcc.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=lAo6U6qrbl9cPd8PQLK1biINmdw7F0BFCsmwVhgN8T0=; b=UF5/kn1mD2f4YgYQU6kVV+KPd5uhuWBoyF3AweahW/Z0Vv3pdDk4Digporyw0fK3g8 hO29mC2D9V6O0KecEsFlc00sN4fvbG0tc7R6GiNmBsHixS+waQRFJMOXWA3KrDEV0oHc SYGBoaC4cjDPyEGEfLneQpUW8n/e2Z0jer1PhrjEG1haFl60MpzCWaKv0+2wzFliQjdk g5Sd+1Guly9Bf4YKFhKlvnq20L3qrR3RNoIG92WEQJ7tlx+7p9/PUyK4pRUN8JV0ESwK wyYEP7vbuIHFOj5XdUUZmmltNl1jTeoMcl2nCf7vlzaPNRYWR3Pc05cAuEtibvjErE56 PQ+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697797169; x=1698401969; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lAo6U6qrbl9cPd8PQLK1biINmdw7F0BFCsmwVhgN8T0=; b=TVn1N2k6j512/PpfbSq4cXyDgNnNj7zFLy5J2kFr3/X5t5QQbTZkiwdDhGWssPAi1V b3hV1XI/vGj0WAYNhCIpwi3QgU6wBjk7BiYGUNxteV7UIDm+iC267dOiYBTQw+Dwh3FD TUrSL+Gz4WIEnoF6IEHw10pVOdi8hMHq29kgPsAgmKKBR1d9+sdNOsVmimS4jQY5k3Vn FiMK+wZHftKgy+YIrTWTQH101YnxkO6NfjyEZ7FvngNDzKg5G+6W6W+Ngrb0wa29AxfE o5X29DDDhTnXJeRq3J6H3JHBPjdrXpFAZK1uU2vxgfyKWWPTsUjIGWtNAHSj1JPXIIG0 jdxg== X-Gm-Message-State: AOJu0Yw6qgamZIJG/At8TCHHQm7rdQVV0wSE+t9JT+ZzRVCWpfoCqE4O WxYs4YcXRznWo5djHkx9lWh5Qh9dLeMKyEdeUoqk8MLt X-Google-Smtp-Source: AGHT+IGvjVz6mv/Na+lgelv0ca0NbwTjKJbILF5I1Xta+ZpeNvq/9xFkpBYKri7F+uI9K8zY5kv7lew1B0pBfWMW4l8= X-Received: by 2002:a17:907:d2a:b0:9be:68db:b763 with SMTP id gn42-20020a1709070d2a00b009be68dbb763mr1048180ejc.71.1697797168496; Fri, 20 Oct 2023 03:19:28 -0700 (PDT) MIME-Version: 1.0 References: <7834093f-0639-9ae1-cf9f-b0377a26f00b@westcontrol.com> In-Reply-To: From: Jonathan Wakely Date: Fri, 20 Oct 2023 11:19:16 +0100 Message-ID: Subject: Re: Compilation of lengthy C++ Files To: Kai Song Cc: David Brown , gcc-help Content-Type: multipart/alternative; boundary="0000000000002105e6060823350d" X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP 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: --0000000000002105e6060823350d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, 20 Oct 2023, 10:32 Kai Song, wrote: > @David: I am sorry there was a misunderstanding with the example. You > wrote four lines of code to be able to replace two lines of code into a > for-loop of length 2, somewhere in a 1Bio line program where this pattern > coincidentally occured once in one generated instance. (In the next > instance, the "pattern" might not occur, so then you just added four > lines.) Also, it is unclear how you would implement in turn the code which > locates the line 200 and decides to replace it with the for-loop. Further, > you left unclear where to place this for-loop (in line 100 or line 200?), > both of which will lead to the wrong result in the generated program due = to > false assumption on raise-conditions. > > I think my initial question has been mis-correlated. I think so because we > drift into a discussion of speed and what is better and faster and > what-not. But this is not the question at all. > The setting is rather: I have a list of lengthy instructions. Think of a > grocery list. The most convenient language for me to write this grocery > list in is c++. > Now I don't care whether my doctor thinks I want to eat this all by myself > or on a weekly basis, and likes that thought or not. I just need to get t= he > groceries. > I can get them myself. In this case, it would mean I have to learn to > generate code of linear compile-complexity into assembly directly by myse= lf. > > I am not even interested in the compilation per se. I just need to be able > to evaluate the code as written. > I am equally fine with using an interpreted language or a different > language. But interpreters have the exact same issue: They refuse to start > computing a flat program code when the file containing it is too big. > So break it up into smaller functions. You've been given the answer, but you don't want to accept it and want to argue that it's too difficult. Maybe that's true, but it's the only way you're going to get the code to compile. So suppose I have a substitution of Taylor serieses into serieses and it > _does_ become chaotic after reordering of terms. That is after all the wo= rk > that the program does. That is what it is made for. > And now I just want some way to evaluate that formula once to tell me > whether y=3Df(x) yields y=3D0 for a particular value of x. This is as bas= ic as > it gets. > > I suppose the enablement of this capability is not in the scope of GCC. Is > there a name for this problem (evaluating lengthy list of compute > instructions/formulas)? Where should I look to find a solution to that > problem? > Use subroutines. Put some of the instructions into a separate function, and call that function. The way you're generating code is not going to work at scale. > On Thu, Oct 19, 2023 at 6:03=E2=80=AFPM David Brown wrote: > >> On 19/10/2023 17:11, Kai Song via Gcc-help wrote: >> >> (It can be helpful to include attributions when replying, so that it is >> clear who wrote what. Thus you should have this line included:) >> >> > On 19/10/2023 16:26, Jonathan Wakely via Gcc-help wrote: >> >> >> >> Nothing you have said actually explains why you can't refactor the >> >> code into utility functions that avoid doing everything in one huge >> >> function. >> >> >> > >> > Because there are no two pieces of code that are exactly identical. The >> > relative distance of two variables being involved into an identical >> formula >> > will change with every line. >> > Example: >> > Line 1000: tmp[100]=3Dfoo(tmp[101],tmp[102]); >> > Line 2000: tmp[200]=3Dfoo(tmp[201],tmp[203]); // dang it, not tmp[202]= but >> > tmp[203] >> > It is like with penrose tiling. It seems all identical but the details >> > break it. You just do not find two identical local areas. No-where. And >> if, >> > you have to particularly search for them by brute-force, and that shou= ld >> > become useless whenever the particular pattern you try to find does ju= st >> > not exist in that particular user's instance. >> > >> >> Surely this is screaming out for a table? >> >> const int foo_table[][3] =3D { >> { 100, 101, 102 }, >> { 200, 201, 203 }, >> ... >> }; >> >> >> for (int i =3D 0; i < 100000000; i++) { >> tmp[foo_table[i][0]] =3D >> foo(tmp[foo_table[i][1]], tmp[foo_table[i][2]]); >> } >> >> This will turn your million-line program into a four line program with a >> big table, which will compile quickly and run faster. >> >> >> >> --0000000000002105e6060823350d--