Comdiv писал(а):
Sergey Volkov писал(а):
2. Си — это переносимый ассемблер.
Кто-то запустил эту манипуляцию в массы, и теперь все повторяют. Но
1. Си - это не ассемблер.
Oleg N. Cher писал(а):
Константин, Вы как-то "замылили" ответ. Мы сейчас вообще не о теориях и не об алгоритмической полноте. Мы о том, что ассемблерная конструкция MOV EAX, EBX имеет смысл _только_ на процессорах архитектуры Intel/AMD 80x86. Точка. Всё. Никакой переносимости. Это и есть ассемблер.
Ассемблер это мнемоническое представление для машинного кода процессора, более удобное для чтения человеком.
Фрагмент кода:
Код:
BEGIN INTEGER BUCKET;
IF FLAG THEN
BEGIN BUCKET := R0; R0 := R1; R1 := R2;
R2 := BUCKET;
END ELSE
BEGIN BUCKET := R2; R2 := R1; R1 := R0;
R0 := BUCKET;
END
RESET(FLAG);
END
В 1968 сообщество решало: это язык высокого уровня или ассемблер?
Решили, что это всё-таки ассемблер, хотя и высокоуровневый.
Автор языка о нём иногда вспоминал "тихим, незлобным словом":
Цитата:
«Наш первый компилятор Паскаля был реализован на семействе компьютеров CDC-6000 и написан на самом Паскале.
Никакого PL6000 не потребовалось, и я рассматривал это как существенный шаг вперед», — вспоминает Вирт.
Несуществующий язык PL6000 Вирт упомянул в связи с тем,
что несколькими годами раньше для эффективной реализации компилятора языка Algol-W на компьютере IBM/360 ему понадобилось разработать низкоуровневый язык PL360.
Теперь же в этом необходимости не было.
Comdiv писал(а):
Info21 писал(а):
4. И не очень-то он (без #) переносимый.
Если пренебречь производительностью, то переносимый и без условной компиляции. Кроме того, для достижения переносимости условная компиляция не является необходимой.
Пример переносимого Си кода:
Building Math::Pari on Strawberry Perl on 64bit MS Windows ( rt.cpan.org #52146)
==
> Math::Pari needs heavy patching - namely the underlaying pari library is
> absolutely not ready for MSWin/x64 where sizeof(int) != sizeof(void*)
But
sizeof( long long) = sizeof(void*)
==
Problem:
==
The point is that on 64bit MS Windows there is:
- size of int = 4 bytes (!!!)
- size of *void = 8 bytes
==
May be solution:
==
. . .
Код:
+#define PARITEMPL_O_NG(x) (x##LL)
+#define PARITEMPUL_O_NG(x) (x##ULL)
+typedef long long paritemplong_t;
+
+typedef long long mp_l_o_ng;
+typedef unsigned long long mp_ul_o_ng;
. . .
==
==
. . .
Код:
- if (sizeof(long) == 4)
+ if (sizeof(mp_l_o_ng) == 4)
{
- union {double d; unsigned long l[2];} x;
+ union {double d; mp_ul_o_ng l[2];} x;
x.d = 2.;
- if (x.l[0]==0 && x.l[1]==(1UL<<30)) printf("1\n");
- else if (x.l[1]==0 && x.l[0]==(1UL<<30)) printf("0\n");
+ if (x.l[0]==0 && x.l[1]==(PARITEMPUL_O_NG(1)<<30)) printf("1\n");
+ else if (x.l[1]==0 && x.l[0]==(PARITEMPUL_O_NG(1)<<30)) printf("0\n");
else
printf("NOT IEEE (32 bit)\n");
}
else
{
- union {double d; unsigned long l;} x;
+ union {double d; mp_ul_o_ng l;} x;
x.d = 2.;
- if (x.l==(1UL<<62)) printf("-\n");
+ if (x.l==(PARITEMPUL_O_NG(1)<<62)) printf("-\n");
else
printf("NOT IEEE (64 bit)\n");
}
. . .
==
http://pari.math.u-bordeaux.fr/archives ... 00003.html =}
===
From: Jason Moxham
...
I've got Pari-svn running on Windows with/without GMP/MPIR in 64bit mode. This
is with MSVC , and when MinGW/MSYS goes 64bit it will work with that
The main problem with Windows64 is that it uses a LLP data model rather than
the usual LP data model , this means that long's are 32 bit. I'm doing this
for the Sage project but it would be nice if the changes could be
incorporated back into Pari , so I propose this.
Introduce a new type and macro ( with signed and unsigned versions)
typedef long paritemplong_t;
#define PARITEMPLONG(x) (x##L)
replace all occurances of long with paritemplong_t and numberL with
PARITEMPLONG(number)
The above is all just simple text replacement and although it means changes to
every file it will have no "real" changes.
Then for WIN64 only we change the definition
typedef long long paritemplong_t;
#define PARITEMPLONG(x) (x##LL)
...
===
+
==
. . .
On Mon, Nov 04, 2002 at 08:07:31PM +0100, Bill Allombert wrote:
- Hide quoted text -
> On Fri, Nov 01, 2002 at 12:13:16AM -0800, Ilya Zakharevich wrote:
> > On which architectures can PARI run with sizeof(long) > sizeof(long*)?
> > I tested, and it does not work on x86.
>
> None, as far as I know.
> None of the 11 architectures I have access to exhibit this behaviour.
This patch kinda-allows compiling with GEN = long long*. The result
of make bench is
. . .
==
===
...
Before applying the patch, a massive replace should be made, e.g., by
running (pfind is available from my directory 'scripts' on CPAN):
pfind src '/\.[ch]$/' '=~ s/\b(unsigned\s+|u)long\b/PARI_uword/g'
pfind src '/\.[ch]$/' '=~ s/\blong\b/PARI_word/g'
pfind src '/\.[ch]$/' '=~ s/\b(\d+|0[0-7]+|0x[\da-fA-F])(U?)L\b/as_${2}WORD($1)/g'
pfind src '/\.[ch]$/' '=~ s/(%[.0-9]*)l([ux])\"/$1\"UW${2}f/g'
pfind src '/\.[ch]$/' '=~ s/(%[.0-9]*)l([d])\"/$1\"IW${2}f/g'
pfind src '/\.[ch]$/' '=~ s/(%[.0-9]*)l([ux])/$1\"UW${2}f\"/g'
pfind src '/\.[ch]$/' '=~ s/(%[.0-9]*)l([d])/$1\"IW${2}f\"/g'
...
===
. . .
==
Метод практически работающий, но изящный ли?
( И это 64-битный Windows, т.е. "не экзотика")
P.S.
Oleg N. Cher писал(а):
по большому-то счёту воспроизвести любое окружение можно на любой платформе, если ресурсов хватит.
И возможно, и воспроизводят: PCem (
https://pcem-emulator.co.uk ).
Причём, не только 3DFX Voodoo Graphics, но и "accurate 8088/8086 timings".