C / asm / long整数 [英] C / asm / long ints

查看:62
本文介绍了C / asm / long整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前段时间我试图使用C中的
数组来计算大数的阶乘,我在C中写的数组编码的整数arithemetic
非常慢,它将需要几乎一秒的时间来乘以2个数组

编码的整数。我心不在焉地看着C的大型精度库,特别是GMP,但是我无法让它与我的编译器一起运行,

很多时候找不到一些头文件。我很好奇接口C和asm的最佳方式是什么,这样我就可以在asm中编写simmilar库

并在C中使用它。


有什么想法吗?

A while back i tried to calculate factorials of large numbers using
arrays in C, the array encoded integer arithemetic that i wrote in C
was very slow, it would take almost a second to multiply 2 array
encoded integers. resently i looked at large precision libraries for C,
in particular GMP but i was unable to get it to run with my compiler,
aperantly some header files were not found. I was curious what is the
best way to interface C and asm so that i could write simmilar library
in asm and use it in C.

Any ideas?

推荐答案

fermineutron说:
fermineutron said:

一段时间后我试图用C中的
数组来计算大数的阶乘,我在C中写的数组编码整数arithemetic非常慢,它将需要几乎一秒的时间来乘以2个数组

编码的整数。我心不在焉地看着C的大型精度库,特别是GMP,但是我无法让它与我的编译器一起运行,

很多时候找不到一些头文件。我很好奇接口C和asm的最佳方式是什么?这样我就可以在asm中编写simmilar库

并在C.
中使用它
A while back i tried to calculate factorials of large numbers using
arrays in C, the array encoded integer arithemetic that i wrote in C
was very slow, it would take almost a second to multiply 2 array
encoded integers. resently i looked at large precision libraries for C,
in particular GMP but i was unable to get it to run with my compiler,
aperantly some header files were not found. I was curious what is the
best way to interface C and asm so that i could write simmilar library
in asm and use it in C.



汇编语言不是一个魔术棒,你可以挥手将坏算法转换成好的算法。如果你的C程序不够快,你的程序集

语言例程也不太可能足够快。


选择更好的算法。然后在C中实现它们。


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上面的域名(但显然放弃了www)

Assembly language is not a magic wand you can wave to turn bad algorithms
into good ones. If your C routines weren''t quick enough, your assembly
language routines are very unlikely to be quick enough either.

Choose Better Algorithms. Then implement them in C.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)




fermineutron写道:

fermineutron wrote:

一段时间我试图用C中的
数组计算大数的阶乘,我编写的数组编码整数arithemetic在C

非常慢,需要差不多一秒才能乘以2个数组

编码的整数。我心不在焉地看着C的大型精度库,特别是GMP,但是我无法让它与我的编译器一起运行,

很多时候找不到一些头文件。我很好奇接口C和asm的最佳方式是什么,这样我就可以在asm中编写simmilar库

并在C中使用它。


有什么想法吗?
A while back i tried to calculate factorials of large numbers using
arrays in C, the array encoded integer arithemetic that i wrote in C
was very slow, it would take almost a second to multiply 2 array
encoded integers. resently i looked at large precision libraries for C,
in particular GMP but i was unable to get it to run with my compiler,
aperantly some header files were not found. I was curious what is the
best way to interface C and asm so that i could write simmilar library
in asm and use it in C.

Any ideas?



可能更容易弄清楚如何让GMP

在您的系统上运行。值得努力。

It would probably be easier to figure out how to make GMP
work on your system. And worth the effort.


fermineutron写道:
fermineutron wrote:

一段时间我试图计算在C中使用

数组的大数阶因子,我在C中写的数组编码整数arithemetic
非常慢
A while back i tried to calculate factorials of large numbers using
arrays in C, the array encoded integer arithemetic that i wrote in C
was very slow



您可能可以编写程序集来处理您在

中执行的操作,您的乘法程序慢一点,但我怀疑你是什么
*真正想要的是从更高的数学中借用的东西:FFT的乘法。

http://numbers.computation.free.fr/C...ithms/fft.html


此主题的变体是在各种编程中发现

涉及真正大数字的情况,在你自己的实验中你偶然发现了这个应用程序划伤的痒蟑螂。


如果是n的近似解!在你的应用程序中很有用,

斯特林在18世纪给了我们一些东西,它们在今天的计算中找到各种各样的用途:
http://mathworld.wolfram.com/Stirlin...oximation.html


如果你在大学里学习计算机科学,你会看到

斯特林在第一道离散数学课程中的公式和DFT

(离散傅立叶变换)将在各种算法和自动机课程中回来困扰你几次。 (或者至少它*应该*;

一些学校似乎并没有真正教授计算机科学。)

You probably could write assembly to to the manipulations that you do in
your multiply procedure "a little less slowly", but I suspect what you
*really* want is something borrowed from higher maths: The FFT multiply.

http://numbers.computation.free.fr/C...ithms/fft.html

Variations on this theme are found in all kinds of programming
situations where really big numbers are involved, and in your own
experiments you stumbled upon the itch that is scratched by this approach.

If approximate solutions to n! would be useful in your application,
Stirling gave us something in the 18th century that finds all kinds
of uses in computing today:
http://mathworld.wolfram.com/Stirlin...oximation.html

If you study computer science in a university setting, you will see
Stirling''s formula in the first course of discrete maths, and the DFT
("Discrete Fourier Transform") will come back to haunt you a few times
in various algorithm and automata courses. (Or at least it *should*;
some schools appear to not actually teach Computer Science.)


这篇关于C / asm / long整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆